In previous episode we introduced clones that retrace your every move. This added tension to each step. Now, in Episode 5, we complete the core gameplay loop by introducing collision detection, game over logic and a restart flow. Thus giving the game consequence and closure.
What We Covered
- Implemented self collision: player dies when colliding with their own body
- Added clone collision: player dies when colliding with enemy body
- Created a game over state that freezes player input and movement
- Clones continue moving after game over for visual payoff
- Displayed a “GAME OVER” message and a “Press Enter to Restart” prompt
- Reset the game cleanly on restart with full state reinitialization
- Animation of Game Over overlay (scale and shake)
This episode gives the player something to fear and a reason to come back for more.
Design Insights
- Used
game.game_over
to gate logic and animation cleanly - Kept clone motion running after game over for stylistic contrast
- Game over UI was rendered directly into the framebuffer for visual consistency
- Cleaned up state via a
RestartGame()
, handling all resets - Basic
ScaleEffect
andShakeEffect
for game over overlay
Implementation Highlights
- Collision detection happens right after
SnakeDoStep()
(and related clone spawning / reducing) game.game_over = true
halts all player behavior- Grid fades, scales and shakes using simple timer based animation
- Restart prompt uses Raylib input to detect
KEY_ENTER
and resets the scene ScaleEffect
instantly increased size of rendered framebuffer and linearly decreases it to normal sizeShakeEffect
is a very basic thing that simply randomly displaces the framebuffer horizontally and vertically
Gameplay Impact
This is the point where Snake Rewind becomes a game and not just a system. Every food pickup is now a calculated risk, every movement is a step toward survival or doom. The game punishes you for being predictable and rewards smart pathing.
What’s Next?
In Episode 6 we will work on score display and feedback, laying the groundwork for juicy UI and animated responses to player progress.