contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
Diff: GameEngine/RocketRacer.cpp
- Revision:
- 10:7323785c071c
- Parent:
- 9:edb39a8334ee
- Child:
- 11:d4aaa959bb20
diff -r edb39a8334ee -r 7323785c071c GameEngine/RocketRacer.cpp --- a/GameEngine/RocketRacer.cpp Wed Mar 27 00:04:00 2019 +0000 +++ b/GameEngine/RocketRacer.cpp Thu Mar 28 11:21:39 2019 +0000 @@ -45,24 +45,26 @@ lcd.drawRect(0,0,50,47,FILL_TRANSPARENT); char buffer[14]; char buffer1[14]; -// int score=64; - + char buffer2[14]; + char buffer3[14]; + + //dispaly score sprintf(buffer,"score"); lcd.printString(buffer,55,0); sprintf(buffer1,"%d",score); lcd.printString(buffer1,58,1); + //dispaly level + sprintf(buffer2,"Level"); + lcd.printString(buffer2,55,3); + sprintf(buffer3,"%d",game_speed); + lcd.printString(buffer3,58,4); lcd.refresh(); } void RocketRacer::GameLoop(N5110 &lcd,Gamepad &pad){ -lcd.clear(); -//MainGameDisplay(lcd); -// POS=2; -// score=0; -// enemy_dead = true; -// control = true; + lcd.clear(); Direction d=pad.get_direction(); @@ -97,18 +99,43 @@ enemy_phase++; if (enemy_phase>22 && ((enemy_0_pos == POS) || (enemy_1_pos == POS)) ){ - EndGame(lcd); + EndGame(pad,lcd); } if (enemy_phase>40){ enemy_dead = true; score++; } - wait(0.1); + + Game_difficulty(); + lcd.refresh(); } - +//adds difficulty to the game after proceeding each level +void RocketRacer::Game_difficulty(){ + + if (score>=0 && score<=5){ + game_speed = 1; + wait(0.09); + } + if (score>5 && score<=10){ + game_speed = 2; + wait(0.07); + } + if (score>10 && score<=20){ + game_speed = 3; + wait(0.06); + } + if (score>20 && score<=30){ + game_speed = 4; + wait(0.05); + } + if (score>30){ + game_speed = 5; + wait(0.03); + } + } void RocketRacer::enemy_position(N5110 &lcd,int place, int phase){ @@ -145,12 +172,19 @@ } -void RocketRacer::EndGame(N5110 &lcd){ - lcd.clear(); while(1){ +void RocketRacer::EndGame(Gamepad &pad,N5110 &lcd){ + lcd.clear(); + char buffer1[14]; lcd.printString("Game over!!!",5,0); - lcd.printString("Better Luck ",2,2); - lcd.printString("next time",2,3); - } -// lcd.refresh(); + lcd.printString("Better Luck ",2,1); + lcd.printString("next time",2,2); + lcd.printString("High score:",2,3); + + sprintf(buffer1,"%d",score); + lcd.printString(buffer1,20,4); + pad.leds_on(); + + lcd.refresh(); + wait(500); } \ No newline at end of file