contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Revision:
30:c5060010a1e6
Parent:
29:e660274d8222
Child:
31:4d4a9d78cae5
--- a/GameEngine/RocketRacer.cpp	Thu Apr 25 10:44:53 2019 +0000
+++ b/GameEngine/RocketRacer.cpp	Sat Apr 27 02:00:28 2019 +0000
@@ -1,10 +1,9 @@
 #include "RocketRacer.h"
 
 
+FXOS8700CQ device(I2C_SDA,I2C_SCL);
 
-/*
-default constructor of the class and initializing the private variables
-*/
+//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)
@@ -65,8 +64,33 @@
     }
 
 
+void RocketRacer::accelerometer_position(Gamepad &pad){
+    
+    float pitchAngle = device.get_pitch_angle();
+if( (pitchAngle > 100)
+     && Init_position!=3 && control==true){//statement to check if the joystick moved right
+        Init_position++;//increments the position of the player sprite 
+        control = false; //sets the flag to false
+        wait(0.09);// small delay to prevent previous press being detected again
+//        printf("its Right\n");
+    }
+    else if( (pitchAngle < 90 )
+    && Init_position!=1 && control==true){//statement to check if the joystick moved left
+        Init_position--;//decrements the position of the player sprite
+        control = false;//sets the flag to false
+        wait(0.09);// small delay to prevent previous press being detected again
+//        printf("its left\n");
+    }
+    else {//statement to check if the joystick position is center
+        control = true;//sets the flag to true
+        wait(0.09);
+//        printf("its center\n");
+        }    
+}
+
+
 void RocketRacer::Joystick_position(Gamepad &pad){
-    
+      
     Direction d=pad.get_direction();//assigning the object d to the method to get the joystick direction
 
     if( (d==E||pad.check_event(Gamepad::R_PRESSED) == true )
@@ -119,6 +143,27 @@
          }  
     }
     
+void RocketRacer::Game_Loop_accelerometer(N5110 &lcd,Gamepad &pad){
+    
+        lcd.clear(); //clears the lcd
+    
+        accelerometer_position(pad);//calls the method to get the joystick direction according to the user
+        player_position(lcd,Init_position);//calls the method to draw the sprites according to joystick postion
+            
+        Generate_New_Enemy();//generate 2 new enemies
+        
+        
+         enemy_position(lcd,first_enemy_position, enemy_phase);//places the first enemy according to the position
+         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
+    }
     
 void RocketRacer::Game_Loop(N5110 &lcd,Gamepad &pad){