Making a Python game - Start and end screens - Part 4

Last time in this series, we got the game to the point , where it seems like it is finally playable.But as the game's programmer some things are obvious to to you and me that wouldn't be that obvious  to someone else , they might even have no idea what to do !
so we shall add a start screen , with instructions on how to play.
we also saw that the game quits too quickly after the player hits the obstacle , we don't even get to final score !,
so, we shall add an end screen to display this final score as well as the current game speed.

Let's begin by adding some constants and variables to store our game's instructions and states

The constant "STARTSCREEN_TEXT"  stores the entire instructions you want to display on the startscreen  , divided in multiple pages and lines, ready to be displayed on the screen.

The variable "startstate" stores the page number on the start screen.

Next, we will add the startscreen and endscreen functions to the game.

startscreen displays the first page of the "STARTSCREEN_TEXT" and waits for a key press , if "space" is pressed then it moves to the next page , else if "esc" is pressed it skips the start screen and directly enters the game

endscreen simply shows the score and the game speed and waits for the player to press "esc" , on doing so it will quit the game.

now that our functions have been defined , we will integrate them in our game.
we need to show the start screen , before our game loop and the endscreen after our game loop, so we call these functions in these respective positions.



now , try running the game , you will see something like this ,

The startscreen.
The game play , is exactly like the last version

The Score and speed displayed after crashing into an opponent

you will see that the game looks really good at this point , however , we still need to add an option to replay the game,instead of just quitting the game after the player loses. that will require some restructuring of the code. but we'll leave that for some other time
The code for this post can be found at the Git repo in the file "Cgame_part3.py"



Comments