![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
Diff: GameEngine/RocketRacer.cpp
- Revision:
- 33:24ef796ff2c8
- Parent:
- 32:e5d997d2ed79
- Child:
- 40:13b8467526d0
--- a/GameEngine/RocketRacer.cpp Mon Apr 29 17:34:37 2019 +0000 +++ b/GameEngine/RocketRacer.cpp Fri May 03 00:27:52 2019 +0000 @@ -9,40 +9,47 @@ game_speed (0),score(0),Init_position(2),enemy_dead(true),control(true) {} +//destructor of the class RocketRacer::~RocketRacer(){ } -//setters + +/////////setters///////////////// +//sets the enemy position void RocketRacer::set_first_position(int first_enemy_position) { first_enemy_position = first_enemy_position; } +//sets the second enemy position void RocketRacer::set_second_position(int second_enemy_position) { second_enemy_position = second_enemy_position; } + void RocketRacer::set_enemy_phase(int enemy_phase) { enemy_phase = enemy_phase; } +//sets the game speed void RocketRacer::set_game_speed(int game_speed) { game_speed = game_speed; } +//sets the game score void RocketRacer::set_game_score(int score) { score = score; } - +//sets the flag enemy_dead void RocketRacer::set_enemy_dead(bool enemy_dead) { enemy_dead = enemy_dead; } - +//sets the flag control void RocketRacer::set_control(bool control) { control = control; } - +//sets the initial position void RocketRacer::set_init_position(int Init_position) { Init_position = Init_position; } @@ -75,15 +82,15 @@ 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 + //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 control = false; //sets the flag to false wait(0.1);// 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 + //statement to check if the gamepad rolled to the left + else if( (pitchAngle < 90 )&& Init_position!=1 && control==true){ Init_position--;//decrements the position of the player sprite control = false;//sets the flag to false wait(0.01);// small delay to prevent previous press being detected again @@ -98,8 +105,8 @@ void RocketRacer::Joystick_position(Gamepad &pad){ - - Direction d=pad.get_direction();//assigning the object d to the method to get the joystick direction + //assigning d to the method to get the joystick direction + Direction d=pad.get_direction(); if( (d==E||pad.check_event(Gamepad::R_PRESSED) == true ) && Init_position!=3 && control==true){//statement to check if the joystick moved right @@ -138,62 +145,60 @@ void RocketRacer::Check_Enemy_Dead(N5110 &lcd,Gamepad &pad){ - + //statement to check if the enemies collided with the rocket if (enemy_phase>23 && ((first_enemy_position== Init_position) - || (second_enemy_position == Init_position)) ){//statement to check if the enemies collided with the rocket + || (second_enemy_position == Init_position)) ){ End_Game(pad,lcd);//calls the end game method that displays game over screen - - + } - if (enemy_phase>39){//statement to check if the enemies crossed without colliding with the rocket + if (enemy_phase>39){//statement to check if the enemies crossed without colliding with the rocket enemy_dead = true; score++;//increments the score - } - } + } +} + 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 - + //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); - 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 - } + 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 +} void RocketRacer::Game_Loop(N5110 &lcd,Gamepad &pad){ + lcd.clear(); //clears the lcd - lcd.clear(); //clears the lcd + Joystick_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 - Joystick_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 - } + 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 +} //adds difficulty to the game after proceeding with each level @@ -237,6 +242,7 @@ } + void RocketRacer::player_position(N5110 &lcd,char RocketPosition){ Main_Game_Display(lcd);//displays the game screen @@ -273,5 +279,5 @@ wait(50); - } +}