Race around the city collecting the flags while avoiding those that stand in the way of your mission. Make no mistake you will need to be quick to outwit your opponents, they are smart and will try to box you in. I wrote this game to prove that writing a game with scrolling scenery is possible even with the limited 6kB of RAM available. I had to compromise sound effects for features, I wanted multiple opponents, I wanted to be able to drop smoke bombs to trap the opponents but all this required memory so the sound effects had to take a back seat.

Dependencies:   mbed

Revision:
1:1b8125937f28
Parent:
0:d85c449aca6d
--- a/Player.h	Wed Jan 28 03:26:07 2015 +0000
+++ b/Player.h	Sun Feb 01 00:43:25 2015 +0000
@@ -2,6 +2,7 @@
 #include "RallyCar.h"
 #include "Flag.h"
 #include "Smoke.h"
+#include "Beeper.h"
 
 #ifndef __PLAYER_H__
 #define __PLAYER_H__
@@ -12,7 +13,7 @@
     Player(Point startPosition) :
         _startPosition(startPosition),
         _smokeIndex(255),
-        _lives(3),
+        _lives(MAX_LIVES),
         _score(0)
     {            
         reset();
@@ -23,10 +24,17 @@
         setPosition(_startPosition);
         setDirection(Up);
         setDesiredDirection(Up);
-        setState(RallyCar::Driving);
+        setState(RallyCar::Idle);
         setSpriteId(4);
         _fuel = 100;   
         _updateCounter = 0;     
+        
+        if (_flagCount == MAX_FLAGS)
+        {
+            _flagCount = 0;
+        }
+        
+        _stateCounter = 60;
     }
     
     void setCars(RallyCar **cars) { _cars = cars; }
@@ -51,7 +59,14 @@
             _smokeIndex = 0;
         }
         
-        if (getState() == RallyCar::Driving)
+        if (getState() == RallyCar::Idle)
+        {
+            if (--_stateCounter == 0)
+            {
+                setState(RallyCar::Driving);
+            }
+        }
+        else if (getState() == RallyCar::Driving)
         {
             ++_updateCounter;
             if (_updateCounter % FUEL_COUNTER == 0) --_fuel;
@@ -133,18 +148,22 @@
                     flag->setActive(false);
                     getParent()->removeGameObject(flag);
                     _score += 100;                    
+                    ++_flagCount;
+                    Beeper::beep(500, 3);                    
+                    Beeper::beep(2000, 4);                    
+                    Beeper::beep(1000, 2);                    
                 }
             }                        
         }
         else if (getState() == RallyCar::StartCrash)
         {
-            _crashCounter = 30;   
+            _stateCounter = 30;   
             setState(RallyCar::Crashed);         
         }
         else if (getState() == RallyCar::Crashed)
         {
-            setSpriteId(10);            
-            if (--_crashCounter == 0)
+            setSpriteId(10);                        
+            if (--_stateCounter == 0)
             {
                 --_lives;
                 for (int i = 0; i < MAX_CARS; ++i)
@@ -152,6 +171,7 @@
                     _cars[i]->reset();
                 }
             }
+            Beeper::noise(2000, 2);
         }
         
         RallyCar::update();
@@ -160,7 +180,10 @@
     inline uint8_t getLives() { return _lives; }
     inline uint32_t getScore() { return _score; }
     inline uint8_t getFuel() { return _fuel; }
-    
+    inline uint8_t getFlagCount() { return _flagCount; }
+
+    inline void decreaseFuel() { if (_fuel > 0) --_fuel; }
+    inline void increaseScore(int score) { _score += score; }    
 private:    
     void smoke(Direction direction)
     {
@@ -211,6 +234,10 @@
             smoke.setActive(true);            
             _smokeIndex = (_smokeIndex + 1) % MAX_SMOKE;
             _fuel -= 2;
+            
+            Beeper::beep(500, 2);
+            Beeper::beep(1000, 3);
+            Beeper::beep(600, 2);
         }
     }
 
@@ -221,11 +248,12 @@
     RallyCar   **_cars;
     Flag       *_flags; 
     Smoke       _smoke[MAX_SMOKE];
-    uint16_t    _crashCounter;
+    uint16_t    _stateCounter;
         
     uint8_t     _lives;
     uint32_t    _score;
     uint8_t     _fuel;
     uint16_t    _updateCounter;
+    uint8_t     _flagCount;
 };
 #endif //__PLAYER_H__
\ No newline at end of file