ELEC2645 (2018/19) / Mbed 2 deprecated ml16c5l

Dependencies:   mbed

Revision:
4:2848b366ee3d
Parent:
3:5d860d0d589e
Child:
5:331b65d1d280
--- a/main.cpp	Tue Apr 09 10:17:24 2019 +0000
+++ b/main.cpp	Thu Apr 11 09:42:27 2019 +0000
@@ -14,9 +14,6 @@
 #include "N5110.h"
 //#include "CopterEngine.h"
 
-#ifdef WITH_TESTING
-# include "tests.h"
-#endif
 
 
 
@@ -30,34 +27,67 @@
 Gamepad pad;
 //CopterEngine copter;
 
+
+
 ///////////// prototypes ///////////////
 void init();
 void update_game(UserInput input);
 void render();
 void welcome();
 
-///////////// functions ////////////////
+////////////// functions ////////////////
+
+
 int main()
 {
-
-
     int fps = 8;  // frames per second
-
     init();     // initialise and then display welcome screen...
     welcome();  // waiting for the user to start
-    
     render();  // first draw the initial frame 
     wait(1.0f/fps);  // and wait for one frame period
-
-
+    
     // game loop - read input, update the game state and render the display
     while (1) {
+  
+   lcd.clear(); 
+   
+                 int a = copter.GameOver();
+                 if(a == 1)
+                 {   a=0;
+                     lcd.clear();
+                     lcd.printString("GAME OVER", 10,1);
+                     lcd.refresh();
+                     int h=0;
+                     for(h=1; h<=500; h++){
+                     pad.tone(h,0.5);
+                     }
+                     
+                     wait(1.0);
+                     lcd.printString("PRESS BACK" ,13,3);
+                     lcd.printString("RESTART",20,4);
+                     lcd.refresh();
+                       while (pad.check_event(Gamepad::BACK_PRESSED)== false) 
+                       {
+                                  
+                                  pad.leds_on();
+                                  wait(0.1);
+                       }
+                       
+                        init();
+                        welcome();
+                        
+                        render();
+                        wait(1.0f/fps);
+                 }
+    
         copter.read_input(pad);
         copter.update(pad);
+    
         render();
         wait(1.0f/fps);
+        
     }
-}
+} 
 
 // initialies all classes and libraries
 void init()
@@ -66,8 +96,7 @@
     lcd.init();
     pad.init();
      
-    // initialise the game with correct ball and paddle sizes
-    copter.init(COPTER_WIDTH,COPTER_HEIGHT,WALL_SIZE,COPTER_SPEED);
+   copter.init(COPTER_WIDTH,COPTER_HEIGHT,WALL_SIZE,COPTER_SPEED,WALL1_SIZE,WALL2_SIZE);
 
 }
 
@@ -75,24 +104,51 @@
 void render()
 {
     // clear screen, re-draw and refresh
-    lcd.clear();  
+   lcd.clear();  
     copter.draw(lcd);
     lcd.refresh();
 }
 
+
 // simple splash screen displayed on start-up
 void welcome() {
+    pad.leds_on();
+    lcd.printString("COPTER", 25,1);
+    lcd.printString("Press START ",10,3);
+    lcd.printString("to Start ",20,5);
+    lcd.refresh();
     
-    lcd.printString("     Copter!    ",0,1);  
-    lcd.printString("  Press Start ",0,4);
-    lcd.refresh();
-     
+    //print the symbal on the screen
     // wait flashing LEDs until start button is pressed 
     while ( pad.check_event(Gamepad::START_PRESSED) == false) {
         pad.leds_on();
-        wait(0.1);
-        pad.leds_off();
-        wait(0.1);
+        wait(0.2);
+        pad.tone(50,0.1);
+        wait(0.2);
+        pad.tone(100,0.1);
+        wait(0.2);
+        pad.tone(500,0.1);
+        wait(0.2);
+        pad.tone(700,0.1);
+        wait(0.2);
+        pad.tone(500,0.1);
+        wait(0.2);
+        pad.tone(100,0.1);
+        wait(0.2);
+        pad.tone(50,0.1);
+        wait(0.2);
+        pad.tone(100,0.1);
+        wait(0.2);
+        pad.tone(500,0.1);
+        wait(0.2);
+        pad.tone(700,0.1);
+        wait(0.2);
+        pad.tone(500,0.1);
+        wait(0.2);
+        pad.tone(100,0.1);
+        wait(0.2);
+        pad.tone(50,0.1);
+        
     }
  
 }
\ No newline at end of file