James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Revision:
29:42651f87522b
Parent:
26:0dc10374546f
Child:
31:c95f1b1d6423
--- a/main.cpp	Thu Apr 25 16:26:34 2019 +0000
+++ b/main.cpp	Sat Apr 27 12:50:30 2019 +0000
@@ -12,6 +12,7 @@
 #include "mbed.h"
 #include "N5110.h"
 #include "BrickBreakerEngine.h"
+#include "ClassicEngine.h"
 #include "OptionsEngine.h"
 #include "SDFileSystem.h"
 #define RADIUS 3
@@ -20,8 +21,10 @@
 //Objects
 Gamepad gamepad;
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+ClassicEngine classic;
 BrickBreakerEngine brick;
 OptionsEngine opt;
+Map map;
 AnalogIn randnoise(PTB0);
 FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL);
 Ball ball;
@@ -45,20 +48,21 @@
 StartOption menu();
 void init();
 void print_start_menu(int output);
+void classic_mode();
 void brickbreaker_mode();
 void options_menu();
 
 
 ////////////////Main Function/////////////////
 
-int fps = 30;
-
+int fps = 16;   //declared globally so it doesn't have to be passed to
+                //the different game mode functions
 int main(){
     init();
     startscreen();
     while(1){
         StartOption choice_selected = menu();
-        if(choice_selected == CLASSIC){ /*engine.classic_mode(accelerometer, gamepad, lcd, fps);*/}
+        if(choice_selected == CLASSIC){ classic_mode();}
         if(choice_selected == BRICKBREAKER){ brickbreaker_mode();}
         if(choice_selected == OPTIONS){ options_menu();}
     }
@@ -74,6 +78,7 @@
     lcd.setContrast(0.55);
     brick.init(RADIUS, ball);
     opt.init();
+    map.init();
     pause.init();
     accelerometer.init();
     sd.disk_initialize();
@@ -138,6 +143,26 @@
         lcd.printString("(A = Select)", 12, 5);
 }
 
+//////////////////Game Mode Functions////////////////////////////////
+
+void classic_mode(){
+    classic.init(ball, map);
+    while(!(map.check_wall_collision(gamepad, ball))){
+        classic.classic_update(ball, accelerometer, map);
+        lcd.clear();
+        classic.classic_draw(lcd, map, ball);
+        lcd.refresh();
+        wait(1/fps);
+        if(gamepad.check_event(gamepad.BACK_PRESSED)){ 
+            PauseOption choice = pause.pause_menu(gamepad, lcd, fps);
+            if(choice == RESUME){}
+            if(choice == RESTART){ classic.init(ball, map); }
+            if(choice == QUIT){ break; }
+            if(choice == HELP){ pause.classic_help(gamepad, lcd); }
+        }
+    }
+}
+
 void brickbreaker_mode(){
     for(int i = 0; i < 45*fps; i++){
         if(i == 1){ brick.set_score(0); }       //reset score when game restarts 
@@ -151,8 +176,8 @@
         lcd.refresh();
         wait_ms(1000/fps);
         if(gamepad.check_event(gamepad.BACK_PRESSED)){
-            int choice = pause.pause_menu(gamepad, lcd, fps, i, BRICKBREAKER_MODE);
-            i = choice;
+            PauseOption choice = pause.pause_menu(gamepad, lcd, fps);
+            i = pause.brickbreaker_action(choice, gamepad, lcd, i, fps);  //returns which frame to jump to
         }
     }
     brick.write_high_scores();
@@ -171,3 +196,5 @@
     if(choice == BALL_SPEED){ opt.change_ball_speed(gamepad, lcd, ball); }
     if(choice == HIGH_SCORES){ opt.view_high_scores(gamepad, lcd); }
 }
+
+