contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Files at this revision

API Documentation at this revision

Comitter:
OmarAlebiary
Date:
Tue May 07 15:17:21 2019 +0000
Parent:
39:822b66b1c935
Commit message:
Final Submission. I have read and agreed with Statement of Academic Integrity

Changed in this revision

GameEngine/RocketRacer.cpp Show annotated file Show diff for this revision Revisions of this file
GameEngine/RocketRacer.h Show annotated file Show diff for this revision Revisions of this file
GameMenus/Menus.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GameEngine/RocketRacer.cpp	Fri May 03 16:57:52 2019 +0000
+++ b/GameEngine/RocketRacer.cpp	Tue May 07 15:17:21 2019 +0000
@@ -6,7 +6,7 @@
 //default constructor of the class and initializing the private variables
 RocketRacer::RocketRacer()
 :first_enemy_position(0),second_enemy_position(0),enemy_phase(0),
-game_speed (0),score(0),Init_position(2),enemy_dead(true),control(true)
+game_speed (0),score(0),pitchAngle(0.0),Init_position(2),enemy_dead(true),control(true)
 {}
 
 //destructor of the class
@@ -14,6 +14,7 @@
 }
 
 /////////setters/////////////////
+
 //sets the enemy position
 void RocketRacer::set_first_position(int first_enemy_position) {
  first_enemy_position = first_enemy_position;
@@ -54,9 +55,10 @@
  Init_position = Init_position;
 }
 
+/////////Game Methods/////////////////
 
 void RocketRacer::Main_Game_Display(N5110 &lcd){
-     
+    
     lcd.clear(); //clears the lcd 
     lcd.drawRect(0,0,46,47,FILL_BLACK);//draws a transparent rectangle on the lcd
     char score_buffer[14];//buffer to store the score 
@@ -81,7 +83,7 @@
 
 void RocketRacer::accelerometer_position(Gamepad &pad){
     
-    float pitchAngle = device.get_pitch_angle();
+    pitchAngle = device.get_pitch_angle();//gets the pitch angle
     //statement to check if the gamepad rolled to the right
     if( (pitchAngle > 100)&& Init_position!=3 && control==true){
         Init_position++;//increments the position of the player sprite 
@@ -130,6 +132,9 @@
 }
 
 
+
+
+
 void RocketRacer::Generate_New_Enemy(){
   
   srand(time(NULL));//seeding the random function
@@ -160,25 +165,39 @@
     
 void RocketRacer::Game_Loop_accelerometer(N5110 &lcd,Gamepad &pad){
     
-        lcd.clear(); //clears the lcd
-        //calls the method to get the joystick direction according to the user
-        accelerometer_position(pad);
-        //calls the method to draw the sprites according to joystick postion
-        player_position(lcd,Init_position);
-        
-        Generate_New_Enemy();//generate 2 new enemies
-        //places the first enemy according to the position
-        enemy_position(lcd,first_enemy_position, enemy_phase);
-        enemy_phase++;//increments the current phase of the enemy
-        enemy_position(lcd,second_enemy_position, enemy_phase);//places the second enemy according to the position
-        enemy_phase++;//increments the current phase of the enemy
-        
-        Check_Enemy_Dead(lcd,pad);//checks if enemies crossed the rocket
-        
-        Game_difficulty(pad); //adds difficulty to the game 
-        
-        lcd.refresh();//refreshes the screen
+    lcd.clear(); //clears the lcd
+    //calls the method to get the joystick direction according to the user
+    accelerometer_position(pad);
+    //calls the method to draw the sprites according to accelerometer postion
+    player_position(lcd,Init_position);  
+    Generate_One_Enemy();//generate 1 new enemy
+    //places the first enemy according to the position
+    enemy_position(lcd,first_enemy_position, enemy_phase);
+    enemy_phase++;//increments the current phase of the enemy
+    //places the second enemy according to the position
+    enemy_position(lcd,second_enemy_position, enemy_phase);
+    enemy_phase++;//increments the current phase of the enemy
+    
+    Check_Enemy_Dead(lcd,pad);//checks if enemies crossed the rocket
+    
+    Game_difficulty(pad); //adds difficulty to the game 
+    
+    lcd.refresh();//refreshes the screen
 }
+
+
+void RocketRacer::Generate_One_Enemy(){
+  
+  srand(time(NULL));//seeding the random function
+  
+  if (enemy_dead){//statement to check if the enemy crossed the player sprite  
+    second_enemy_position = (rand() % 3)+1;//generates a random number from 1 to 3 
+    //printf("%d",second_enemy_position);
+    enemy_phase = 0; 
+    enemy_dead = false;
+    }
+}
+
     
 void RocketRacer::Game_Loop(N5110 &lcd,Gamepad &pad){
     lcd.clear(); //clears the lcd
--- a/GameEngine/RocketRacer.h	Fri May 03 16:57:52 2019 +0000
+++ b/GameEngine/RocketRacer.h	Tue May 07 15:17:21 2019 +0000
@@ -203,6 +203,11 @@
   * @param pad @details calls the Gamepad object to be passed to the methods called inside this method
   */
     void Game_Loop_accelerometer(N5110 &lcd,Gamepad &pad);
+    /**
+  * @brief method that generates one random enemy
+  * @details seeds the rand function then generate a random enemy between 1->3
+  */
+    void Generate_One_Enemy();
     
     
     
@@ -213,6 +218,7 @@
     int enemy_phase;
     int game_speed;
     int score;
+    float pitchAngle;
     char Init_position;
     bool enemy_dead;
     bool control;
--- a/GameMenus/Menus.cpp	Fri May 03 16:57:52 2019 +0000
+++ b/GameMenus/Menus.cpp	Tue May 07 15:17:21 2019 +0000
@@ -53,8 +53,8 @@
 void Menus::check_button_pressed(Gamepad &pad,N5110 &lcd){  
     if (pad.check_event(Gamepad::A_PRESSED) == true){//if A presed 
       pad.leds_off();
-      while(1){//call the game loop
-        Rocket_Race.Game_Loop(lcd,pad);
+      while(pad.check_event(Gamepad::BACK_PRESSED) == false){//loop since back not pressed
+        Rocket_Race.Game_Loop(lcd,pad);//call the game loop
         }
     }else if (pad.check_event(Gamepad::B_PRESSED) == true){//if B presed
       InstructionsMenu(pad,lcd);//call the instructions menu
@@ -63,8 +63,8 @@
       }
     }else if (pad.check_event(Gamepad::Y_PRESSED) == true){//if Y presed
       pad.leds_off();
-      while(1){//call the game loop with accelerometer control
-        Rocket_Race.Game_Loop_accelerometer(lcd,pad);
+      while(pad.check_event(Gamepad::BACK_PRESSED) == false){//loop since back not pressed
+        Rocket_Race.Game_Loop_accelerometer(lcd,pad);//call the game loop with accelerometer control
       }
     }else if (pad.check_event(Gamepad::X_PRESSED) == true){//if X presed
       credits(lcd,pad);//call the credits page
@@ -125,6 +125,7 @@
     lcd.printString("accelormeter",0,1);
     lcd.printString("to control ",0,2);
     lcd.printString("the rocket ",0,3);
+    lcd.printString("in play/acc",0,4);
     
     lcd.printString("< press BACK ", 12, 5);
     lcd.refresh();
--- a/main.cpp	Fri May 03 16:57:52 2019 +0000
+++ b/main.cpp	Tue May 07 15:17:21 2019 +0000
@@ -64,15 +64,7 @@
 int main(){
     
     
-    setup();
-//      test.test_welcomeMenu(pad,lcd);
-//      test.test_Play_Welcome_Melody(pad);
-//      test.test_End_Game_Melody(Gamepad &pad);
-//      test.test_drawMenu(lcd, pad);
-//      test.test_credits_page(lcd,pad);
-//      test.test_loading_menu(lcd);
-//      test.test_InstructionsMenu(pad,lcd);
-//      test.test_Game_Loop(pad,lcd);
+    setup();//initializes all the objects
    
     menus.welcomeMenu(pad,lcd);//displays the welcome menu
     menus.loading_menu(lcd);//displays the loading menu next