Turnbased Roguelike
Role: Programmer
Team size: 2
Time: 2 weeks
Made in Unity with C#
Small project I made in "Game Programming with C#" at Futuregames together with another programmer, Emil Sundman. We mostly worked on separate stuff but helped eachother when there was any problems.
A* Pathfinding
Pathfinding was a huge part of this project in order to get enemies to move towards and attack the player. This was my first project ever where I implemented any pathfinding on my own and did not use Unitys NavMesh system so I started by doing some research. I read several articles, watched several videos and took quick looks at some code snippets in different programming languages to get an understanding of how A* pathfinding works.
​
Because the pathfinding should be able to be used from anywhere I made the class and methods static. The main method takes the grid of tiles, a start position and an end position to calculate a path if one is possible and returns a list of positions for the steps to reach the end position with an out parameter. The method creates pathnodes which does the calculations for distance to the start- and end positions which are used to calculate their F costs to find the best route. The class for the tiles has an enum for if it's walkable or not which is used when looking for possible neighboring tiles to move to.

Entities
Because most of the characters in this game were going to have very similar behaviours I decided to make a base class (Entity) to hold most of the functionality. This class have prepared methods for things like checking if a move is valid, moving the character, flipping the sprite when going the other way and attacking which also includes the small animation that I made with a coroutine.
​
I then made two new classes (Player and Enemy) which inherits the Entity class and use the methods depending on player/AI input.
​
Enemy behaviour
For the enemies behaviour I decided to setup a few rules to get them to chase and attack the player character. I programmed the actions from closest to furthest range to the player character which I think made it very easily readable in code. The rules I made was:
​
-
Attack if the player is in attack range.
-
Move towards the player if in chase range.
-
Move in a random direction.
​
​
​
​
Turnbased
We wanted to make the game turnbased so that the player moves and then all the enemies moves after. In order to make this I decided to create two controller scripts, one for the player and one for the enemies. The player controller reads input and controls the player character if the action is valid whereas the enemy controller simply tells the enemies to make their moves one at a time. To make it easier to debug the enemies decisions I added settings for delays at the start and end of the enemy turn and also between different enemies moves. To make the game turnbased I added UnityEvents which are called at the end of the player/enemy turn and let's the other controller script know that it can start making moves.
​
​

Takeaways
This was my first project working with my own pathfinding implementation which while it I had to do some research for it and it was challenging it was also very fun and felt rewarding. There are things that could have been improved in this implementation like not having to take a grid of a specific class (Tile).
​
I really liked making a base class for character functionality and then building more things on top of that for structure and using UnityEvents instead of making references to specific classes.
​
Working on individual tasks worked very well because we still had great communication and helped eachother out whenever we had to put things together.

