A project that creates falling asteroids at random positions along the top of the screen for a space ship at the bottom to shoot, using a Nokia N5110 LCD, joystick and pushbuttons - A revised name from my earlier project L2_2645
Dependencies: DebounceIn N5110 PowerControl mbed
Fork of L2_2645_project by
Diff: main.cpp
- Revision:
- 3:39c95d65bee5
- Parent:
- 2:8d28a2f491eb
--- a/main.cpp Fri May 08 11:30:43 2015 +0000 +++ b/main.cpp Mon May 11 14:37:07 2015 +0000 @@ -16,8 +16,10 @@ Ticker readShoot; /// timer to regularly call new asteroids Ticker readTheAsteroid; -/// timeout to create the asteroids +/// timer to create the asteroids Timer shootSoundtimer; +///timeout used to stop button skip +Timeout EndGame; /** create enumerated type (0,1,2,3 etc. for direction) @@ -60,7 +62,7 @@ asteroid.nscore = 0; srand(15000*randomPin); /// seeding random function calibrateJoystick(); /// set's centred values of joystick - pollJoystick.attach(&updateJoystick,1/45.0); /// read joystick 45 times per second + pollJoystick.attach(&updateJoystick,1/50.0); /// read joystick 50 times per second ship.SetValues(42,39); /// initialise ships starting x,y coordinates PHY_PowerDown(); /// power down ethernet connection @@ -240,8 +242,7 @@ bullet.clearBullet(); /// clear the existing bullet readTheAsteroid.detach(); /// detach the read asteroid function asteroid.destroyAsteroid(); /// destroy asteroid in place - asteroid.nscore=asteroid.nscore-1; /// minus one point for the asteroid that was detroyed in losing - state=3; /// go to state 3 (end screen) + EndGame.attach(&endState,0.3); } else {} lcd.drawLine(0,0,83,0,1); /// keep re-drawing top line as this is damaged while asteroid moves accross it @@ -309,6 +310,7 @@ { lcd.clear(); /// clear entire display to make way for end screen asteroid.nscore = asteroid.nscore-PauseNumber; /// takes points off for the asteroid destroyed when pausing game and destroy asteroid command sent + asteroid.nscore = asteroid.nscore-1; char buffer[14]; /// set buffer to 14, screen 84 pixels long , 6 pixel per char , 84/6 = 14 int score = sprintf(buffer,"Score: %d",asteroid.nscore); /// print formatted data to buffer if (score <= 14) { /// if string will fit on display @@ -328,7 +330,7 @@ lcd.printString(buffer1,7,4); /// display on screen } lcd.printString("game over !",12,0); /// closing message - lcd.printString("Press S4 to",10,1); + lcd.printString("Press S5 to",10,1); lcd.printString("Play again",12,2); lcd.drawLine(0,0,0,47,1); /// draw outline lcd.drawLine(83,0,83,47,1); @@ -336,7 +338,7 @@ lcd.drawLine(0,47,83,47,1); lcd.refresh(); /// refesh LCD to create this display - while(!buttonS) { /// while button b has not been pressed sleep (save power) + while(!buttonP) { /// while button b has not been pressed sleep (save power) Sleep(); } /// when button s pressed @@ -367,6 +369,11 @@ } } +void endState() +{ + state = 3; + } + void calibrateJoystick() {