πΎ Enemies & Simple AI

Spikes are scary, but they just sit there. The baddies that make your heart pound are the ones that move β pacing around, or even spotting you and giving chase. πΎ
So how does an enemy βthinkβ? Spoiler: it doesn't β it just follows a few tiny rules, exactly like the rest of your game.
The big idea: AI is just rules, every loop
When an enemy seems βsmart,β it's really running a handful of if-this-then-thatrules β once per loop, just like your hero. There's no magic and no real thinking.
The three classic brains: patrol (pace back and forth, ignore the player), chase(βif I can see the player, step toward themβ), and flee (the same rule, but step away). The enemy can only react to what it can seeβ and that sight is just a distance number you control. That's the whole trick behind βgame AI.β
Your turn: give the baddie a brain
Pick the enemy's brain, then tune its speed and how far it can see (watch the coloured zone). Walk in and out of its sight and feel the rules kick in.
Click the game, then β β move and β / Space jump. Try to dodge the πΎ!
π§ The enemy's brain
Pick the rule it follows every loop.
Patrols⦠until it sees you, then comes after you!
π Speed
ποΈ Eyesight
Discovery missions
Try each one, tick it off, then peek at the secret.
βοΈSet the brain to Patrol and stand right next to the enemy. Does it notice you at all?
π Switch to Chase and slowly walk toward it. Watch the coloured zone β what happens the instant you step inside it?
πSet it to Flee and try to walk into it. Can you catch it?
ποΈTurn the enemy's eyesight way down (even to 0) and sneak past it on Chase.
π¨Crank the enemy's speed above yours and try to escape a Chase. Then use a jump or the ledge to juke it.
π You leveled up! You now know:
- π§ Enemy βAIβ is just a few if-this-then-that rules, run every loop.
- βοΈ Patrol = follow a fixed path, ignore the player.
- π Chase / π Flee = when it SEES you, move toward / away.
- ποΈ βSightβ is just a distance number β its senses have limits.
- βοΈ Tuning speed + sight is how you make a baddie fun but fair.
π¬ Behind the scenes β what's next?
Look at everything you've got now: a hero, a world, collisions, sprites, a goal, a Game Over, and enemies with brains. Those are all the LEGO bricks of a game! π§± Next, you stop following along and start inventingβ mixing those bricks into a game that's yours. π‘π