contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
Diff: GameEngine/RocketRacer.cpp
- Revision:
- 28:39607fb67e88
- Parent:
- 27:771d186b1bc8
- Child:
- 29:e660274d8222
diff -r 771d186b1bc8 -r 39607fb67e88 GameEngine/RocketRacer.cpp --- a/GameEngine/RocketRacer.cpp Sun Apr 21 11:26:12 2019 +0000 +++ b/GameEngine/RocketRacer.cpp Wed Apr 24 10:19:07 2019 +0000 @@ -3,7 +3,7 @@ /* -default constructor of the class and initializing th eprivate variables +default constructor of the class and initializing the private variables */ RocketRacer::RocketRacer() :first_enemy_position(0),second_enemy_position(0),enemy_phase(0), @@ -44,7 +44,7 @@ && 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.01);// small delay to prevent previous press being detected again + wait(0.09);// small delay to prevent previous press being detected again // printf("its Right\n"); } else if( (d==W ||pad.check_event(Gamepad::L_PRESSED) == true ) @@ -69,23 +69,28 @@ if (enemy_dead){//statement to check if the enemy crossed the player sprite first_enemy_position = Init_position;//places the first enemy above the player's 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::Check_Enemy_Dead(N5110 &lcd,Gamepad &pad){ if (enemy_phase>23 && ((first_enemy_position== Init_position) - || (second_enemy_position == Init_position)) ){//statement to check if the enemies collided with the rocket - End_Game(pad,lcd);//calls the end game method that displays game over screen + || (second_enemy_position == Init_position)) ){//statement to check if the enemies collided with the rocket + 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(N5110 &lcd,Gamepad &pad){ lcd.clear(); //clears the lcd @@ -97,9 +102,9 @@ enemy_position(lcd,first_enemy_position, enemy_phase);//places the first enemy according to the 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++; + enemy_phase++;//increments the current phase of the enemy Check_Enemy_Dead(lcd,pad);//checks if enemies crossed the rocket @@ -136,15 +141,15 @@ void RocketRacer::enemy_position(N5110 &lcd,int place, int phase){ if (place==1){//draws the enemy sprite at position 1 - lcd.drawSprite(2,phase,11,9,(int *)enemy); + lcd.drawSprite(3,phase,11,9,(int *)enemy); } if (place==2){//draws the enemy sprite at position 2 - lcd.drawSprite(18,phase,11,9,(int *)enemy); + lcd.drawSprite(19,phase,11,9,(int *)enemy); } if (place==3){//draws the enemy sprite at position 3 - lcd.drawSprite(34,phase,11,9,(int *)enemy); + lcd.drawSprite(35,phase,11,9,(int *)enemy); } lcd.refresh(); @@ -155,13 +160,13 @@ Main_Game_Display(lcd);//displays the game screen if (RocketPosition==1){//places the rocket at positon 1 - lcd.drawSprite(2,34,11,9,(int *)rocket); + lcd.drawSprite(3,34,11,9,(int *)rocket); } if (RocketPosition==2){//places the rocket at positon 2 - lcd.drawSprite(18,34,11,9,(int *)rocket); + lcd.drawSprite(19,34,11,9,(int *)rocket); } if (RocketPosition==3){//places the rocket at positon 3 - lcd.drawSprite(34,34,11,9,(int *)rocket); + lcd.drawSprite(35,34,11,9,(int *)rocket); } lcd.refresh(); } @@ -181,23 +186,10 @@ pad.leds_on();//turns all leds on lcd.refresh(); - End_Game_Melody(pad); - - wait(500); + tones.End_Game_Melody(pad); //calling tones object to play melody + wait(50); } -void RocketRacer::End_Game_Melody(Gamepad &pad){ - pad.tone(300,1);//makes a tone to indicate gameover - wait(0.25); - pad.tone(450,1);//makes a tone to indicate gameover - wait(0.25); - pad.tone(300,1);//makes a tone to indicate gameover - wait(0.5); - pad.tone(450,1);//makes a tone to indicate gameover - wait(0.25); - pad.tone(300,1);//makes a tone to indicate gameover - wait(1); - } \ No newline at end of file