1D-Pong game based on a LED strip with 150 LPD6803-controlled pixels. Game keeps score for 'best-of-21' game. Written for KL25Z

Dependencies:   MODSERIAL mbed

Revision:
9:c5086fe3c0cc
Parent:
8:f46db1ff5ec9
Child:
10:6f9624c7425d
--- a/main.cpp	Wed Aug 21 21:55:40 2013 +0000
+++ b/main.cpp	Wed Aug 21 22:19:46 2013 +0000
@@ -12,7 +12,7 @@
 void UpdateDemoPaddle(void);
 void Score(uint8_t left, uint8_t right);
 void DrawGamePaddle(void);
-
+void HandleScore(uint8_t *, uint8_t *, bool, Timer *);
 uint16_t totalstrip[NUMBER_OF_PIXELS];
 volatile int8_t paddlestart= 0;
 SPI ledstrip(PTD2,NC,PTD1);
@@ -164,6 +164,7 @@
     paddle.setSize(6);
     paddle.setSpeed(30);
     paddle.setColor(255,0,255);
+    gametimer.start();
     while(1) {
         //PaddleDemo(2,255,10,100);
         DrawGamePaddle();
@@ -188,17 +189,20 @@
                     paddle.direction = 1;
             }
         }
+        if(gametimer.read()>4)
+        {
+            paddle.setSize(4);
+        }
+        if(gametimer.read()>8)
+        {
+            paddle.setSize(2);
+        }   
+        paddle.setSpeed(gametimer<4?30:gametimer.read()*10);
         if(paddle.position >= NUMBER_OF_PIXELS && (paddle.direction == 1))
         {
             //left player scores!
             left_score++;
-            WinLoose(2, false);
-            Score(left_score, right_score);
-            if(left_score+right_score == 11)
-            {
-                left_score = right_score = 0;
-                Randomblinks(2,5);
-            }
+            HandleScore(&left_score,&right_score,false, &gametimer);
             paddle.position = -paddle.getSize();
             
         }
@@ -206,18 +210,26 @@
          {
             //right player scores!
             right_score++;
-            WinLoose(2, true);
-            if(left_score+right_score == 11)
-            {
-                left_score = right_score = 0;
-                Randomblinks(2,5);
-            }
-            Score(left_score, right_score);
+             HandleScore(&left_score,&right_score,true, &gametimer);
             paddle.position = NUMBER_OF_PIXELS;
          }
     }
 }
 
+void HandleScore(uint8_t *leftscore, uint8_t *rightscore, bool last_won, Timer *gametimer)
+{
+    WinLoose(2, last_won);
+    Score(*leftscore, *rightscore);
+    if(*leftscore + *rightscore == 11)
+    {
+       *leftscore = 0;
+       *rightscore = 0;
+       Randomblinks(2,5);
+    }
+    (*(mbed::Timer *)gametimer).reset();
+    paddle.setSize(6);
+}
+
 void DrawGamePaddle(void)
 {
     uint8_t ledcounter;