![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
1D-Pong game based on a LED strip with 150 LPD6803-controlled pixels. Game keeps score for 'best-of-21' game. Written for KL25Z
Diff: main.cpp
- Revision:
- 10:6f9624c7425d
- Parent:
- 9:c5086fe3c0cc
- Child:
- 11:fc80c39ba9f0
--- a/main.cpp Wed Aug 21 22:19:46 2013 +0000 +++ b/main.cpp Wed Aug 21 22:29:30 2013 +0000 @@ -57,6 +57,7 @@ speed = 0.001; m_speed = speed; time = 1/m_speed; + UpdatePosition.detach(); UpdatePosition.attach(this,&Paddle::PositionUpdater, time); } @@ -166,6 +167,7 @@ paddle.setColor(255,0,255); gametimer.start(); while(1) { + static uint8_t naglevel1 = 0, naglevel2 = 0; //PaddleDemo(2,255,10,100); DrawGamePaddle(); //wait(.05); @@ -189,28 +191,33 @@ paddle.direction = 1; } } - if(gametimer.read()>4) + if(gametimer.read()>4 && !naglevel1) { + naglevel1 = 1; paddle.setSize(4); + paddle.setSpeed(40); } - if(gametimer.read()>8) + if(gametimer.read()>8 && !naglevel2) { + naglevel2 = 1; paddle.setSize(2); + paddle.setSpeed(70); } - paddle.setSpeed(gametimer<4?30:gametimer.read()*10); + //paddle.setSpeed(gametimer<4?30:gametimer.read()*10); if(paddle.position >= NUMBER_OF_PIXELS && (paddle.direction == 1)) { //left player scores! left_score++; HandleScore(&left_score,&right_score,false, &gametimer); paddle.position = -paddle.getSize(); - + naglevel1=naglevel2 = 0; } if(paddle.position < -paddle.getSize() && (paddle.direction == 0)) { //right player scores! right_score++; HandleScore(&left_score,&right_score,true, &gametimer); + naglevel1=naglevel2 = 0; paddle.position = NUMBER_OF_PIXELS; } } @@ -218,7 +225,7 @@ void HandleScore(uint8_t *leftscore, uint8_t *rightscore, bool last_won, Timer *gametimer) { - WinLoose(2, last_won); + WinLoose(1.5, last_won); Score(*leftscore, *rightscore); if(*leftscore + *rightscore == 11) { @@ -228,6 +235,7 @@ } (*(mbed::Timer *)gametimer).reset(); paddle.setSize(6); + paddle.setSpeed(30); } void DrawGamePaddle(void) @@ -296,7 +304,7 @@ { write_led(&totalstrip[(NUMBER_OF_PIXELS-1)-(sidecounter*2)],rightled.red,rightled.green,rightled.blue); } - wait(0.7); + wait(0.4); } wait(0.5); }