Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: engine/main.cpp
- Revision:
- 4:a6ca44e29e97
- Parent:
- 3:124a5eb55c77
- Child:
- 5:cd63b0b896aa
--- a/engine/main.cpp Tue May 01 09:06:51 2018 +0000 +++ b/engine/main.cpp Tue May 01 10:03:55 2018 +0000 @@ -57,7 +57,7 @@ { -//set initial location conditions for the player and car and score +//set initial location conditions for the player and car(s) and score x_player = 24; y_player = 29; @@ -66,6 +66,8 @@ x_car = arrayNum[RandIndex]; y_car = 0; + + //set score score = 0; @@ -116,14 +118,42 @@ lcd.drawSprite(x_car,y_car,20,15,(int*) car); y_car++; + lcd.drawSprite(x_car2,y_car2,20,15,(int*) car2); + y_car2++; + +// re-generate cars continously + + if (y_car = 20){ + x_car2 = arrayNum[RandIndex]; + y_car2 = -17; + + + } + + if (y_car2 = 20){ + x_car = arrayNum[RandIndex]; + y_car = -17; + + + } - //display score +//display score score++; // difficulty = read_pot(); sprintf (str, "%d", score); lcd.printString(str,64,1); - + + +//if there is a collision, display "game over" screen + if (x_car = x_player && y_car = 12){ + printf("collision"); + y_car = 12; + score=score; + wait(0.5); + gameOver(); + + } @@ -142,8 +172,19 @@ } - + + } +void gameOver(){ - + lcd.clear(); + lcd.printString(str,64,1); + lcd.printString ("GAME OVER", 3,1); + lcd.printString ("PRESS START TO TRY AGAIN ", 3,10); + + if ( pad.check_event(Gamepad::START_PRESSED) == true) { + + newGame(); + + }