![](/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:
- 13:cec06eb1d7b0
- Parent:
- 12:1d3b0218d8d0
- Child:
- 14:8df7e6fced07
--- a/GameEngine/RocketRacer.cpp Sat Mar 30 13:01:59 2019 +0000 +++ b/GameEngine/RocketRacer.cpp Wed Apr 03 08:50:46 2019 +0000 @@ -1,6 +1,7 @@ #include "RocketRacer.h" - +DigitalIn buttonL(PTB18); +DigitalIn buttonR(PTB3); const int enemy[11][9] = { { 0,0,0,0,1,0,0,0,0 }, @@ -30,14 +31,17 @@ { 0,0,1,1,1,1,1,0,0 }, }; -int first_enemy_position, second_enemy_position, enemy_phase; -int game_speed = 0; -int score = 0; -char POS=2; -bool enemy_dead = true; -bool control = true; + - +RocketRacer::RocketRacer(){ + first_enemy_position=0, second_enemy_position=0, enemy_phase=0; + game_speed = 0; + score = 0; + POS=2; + enemy_dead = true; + control = true; + +} void RocketRacer::Main_Game_Display(N5110 &lcd){ @@ -47,6 +51,8 @@ char score_buffer1[14]; char level_buffer[14]; char level_buffer1[14]; + buttonL.mode(PullDown); + buttonR.mode(PullDown); //dispaly score sprintf(score_buffer,"score"); @@ -66,12 +72,12 @@ void RocketRacer::Joystick_position(Gamepad &pad){ Direction d=pad.get_direction(); - if(d==E && POS!=3 && control==true){ + if((d==E||buttonR==true) && POS!=3 && control==true){ POS++; control = false; printf("its Right\n"); } - else if(d==W && POS!=1 && control==true){ + else if((d==W ||buttonL==true)&& POS!=1 && control==true){ POS--; control = false; printf("its left\n"); @@ -99,6 +105,7 @@ if (enemy_phase>22 && ((first_enemy_position== POS) || (second_enemy_position == POS)) ){ End_Game(pad,lcd); + } if (enemy_phase>40){ enemy_dead = true; @@ -211,8 +218,13 @@ lcd.printString(buffer1,20,4); pad.leds_on(); pad.tone(5000,2); + lcd.refresh(); wait(500); + + + + } \ No newline at end of file