contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Revision:
40:13b8467526d0
Parent:
33:24ef796ff2c8
--- 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