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: main.cpp
- Revision:
- 29:15e9640646b7
- Parent:
- 28:e0161a52a8b9
- Child:
- 30:863565e9859f
--- a/main.cpp Wed May 08 18:02:11 2019 +0000 +++ b/main.cpp Wed May 08 21:11:35 2019 +0000 @@ -8,10 +8,10 @@ Date: 09/05/2019 */ -#include "mbed.h" -#include "Gamepad.h" -#include "N5110.h" -#include "Engine.h" +#include "mbed.h" +#include "Gamepad.h" +#include "N5110.h" +#include "Engine.h" //structs struct UserInput { @@ -24,9 +24,8 @@ Gamepad pad; Engine eng; Doodler dood; -Enemy eny; -// prototypes +// prototypes void init(); void update_game(UserInput input); void render(); @@ -34,24 +33,31 @@ void game_over(); // functions -int main(){ - while(1){ +int main() +{ + while(1) { init(); welcome(); int fps = 8; render(); // draws wait(1.0f/fps); - while(1){ + while(1) { + render(); eng.read_input(pad); + bool score_added = eng.get_score_check(); eng.update(pad); - render(); + bool updated_score_added = eng.get_score_check(); + if ( (score_added == true) && (updated_score_added == true) ){ + eng.subtract_score(); + } // checking if the previous score has increased by one right after one update means that the a floor + // remains fixed at y = 10 (which adds a score). This will then prevent the score from increasing infinitely. wait(0.8f/fps); bool end_game = eng.get_game_over(); - if (end_game == true){ + if (end_game == true) { game_over(); break; } - if (pad.check_event(Gamepad::BACK_PRESSED) == true){ + if (pad.check_event(Gamepad::BACK_PRESSED) == true) { break; } } @@ -61,24 +67,27 @@ } // initialies all classes and libraries -void init(){ - // need to initialise LCD and Gamepad +void init() +{ + // need to initialise LCD and Gamepad lcd.init(); lcd.setBrightness(1); lcd.setContrast(0.5), - pad.init(); + pad.init(); eng.init(); } -void render(){ +void render() +{ lcd.clear(); eng.draw(lcd); lcd.refresh(); } // Starting menu screen display -void welcome() { - lcd.printString(" Doodle Jump! ",0,1); +void welcome() +{ + lcd.printString(" Doodle Jump! ",0,1); lcd.printString(" Press Start ",0,4); lcd.refresh(); while ( pad.check_event(Gamepad::START_PRESSED) == false) { @@ -89,19 +98,20 @@ } } -void game_over() { +void game_over() +{ lcd.clear(); - lcd.printString("Game Over!",3,1); - lcd.printString("Press back",3,3); + lcd.printString("Game Over!",3,1); + lcd.printString("Press back",3,3); int score = eng.get_score(); char buffer[14]; sprintf(buffer,"SCORE:%d", score); lcd.printString(buffer, 3, 5); lcd.refresh(); while ( pad.check_event(Gamepad::BACK_PRESSED) == false) { - pad.leds_on(); - wait(0.1); - pad.leds_off(); - wait(0.1); + pad.leds_on(); + wait(0.1); + pad.leds_off(); + wait(0.1); } } \ No newline at end of file