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:
- 2:a48df109588e
- Parent:
- 1:a3c9025e0dad
- Child:
- 3:124a5eb55c77
diff -r a3c9025e0dad -r a48df109588e engine/main.cpp --- a/engine/main.cpp Tue Apr 24 10:03:41 2018 +0000 +++ b/engine/main.cpp Mon Apr 30 23:29:45 2018 +0000 @@ -17,24 +17,66 @@ N5110 lcd(PTC9, PTC0, PTC7, PTD2, PTD1, PTC11); Gamepad pad; - - +void init(); +void startUp(); +void newGame(); +void gameOver(); int main() +{ + init(); + startUp(); + newGame(); + gameOver(); +} +void init() { // initialise the lcd and gamepad lcd.init(); lcd.setContrast(0.5); pad.init (); +} -//set initial location conditions for the car + +void startUp() +{ + //print start screen + lcd.drawSprite (1,1,8,20,(int*) titlescreen); + lcd.printString ("PRESS START", 3,1); + lcd.refresh(); + while ( pad.check_event(Gamepad::START_PRESSED) == false) { + + } +} + +void newGame() +{ + + +//set initial location conditions for the player and car and score x_player = 24; y_player = 29; + const int arrayNum[3] = {'4', '24', '44'}; + int RandIndex = rand() % 3; + +// x_car = arrayNum[RandIndex]; + x_car = 24; + y_car = 0; + +//set score + score = 0; + + + + + + +//main while loop while (1) { lcd.clear(); @@ -42,15 +84,15 @@ //print the player sprite lcd.drawSprite(x_player,y_player,20,15,(int*) player); -//if L pressed, move player left, if R pressed, move player right - if ( pad.check_event(Gamepad::L_PRESSED) == true) { +//if X pressed, move player left, if B pressed, move player right + if ( pad.check_event(Gamepad::X_PRESSED) == true) { x_player = x_player-20; } if (x_player <4) { x_player = 4; } - if ( pad.check_event(Gamepad::R_PRESSED) == true) { + if ( pad.check_event(Gamepad::B_PRESSED) == true) { x_player = x_player+20; } @@ -66,25 +108,32 @@ lcd.drawRect(41,1,1,1500,FILL_BLACK); lcd.drawRect(61,1,1,1500,FILL_BLACK); - // l1.MoveTo (1,1); - // l1.LineTo (1,50); - -//display score - score = 1; - score = score++; + + + + +//cars move down the road + + lcd.drawSprite(x_car,y_car,20,15,(int*) car); + y_car++; - // lcd.printChar (score*read_pot(), 25,20); + //display score + score++; -//cars move down the road - x_car = 24; - y_car = 1; - - y_car = y_car+1; +// difficulty = read_pot(); + sprintf (str, "%d", score); + lcd.printString(str,64,1); + + + + + + lcd.refresh(); - wait(0.05); + wait(0.1); @@ -94,7 +143,7 @@ } +} -}