This is the last part of the “Kotlin Game Development” series and we are going to add the “game over” scene to our snake game and also reflect on the whole process. It might be helpful to read the previous posts first in order to understand what’s going on.
- Part 1 - Introduction
- Part 2 - Creating a Scene
- Part 3 - Controller Input
- Part 4 - Game Loop
- Part 5 - Game Factory
- Part 6 - Main Menu
- Part 7 - Model
- Part 8 - Game Scene
- Part 9 - Finalizing The Game (you are here)
Game Over Scene
Our game needs one more scene in order to be completed: GameOverScene, let’s add it to our project:
There are 2 major steps happening here:
- scanning the user input
- drawing hint text in the center of our new scene
Let’s go through those steps one by one:
This step is pretty straightforward, we need to scan through all of the input events in order to find out if the ENTER key was pressed. Pressing the ENTER key means we should navigate to the GameScene and restart our game.
Let’s move to the next step:
The first 2 lines are responsible for filling the screen in black. The next two lines are just initializing the font that we want to use for drawing the text and the rest of the code is responsible for actually drawing it. Luckily for us, the Java SDK provides us with the getStringBounds method which can predict the size of the text that we’re going to draw. Using those metrics, we can place our text at the center of the screen:
In this series we’ve covered the basics of game development using Kotlin and we’ve also created a fully playable snake game.
There are far more in the game development than just that. Here is the steps that I recommend if you want to go further (the order is irrelevant):
- learn how to create graphics (raster, vector, 3D objects rendered to 2D images, doesn’t matter)
- learn how to create and add sound effects and music to your game
- learn a game engine, the best choice depends on your experience in programming. I’d recommend Game Maker for total noobs, LibGDX for people who have solid programming skills and something like Unity if you want to sell your game or pursue a career in game development
- copy a few successful games with simple mechanics. It can teach you a lot about the art of making games
- don’t be too hard on yourself. There are tons of things to learn but it is worth it only if you enjoy the process!