submit

Dependencies:   mbed Gamepad N5110

Revision:
2:934daa65f73d
Parent:
1:b49c36604125
Child:
3:1358cbb05ad3
--- a/main.cpp	Sat Apr 13 10:07:50 2019 +0000
+++ b/main.cpp	Sat Apr 13 15:45:03 2019 +0000
@@ -5,12 +5,6 @@
 #include "snake.h"
 #include "Engine.h"
 
-/////////////// structs /////////////////
-struct UserInput {
-    Direction d;
-    float mag;
-};
-
 /////////////// objects ///////////////
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 Gamepad pad;
@@ -19,7 +13,6 @@
 
 ///////////// prototypes ///////////////
 void init();
-void update_game(UserInput input);
 void run();
 void welcome();
 
@@ -31,15 +24,13 @@
     init(); 
     welcome();  // show welcome display, waiting for the user to start
     
-
-    while (1) {
-
+     // game loop - read input, update the game state and render the display
+    while (snake.over == 0) {
     run();
-    wait(5.0f/fps);  // and wait for one frame period
-}
-    
-     // game loop - read input, update the game state and render the display
+    wait(1.0f/fps);  // and wait for one frame period
+    }
 
+ 
 }
 
 // simple splash screen displayed on start-up
@@ -65,9 +56,11 @@
     // clear screen, re-draw and refresh
     lcd.clear();
     int length = snake.get_length();
+    snake.check_eat(pad);
     snake.draw(lcd,length);
     int direction = engine.get_direction(pad);
     snake.update(direction,length);
+    snake.check_over(lcd);
     lcd.refresh();
 }
 
@@ -77,7 +70,7 @@
     // need to initialise LCD and Gamepad 
     lcd.init();
     pad.init();    
-    snake.init(1,3);
+    snake.init(2,3);
      
 }