Day 2: Enemies and shootouts

Today, I added enemies.

The first step was to create a sprite for it. I did this in the free pixel art app called Piskel, which I used to make all of my sprites for this game. Then, I got the sprite into arcade and on the window.

Now it was time to create an AI for the enemies. The first thing I did was to get a line-of-sight algorithm working, so the enemies will move toward the player if the player is not in the line of sight. For actually moving, I had two options:
1. A-star pathfinding towards the player
2. Simply angling towards the player and going in a straight line.

I found both options to be equally effective, except the A-star method was a bit more intensive. In the end, I just opted for the second method. The enemies will check if the player is in their line of sight, and if it is not, the enemy will move toward the player until the player is in the line of sight.

Now that I could get enemies to move the player into their line of sight, it was time to make the enemies shoot at the player. To do this, I made it so that (before adjustment) there was a 1-in-200 chance that the enemy would shoot every frame. After adjusting for delta time using the following code, I had a pretty fair shooting algorithm.

adj_odds = int(200 * (1 / 60) / delta_time)
Code for adjusting odds for delta time

The next thing I did was to make a leveling system. This game is an endless shooter, and the enemies come in waves.
I did this by tracking a level variable and incrementing it when all the enemies were killed. Then, when setting up the new wave, I would spawn in the number of enemies that level contained. For example, if level is 1, I spawn in 1 enemy, if level is 2, I spawn in 2 enemies, and so on.

Combine this all together, and I had a fairly challenging game.

See you tomorrow!