![](/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:
- 14:8df7e6fced07
- Parent:
- 13:cec06eb1d7b0
- Child:
- 15:8a768106c297
--- a/GameEngine/RocketRacer.cpp Wed Apr 03 08:50:46 2019 +0000 +++ b/GameEngine/RocketRacer.cpp Wed Apr 03 09:18:15 2019 +0000 @@ -34,10 +34,11 @@ RocketRacer::RocketRacer(){ + first_enemy_position=0, second_enemy_position=0, enemy_phase=0; game_speed = 0; score = 0; - POS=2; + Init_position=2; enemy_dead = true; control = true; @@ -70,15 +71,16 @@ void RocketRacer::Joystick_position(Gamepad &pad){ + Direction d=pad.get_direction(); - if((d==E||buttonR==true) && POS!=3 && control==true){ - POS++; + if((d==E||buttonR==true) && Init_position!=3 && control==true){ + Init_position++; control = false; printf("its Right\n"); } - else if((d==W ||buttonL==true)&& POS!=1 && control==true){ - POS--; + else if((d==W ||buttonL==true)&& Init_position!=1 && control==true){ + Init_position--; control = false; printf("its left\n"); } @@ -94,7 +96,7 @@ srand(time(NULL)); if (enemy_dead){ - first_enemy_position = POS; + first_enemy_position = Init_position; second_enemy_position = (rand() % 3)+1; enemy_phase = 0; enemy_dead = false; @@ -103,7 +105,7 @@ void RocketRacer::Check_Enemy_Dead(N5110 &lcd,Gamepad &pad){ - if (enemy_phase>22 && ((first_enemy_position== POS) || (second_enemy_position == POS)) ){ + if (enemy_phase>22 && ((first_enemy_position== Init_position) || (second_enemy_position == Init_position)) ){ End_Game(pad,lcd); } @@ -118,7 +120,7 @@ lcd.clear(); Joystick_position(pad); - player_position(lcd,POS); + player_position(lcd,Init_position); Generate_New_Enemy(); @@ -138,7 +140,7 @@ //adds difficulty to the game after proceeding with each level void RocketRacer::Game_difficulty(Gamepad &pad){ - + if (score>=0 && score<=5){ pad.led(1,1.0); game_speed = 1; @@ -173,6 +175,7 @@ void RocketRacer::enemy_position(N5110 &lcd,int place, int phase){ + if (place==1){ lcd.drawSprite(2,phase,11,9,(int *)enemy); } @@ -207,6 +210,7 @@ void RocketRacer::End_Game(Gamepad &pad,N5110 &lcd){ + lcd.clear(); char buffer1[14]; @@ -216,15 +220,11 @@ lcd.printString("High score:",2,3); sprintf(buffer1,"%d",score); lcd.printString(buffer1,20,4); + pad.leds_on(); - pad.tone(5000,2); - - + pad.tone(4500,1); + lcd.refresh(); wait(500); - - - - } \ No newline at end of file