Devlog: Engaging with Enemies - Seamus Lynch
Enemies are an essential part of Sporatic Tactics. They dictate the players gameplay. Thats why it is important that the player can interact with the enemy in meaningful ways.
In Sporatic Tactics, the player steers enemies out of their kingdom's borders by positioning their troops near them, scaring them away. Once an enemy has been steered out of the play area (your kingdom), they are defeated. That begs the question, how exactly do the enemies respond to your nearby troops?
The straightforward solution is to have the enemy move in the opposite direction of your troop. This is flawed in a number of ways. First, it's boring. You're just sending out a troop in a straight line until the enemy is chased out. Second, and arguably more important, it leaves less room for skilled play.
This next image shows some of the logic present in the game. The most important part is that when you only have one troop next to an enemy, there is no certainty in where the enemy will go, thus it will take longer to steer them away. In examples 2 and 3 you can see that more ally troops equilibrate the enemies moves to be more predictable, rewarding not only more commitment of troops, but smarter placement of troops. These are just three examples of how you can arrange your troops to move the enemy. You can arrange your troops however way you want, and the enemy will move in accordance. This begs another question, how does the enemy know where there are ally troops and how to move accordingly?
The basis of the system is a binary type principal. When an allied troop is standing in a specific direction in relation to the enemy, a certain number is added to a variable. Each possible number is then assigned a movement direction, whether its set or a random range. Since the numbers ascend in this way (like in binary) no two combinations will total to the same value. There is one problem with this method; there is a lot of combinations. The way to alleviate this is by rotating the number allocation to allign with where an allied troop is. This in effect reduces the amount of combinations to those where there is always a troop in position 1. Now lets see how this works in code.
When the enemy moves to a space, they send a raycast out in each of the six hexagonal directions which are then put into an array. The array is then scanned through, checking each raycast for a hit and if so, a variable is set to the corresponding index. This sets the orientation of the number allocation. The array is then scanned through again, and the numbers are added. For this to work, when the raycasy array is set, it is mostly repeated (Eg. Array = {1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5}. This is to allow the orientation variable to act as the offset while still assigning the correct numbers. Finally, there is a check to see if the positionCalculator variable, which has been adding up all the numbers is 0, meaning no enemies were detected. This determines the true/false of the nearEnemy variable, which is used in code elsewhere.
Then comes the movement part. PositionCalculator is fed into a switch statement with all the possible number combinations and their corresponding result. Case 0 is no enemies near, so an array containing the games buildings is scanned, checking for the closest one and assigning it as the enemies move target. In every other case, the child object unitMover is moved in the corresponding direction, adhering to the orientation. Here you can see the possible cases where the enemy only has one place to go, and also if they are surrounded, which destroys them.
This is a case where the enemy could move to more than one space, so another switch statement with a Random.Range is used to determine the final outcome.
With this system in place, players have more ways to deal with enemies. They can show their skill in multiple ways, by steering enemies away as fast as possible or if overwhelmed, knowing how exactly they can manipulate the enemies movement to stretch their forces as thin as possible.
Sporadic Tactics
Status | Released |
Author | PrimalTurtwig2 |
More posts
- Emily Fanning -DevLogMay 10, 2024
- Sprite designMay 10, 2024
Leave a comment
Log in with itch.io to leave a comment.