![](/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:
- 11:d4aaa959bb20
- Parent:
- 10:7323785c071c
- Child:
- 12:1d3b0218d8d0
diff -r 7323785c071c -r d4aaa959bb20 GameEngine/RocketRacer.cpp --- a/GameEngine/RocketRacer.cpp Thu Mar 28 11:21:39 2019 +0000 +++ b/GameEngine/RocketRacer.cpp Thu Mar 28 11:53:01 2019 +0000 @@ -62,12 +62,10 @@ } -void RocketRacer::GameLoop(N5110 &lcd,Gamepad &pad){ - - lcd.clear(); - + +void RocketRacer::Joystick_position(Gamepad &pad){ Direction d=pad.get_direction(); - + if(d==E && POS!=3 && control==true){ POS++; control = false; @@ -82,10 +80,9 @@ control = true; printf("its middle\n"); } - - player_position(lcd,POS); - - srand(time(NULL)); +} +void RocketRacer::Generate_New_Enemy(){ + srand(time(NULL)); if (enemy_dead){ enemy_0_pos = POS; @@ -93,22 +90,39 @@ enemy_phase = 0; enemy_dead = false; } + } + +void RocketRacer::Check_Enemy_Dead(N5110 &lcd,Gamepad &pad){ + + if (enemy_phase>22 && ((enemy_0_pos == POS) || (enemy_1_pos == POS)) ){ + EndGame(pad,lcd); + } + if (enemy_phase>40){ + enemy_dead = true; + score++; + } + } + +void RocketRacer::GameLoop(N5110 &lcd,Gamepad &pad){ + + lcd.clear(); + + Joystick_position(pad); + player_position(lcd,POS); + + Generate_New_Enemy(); + + enemy_position(lcd,enemy_0_pos, enemy_phase); enemy_phase++; enemy_position(lcd,enemy_1_pos, enemy_phase); enemy_phase++; - if (enemy_phase>22 && ((enemy_0_pos == POS) || (enemy_1_pos == POS)) ){ - EndGame(pad,lcd); - } - if (enemy_phase>40){ - enemy_dead = true; - score++; - } - - Game_difficulty(); - - lcd.refresh(); + Check_Enemy_Dead(lcd,pad); + + Game_difficulty(); + + lcd.refresh(); }