Enemies with states
A slime is a small machine with three states: rest, hop and gone. How the states make it feel alive, and how a few numbers make it dangerous.
Rest, hop, gone
Each slime is always in one of three states. Resting, it waits and counts down. When the count runs out it hops: for 22 frames it moves in one direction. Then it rests again. Gone means it was defeated.
When a hop starts, the slime looks at the hero. If the hero is near, closer than CHASE_RANGE pixels, it hops toward them. If not, it hops one of eight ways at random. That one choice is why slimes seem to notice you.
GBC Intermediate is a course for paid accounts. The rest of this lesson, and its guided session, are in the app.
Next lessonItems and an inventory