![](/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:
- 7:e605dbca7330
- Parent:
- 6:c2040b4cf589
- Child:
- 8:f46db1ff5ec9
--- a/main.cpp Wed Aug 21 20:47:16 2013 +0000 +++ b/main.cpp Wed Aug 21 21:10:38 2013 +0000 @@ -24,6 +24,7 @@ // ~Paddle();//deconstructor int8_t position; uint8_t direction; + void setSpeed(float speed); void setColor(uint8_t red, uint8_t green, uint8_t blue); uint8_t getSize(void); void setSize(uint8_t size); @@ -32,6 +33,9 @@ uint8_t m_red ,m_green ,m_blue; uint8_t m_size; uint8_t m_paddle[MAX_PADDLE_SIZE][3]; + float m_speed; + Ticker UpdatePosition; + void PositionUpdater(void); }; Paddle::Paddle() @@ -40,6 +44,28 @@ setSize(4); position = -getSize(); direction = 1; + setSpeed(50); +} + +void Paddle::setSpeed(float speed) +{ +//truncate + float time; + if(speed > 100000) + speed = 100000; + if(speed <= 0) + speed = 0.001; + m_speed = speed; + time = 1/m_speed; + UpdatePosition.attach(this,&Paddle::PositionUpdater, time); +} + +void Paddle::PositionUpdater(void) +{ + if(direction == 1) + position++; + else + position--; } uint8_t Paddle::getColor(uint8_t pixel, uint8_t color) @@ -138,12 +164,11 @@ while(1) { //PaddleDemo(2,255,10,100); DrawGamePaddle(); - wait(.05); + //wait(.05); //Score(3,2); //WinLoose(2.5, LEFT); if(paddle.direction == 1) { - paddle.position++; if(leftpushed) { leftpushed = false; @@ -152,7 +177,6 @@ } else { - paddle.position--; if(rightpushed) { rightpushed = false;