Hugo Hu / Mbed 2 deprecated BRAVEHEART

Dependencies:   mbed N5110 ShiftReg PinDetect

Revision:
17:d6a3b29cab31
Parent:
16:caf613d5b85e
Child:
18:709ea375b0df
--- a/Game.h	Sun May 10 13:14:33 2015 +0000
+++ b/Game.h	Mon May 11 03:52:18 2015 +0000
@@ -6,61 +6,58 @@
 */
 
 #include "State.h"
-#include "Resources.h" // TODO: Move to State.h ?
+#include "Resources.h"
 #include "Entity.h"
+#include "Enemy.h"
 #include "map.h"
+#include "Geometry.h" // Rectangle and Point structs
 #include <vector>
+#include <sstream>
+#include "Global.h"
 
 #define TERMINAL_VELOCITY 3
 
-/// Simple objects with a position (x,y) and velocity (vx, vy)
-struct Point
-{
-    int x;
-    int y;
-    int vx, vy;
-};
 
-struct Rectangle
-{
-    Rectangle(int x, int y, int w, int h) : x(x), y(y), width(w), height(h) {}
-    int x;
-    int y;
-    int width;
-    int height;
-};
 /// State: Game
 class Game : public State
 {
     public:
         /// Creates the Game state
-        Game(StateManager* fsm, N5110 *lcd, InputManager* input)
-                : State(fsm, lcd, input) {init();}
+        Game(StateManager* fsm, N5110 *lcd, InputManager* input, Sound *sound)
+                : State(fsm, lcd, input, sound) {init();}
+                
+        /// Deconstructor: Frees all memory that was temporarely allocated by the Game state.
+        ~Game();
                                 
-        /// Handle input and update logic
+        /// Handle input and update logic.
         virtual void update(float dt);
         
-        /// Draw state to lcd
+        /// Draw state to lcd.
         virtual void render();
         
         
     private:
-        /// Moves entity in map. If collision occurs, entity can not move further
+        void init();    /// Sets some initial values
         void spawnEnemy();  /// Spawns a new enemy
         void moveEnemies(); /// Movement and AI for all enemies
-        void moveWithCollisionTest(Entity* entity, const int map[HEIGHT][WIDTH]);
+        void moveWithCollisionTest(Entity* entity, const int map[HEIGHT][WIDTH]); /// Moves entity in map. If collision occurs, entity can not move further.
         bool hitTestRect(Rectangle r1, Rectangle r2); /// Returns true if two rectangles overlap
         bool bulletHitMap(Rectangle &bulletColRect, const int map[HEIGHT][WIDTH]); /// Help function for detecting collision between moving bullet and map.
-    
-        void init();    /// Sets some initial values
+        void renderScore(); /// Draws the current score in upper right corner
+        void respawnPlayer(); /// Respawns player at start position
+        
+        int livesLeft; /// The number of lives left
+        bool paused;        // True if the game is paused
+        
+        int spawnRate;  /// Probability of enemy spawning in a single frame/update.
+        static const int spawnPoints[3][2]; /// Positions where enemies can spawn.
+        
         Entity player;  /// Player object
+        std::vector<Point*> bullets;    /// Container for bullets
+        std::vector<Enemy*> enemies;    /// Container for enemies
         
         bool releasedBtnB;  /// True if button B has been released after being pressed down
-        bool releasedBtnC;
-        bool paused;        // True if the game is paused
-        
-        std::vector<Point*> bullets;    /// Container for bullets
-        std::vector<Enemy*> enemies;    /// Container for enemies
+        bool releasedBtnC;  /// True if button C has been released after being pressed down
 };
 
 #endif