AI, I hate AI

This week I took it upon myself to do the AI for the enemy fish and the light bulb for the player. While the light bulb was pretty straight forward the AI was a lot harder to put together. I realize this task will take much more time than I expected. It didn’t help that I was stuck in bed the whole week with fever and “puke sickness”.

Image

The light bulb consists of a sprite that’s always drawn just in front of the player and a “light” with a variable radius. I thought it would be easy just to create a class and draw it out. I was wrong, I created the class without problem, but when I tried to give the light bulb its properties it refused to recognize SFML (The library we’re using to do most of the work). This is still a problem as I’m writing this. Everything works fine when I remove all things that have to do with SFML. This is no option for the release version so I will not stop until I get it right.

Image

The AI was a bit scary as it’s the first one I ever try to make. I was right to be scared, it’s hard. The AI consists of three states: Idle, Attacking and Fleeing.

In its Idle state the fish are just swimming around minding its own business. To make it swim around in random directions doing fish-things is a lot harder than you might thing, at least for me.

The Attack state is pretty self-explanatory, the fish attacks the player. The attack state is triggered if the fish is larger or of equal size of the player and if it discovers the player before it gets attracted by the light bulb.

If the fish is smaller and discovers the player before it is caught, it will enter its fleeing state. When it does it will get a speed increase and starts of away from the player.

I solved this in a simple way. If the fish is smaller and behind the player and within a set number of pixels (still tweaking the number) is flees.

And the same thing with the larger fish but it attacks instead of flee.

From the start we wanted fish to eat and flee from other fish and create a sort of ecosystem. But this is a lot more work than we have time or skill for.

Image