Level Up Your Snake, Part 5: A Proper Game Over
- Marcel Pflug
- 4 hours ago
- 2 min read
Our game now runs through three lives and then simply stops, leaving the last crash frozen on screen. That is a flat way to finish. In this part we give the game a real ending: a GAME OVER screen that announces the result, shows the final score, and invites the player to press START for another go. It reuses everything we have already built, so it is short and satisfying.
The Game-Over Screen
Just like the title screen in Part 2, the game-over screen is nothing more than text placed on a cleared display, using the font from Part 1 and the number-drawing helper from Part 3:
void game_over_screen(void) {
clear_screen();
draw_text(7, 4, "GAME");
draw_text(7, 6, "OVER");
draw_text(6, 9, "SCORE");
draw_num3(12, 9, score); // the final score
draw_text(4, 13, "PRESS START");
}There is nothing new to learn here, which is rather the point. clear_screen() blanks the display. The two draw_text lines stack the words GAME and OVER in the middle, on rows 4 and 6. The next pair writes the label SCORE and then, with draw_num3, the player's final score right beside it, so they can see how they did. The last line writes PRESS START near the bottom. Every tool in this function is one we built in an earlier part, now paying us back.

Wiring It Into the Game
Now we just call it at the right moment. In Part 4 the lives loop kept running while lives remained; the instant it ends, all lives are gone, so that is exactly where the game-over screen belongs:
// ... the while (lives > 0) loop has just ended ...
game_over_screen();
waitpad(J_START); // wait for the player to press START
waitpadup(); // then loop back to the title screenIn plain words: as soon as the lives run out and that loop finishes, game_over_screen() paints the ending. waitpad(J_START) then holds everything there until the player presses START, so the result stays on screen for as long as they like. waitpadup() waits for them to release the button, and because this whole block sits inside the game's main outer loop, releasing START quietly carries us right back to the title screen from Part 2, ready for a fresh game. The player can now lose, see their score, and jump straight back in, which is the loop every arcade game is built on.
Coming Up in Part 6
The game is now complete from start to finish. In the final part we add the two touches that make it a pleasure to play: sound, so eating and dying actually make a noise, and a pause function so you can stop mid-game. Then we hand you the whole finished project to download.
The console this game runs on is documented, with photographs, in the collection.










Comments