Day 3- some upgrades, and AI for the bad guys


Last day of the weekend, so according to my plan, I should have all the basic mechanics implemented. Let's talk about, how to do things, but only when in JAM MODE

1. Enemy status.

At least one of the POWERUPS is gonna give the enemy a status effect, that affects them over time. There are ways to do it smart, but this is a game jam, so I did it fast instead.

Generally- you have a class attached to enemy, that tracks it's status. When enemy takes damage, the health class raises an event. EnemyStatus class listens to this event, and applies the status, if the right conditions are met. So far so good? Well, here's when it gets stupid. Right now, EnemyStatus class has a hard reference to PlayerStatus (one of the class that I wrote about yesterday). This of course, is fine in my game- we have only one player, that controls only one character, and only the player can give enemies statuses. If this wasn't the case (imagine exploding barrels that put enemies on fire) I would need to find a better way to do this.

Also- if I wanted to develop this project longer than the jam. Hard references make projects harder to maintain, and this goes double, for references that have no business where they are.

This is a jam though, and I have a timeline to keep :)

2. One day AI.

There are many ways to implement enemy AI. If you have just a few of hours to do this, and you decide to make it even less (we had beautiful weather here, so I went for a walk), the simplest way, is to make a State Machine.

A bit of theory. A state consists of states (for us, they are: idle, engage, attack, random movement, die), and  a set of conditions describing when the states change. For example- an IDLE enemy can decide to ATTACK if our hero is close, but only ENGAGE if our guy is further away.

Now, enemy AI is complicated stuff, and normally takes a lot of time to debug, fix, polish, so it looks natural. Time isn't something we have here. So to make enemies make less mistakes, like trying to walk into level geometry, I made my enemies THINK more.

Every enemy has a random time range. After it spends given time in a single state, it picks a state again. So if my guy decided, that moving through a wall was a good idea... he's likely gonna change his mind after a few seconds.

3. Natural looking movement

When the bad guys try to close the distance between them and player, they don't go to the player directly. Instead, they choose a place in proximity of the player (parameter! - what "proximity" means is different for different enemies). This makes it look like they try to weave, instead of trying to rush the player. Of course- mele enemies might decide to rush the player after closing in enough (rush distance is another parameter). By the way. There are no REAL mele enemies in my game. Those are just normal enemies that have a mele-like animation, and a ranged weapon with a very short range. 

So there you have it! This is the way to fake simplify enemy AI in just one day!

4. Happy accidents!

I started to add a launched weapon, but accidently gave mass to the missile. I liked the missiles falling slowly over time, so Instead of a launcher I have a thrown weapon now!

Tomorrow- level design!

Leave a comment

Log in with itch.io to leave a comment.