Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Game/Game.cpp
- Revision:
- 31:e681177037ef
- Parent:
- 30:91038c2afec7
- Child:
- 32:9c250eda7f3f
--- a/Game/Game.cpp Fri Apr 05 13:54:34 2019 +0000 +++ b/Game/Game.cpp Fri Apr 05 15:34:28 2019 +0000 @@ -6,17 +6,14 @@ Game::Game(){ noOfCubes = 25; //How many cubes are in the scene - homeSelection = 0; //default selection for the home screen + menuSelections.homeMenuSelection = 0; //default selection for the home screen gamepad.init(); renderer.init(); resetScene(); - help = -1; //Set help screen to inactive (-1) + helpScreenNumber = -1; //Set help screen to inactive (-1) input.x = 0; //Set joystick input to 0 input.bCooldown = input.yCooldown = input.aCooldown = false; //Allow buttons to be pressed - deathMenuSelection = true; //Set death menu to highlight restart option - //filePointer = fopen("/sd/topscore.txt", "w"); - //fprintf(filePointer, "%i", score); - pc.printf("a"); + menuSelections.deathMenuSelection = 0; //Set death menu to highlight restart option highScore = readHighScore(); } @@ -54,7 +51,7 @@ while(true) { processInput(); //process user input and store values in input struct renderer.clear(); - if(help > -1){ + if(helpScreenNumber > -1){ helpScreen(); //Show the help screen if the help screen number is above -1 } else if(inHomeMenu){ @@ -113,7 +110,7 @@ } } else{ - coord.x = 0; //if not playing (dead) prevent joystick moving anything + input.x = 0; //if not playing (dead) prevent joystick moving anything } } @@ -123,7 +120,7 @@ highScore = score; writeHighScore(highScore); } - renderer.drawDeathScreen(deathMenuSelection, highScore); //draw death screen if game over + renderer.drawDeathScreen(menuSelections.deathMenuSelection, highScore); //draw death screen if game over deathButtonSelections(); //select menu option } @@ -141,38 +138,38 @@ void Game::deathButtonSelections(){ //determine selection on death screen if(input.yButton){ //if y pressed highlight top option (restart) - deathMenuSelection = true; + menuSelections.deathMenuSelection = 0; } else if(input.aButton){ //if a pressed highlight bottom option (home menu) - deathMenuSelection = false; + menuSelections.deathMenuSelection = 1; } - if (deathMenuSelection && input.bButton){ //if top option highlighted and b pressed then restart game + if (menuSelections.deathMenuSelection == 0 && input.bButton){ //if top option highlighted and b pressed then restart game playing = true; score = 0; resetScore(); resetScene(); } - else if(!deathMenuSelection && input.bButton){ //if bottom option highlighted and b pressed then go to home screen + else if(menuSelections.deathMenuSelection == 1 && input.bButton){ //if bottom option highlighted and b pressed then go to home screen resetScore(); inHomeMenu = true; } } void Game::homeButtonSelections(){ //determine selection on home screen - if(input.yButton && homeSelection > 0){ //if top option isnt highlighted and y pressed then move highlight up - homeSelection--; + if(input.yButton && menuSelections.homeMenuSelection > 0){ //if top option isnt highlighted and y pressed then move highlight up + menuSelections.homeMenuSelection--; } - else if(input.aButton && homeSelection < 2){ //if bottom option isnt highlighted and a pressed then move highlight down - homeSelection++; + else if(input.aButton && menuSelections.homeMenuSelection < 2){ //if bottom option isnt highlighted and a pressed then move highlight down + menuSelections.homeMenuSelection++; } - if (input.bButton && homeSelection == 0){ //if top highlighted and b pressed then start game + if (input.bButton && menuSelections.homeMenuSelection == 0){ //if top highlighted and b pressed then start game inHomeMenu = false; playing = true; } - else if(input.bButton && homeSelection == 1){ //if bottom highlighted and b pressed then exit game - help = 0; + else if(input.bButton && menuSelections.homeMenuSelection == 1){ //if bottom highlighted and b pressed then exit game + helpScreenNumber = 1; } - else if(input.bButton && homeSelection == 2){ //if bottom highlighted and b pressed then exit game + else if(input.bButton && menuSelections.homeMenuSelection == 2){ //if bottom highlighted and b pressed then exit game renderer.turnOff(); exit(0); } @@ -180,30 +177,35 @@ void Game::homeScreen(){//draw home screen homeButtonSelections(); //determine selection on home screen - renderer.drawHomeScreen(homeSelection); + renderer.drawHomeScreen(menuSelections.homeMenuSelection); } void Game::helpScreen(){ //Show help screen depending on help screen number - if (help < 2) { + if (helpScreenNumber == 1) { renderer.drawHelpScreen1(); checkNextHelpScreen(); } - else if (help == 2) { + else if (helpScreenNumber == 2) { renderer.drawHelpScreen2(); checkNextHelpScreen(); } - else if (help == 3) { + else if (helpScreenNumber == 3) { renderer.drawHelpScreen3(); checkNextHelpScreen(); } - else if (help == 4) { //if past last screen then set help screen number to disabled (-1) - help = -1; + else if (helpScreenNumber == 4) { + renderer.drawHelpScreen4(); + checkNextHelpScreen(); + + } + else if (helpScreenNumber == 5) { //if past last screen then set help screen number to disabled (-1) + helpScreenNumber = -1; } } void Game::checkNextHelpScreen(){ //if a button pressed then advance help screen if(input.bButton){ - help ++; + helpScreenNumber ++; } } @@ -218,10 +220,10 @@ disableBButton(b); } -void Game::disableYButton(bool y){ //Set y button to disabled, call function to reenable in 0.3 seconds +void Game::disableYButton(bool y){ //Set y button to disabled, call function to reenable in 0.2 seconds if(!input.yCooldown && y){ input.yCooldown = true; - disableY.attach(callback(this, &Game::enableY), 0.3); //attach function to ticker to renable y button + disableY.attach(callback(this, &Game::enableY), 0.2); //attach function to ticker to renable y button input.yButton = true; } else{ @@ -229,10 +231,10 @@ } } -void Game::disableAButton(bool a){ //Set a button to disabled, call function to reenable in 0.3 seconds +void Game::disableAButton(bool a){ //Set a button to disabled, call function to reenable in 0.2 seconds if(!input.aCooldown && a){ input.aCooldown = true; - disableA.attach(callback(this, &Game::enableA), 0.3); //attach function to ticker to renable a button + disableA.attach(callback(this, &Game::enableA), 0.2); //attach function to ticker to renable a button input.aButton = true; } else{ @@ -240,10 +242,10 @@ } } -void Game::disableBButton(bool b){ //Set b button to disabled, call function to reenable in 0.3 seconds +void Game::disableBButton(bool b){ //Set b button to disabled, call function to reenable in 0.2 seconds if(!input.bCooldown && b){ input.bCooldown = true; - disableB.attach(callback(this, &Game::enableB), 0.3); //attach function to ticker to renable b button + disableB.attach(callback(this, &Game::enableB), 0.2); //attach function to ticker to renable b button input.bButton = true; } else{