Alright! Now that we’ve defined our game, finished the storyboard, and decided what it is we want to do with our game, it’s time to get started. Of course, the start screen is probably the best place to do that! So, I’ve completed game state 0, the start screen.

Not a lot you can do here, but it does flash every second between “Select = Start” and “Right = Info”. If you push one of those buttons, the game state changes to the appropriate number. I had to use this flashing option because the display is actually only 16×2, and I originally thought it was 18×2. Essentially the screen was too short for the information I wanted to present. However, the flashing options is nice because it shows that the display is active.

Makes me want to play it!

You can check out the latest commit on my GitLab, and here is game state 0:

if (gameState == 0) { // start screen state.
// The initial start screen. Let’s set all game variables for a new game.
// Game variables:
gameState = 0; // The state of game play.
gameBullets = 9; // Number of bullets remaining.
gameSpeed = 1; // The speed of the game.
gameScore = 0; // Number of asteroids destroyed or past.
gamePosition = 0; // Your space ships location, 0 for up, 1 for down.
gameAsteroidOne = 14; // First asteroid starting space.
gameAsteroidTwo = 25; // Second asteroid starting space.
gameAsteroidThree = 17; // Third asteroid starting space.
gameAsteroidFour = 23; // Fourth Asteroid starting space.

lcd.setCursor(0,1); // move to the begining of the second line
if (gameLineNum != 0){
lcd.print(” Right = Info “);
gameLineNum = 0;
} else {
lcd.print(” Select = Start “);
gameLineNum = 1;
}

lcd_key = read_LCD_buttons(); // read the buttons

switch (lcd_key){// depending on which button was pushed, we perform an action

case btnRIGHT:{
gameState = 1;
break;
}
case btnSELECT:{
gameState = 3;
break;
}
}
// Add a delay in the loop.
delay(1000);
} // End gameState 0, asteroids start screen.

As you can see, the most important thing game state 0 does is set all the variables back to the default.

Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *