Final Submission. I have read and agreed with Statement of Academic Integrity.
Dependencies: mbed Gamepad N5110 Joystick
Diff: main.cpp
- Revision:
- 8:264398d3c610
- Parent:
- 5:23a85b16ee54
- Child:
- 9:a7ea33e6bd82
--- a/main.cpp Thu May 09 09:09:07 2019 +0000 +++ b/main.cpp Thu May 09 10:55:22 2019 +0000 @@ -23,22 +23,26 @@ GameEngine engine; bool game_cont = false; +float speed = 0.0; int main() { - //srand(time(NULL)); Init(); Welcome(); - engine.init(); - //bool game_cont = true; - + while(1) { + engine.direction_reset(); + Menu(); + engine.init(); - while(engine.get_game_cont() == true) { - render(); - update(); + while(engine.get_game_cont() == true) { + render(); + update(); + } + lcd.clear(); + lcd.printString("You Lose",0,0); + lcd.refresh(); + wait(2.0); } - lcd.clear(); - lcd.refresh(); } @@ -67,6 +71,32 @@ wait(2.0); } +// Protoype menu +void Menu() { + //engine.get_dir(gamepad); + int game_speed = 0; + lcd.clear(); + lcd.printString("Select speed",0,0); + lcd.printString("Slowest: X",0,2); + lcd.printString("Fastest: B",0,3); + lcd.refresh(); + + while(game_speed == 0) { + engine.get_dir(gamepad); + if (engine.get_direction() == 2) { + game_speed = 1; + } else if (engine.get_direction() == 3) { + game_speed = 2; + } + } + + if (game_speed == 1) { + speed = 0.5; + } else if (game_speed == 2) { + speed = 0.2; + } +} + // Draws each frame on screen void render() { lcd.clear(); @@ -81,5 +111,5 @@ engine.food_move(); engine.snake_body(lcd); lcd.refresh(); - wait(0.2); + wait(speed); } \ No newline at end of file