Ellis Blackford Stroud 201155309

Dependencies:   mbed FATFileSystem

Revision:
4:035448357749
Parent:
3:a8960004d261
Child:
5:0b31909caf7f
--- a/main.cpp	Fri Mar 29 18:45:40 2019 +0000
+++ b/main.cpp	Mon Apr 08 15:10:28 2019 +0000
@@ -20,45 +20,41 @@
 Menu menu;
 Ball ball;
 void init();
+int frame_rate = 40;
 
 int main()
 {
     init();
     lcd.clear();
     menu.print_welcome(lcd);
-    menu.print_menu(lcd);
+    menu.print_menu(lcd); 
     bool start_game = false; 
     
-    //menu loop navigates menu until game started
-    while(start_game == false) {
+    while(start_game== false) {   //menu loop navigates menu until game started
+
+        lcd.refresh();
         menu.menu_select(pad, lcd); //main menu cursor code loops until start pressed
-        start_game = menu.menu_change(lcd, pad); //changes menu screen to choice returns true if game started
-        //check if game has been started
-        if(start_game == false) {
-            menu.menu_return(lcd, pad); //if game not started wait until back pressed
-        }
+        start_game = menu.menu_change(lcd, pad); //changes menu screen to choice returns true if game started        
     }  
-    //code to run game 
+    
+    frame_rate = menu.get_frame_rate(); 
+    
+    //game loop to run game
     
     int x_pos = 24;
     int y_pos = 24;
-    float x_vel = 0.0f;
-    float y_vel = 0.0f;
     ball.init(x_pos, y_pos);
-    ball.set_vel(x_vel, y_vel);
     
     while(1){ 
     
-        lcd.clear();
-        ball.move_ball();
-        ball.draw_ball(lcd);
-        ball.read_joy(pad);
-        ball.draw_aim(lcd);
-        ball.draw_screen(lcd);
+        lcd.clear();    
         ball.shoot_ball(pad);
+        ball.move_ball(frame_rate, lcd);
+        ball.draw_screen(lcd, pad);
         lcd.refresh();
 
-        wait(0.1);
+        wait(1.0f/frame_rate); //time between loops/frames
+
     }
     
 }
@@ -66,6 +62,7 @@
 void init()
 {
     lcd.init();
-    lcd.setContrast(0.5);
     pad.init();
+    menu.init();
+    lcd.setContrast(0.5f);
 }