← Back to the map
Lesson 6

πŸ‘Ύ Enemies & Simple AI

Enemies & Simple AI illustration

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.

1

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.”

2

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.

tagged: 0

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

2.5 (slower than you)

πŸ‘οΈ Eyesight

170px
3

Discovery missions

Try each one, tick it off, then peek at the secret.

0/5
  • ↔️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:

🎬 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. πŸ’‘πŸ‘‡

πŸ’‘Next stop Β· Lesson 7Design Your Game β†’Turn your big idea into a small game you can actually finish.
← Back to the map