Andreas Garmannslund / Mbed 2 deprecated SimplePlatformGame

Dependencies:   N5110 PinDetect PowerControl mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Game.h Source File

Game.h

Go to the documentation of this file.
00001 #ifndef GAME_H
00002 #define GAME_H
00003 
00004 /** @file Game.h
00005 *   @author Andreas Garmannslund
00006 */
00007 
00008 #include "State.h "
00009 #include "Entity.h "
00010 #include "Enemy.h"
00011 #include "map.h"
00012 #include "Geometry.h " // Rectangle and Point structs
00013 #include <vector>
00014 #include <sstream>
00015 #include "Global.h"
00016 
00017 #define TERMINAL_VELOCITY 3
00018 
00019 
00020 /// State: Game
00021 class Game : public State
00022 {
00023     public:
00024         /// Creates the Game state
00025         Game(StateManager* fsm, N5110 *lcd, InputManager* input, Sound *sound)
00026                 : State(fsm, lcd, input, sound) {init();}
00027                 
00028         /// Deconstructor: Frees all memory that was temporarely allocated by the Game state.
00029         ~Game();
00030                                 
00031         /// Handle input and update logic.
00032         virtual void update(float dt);
00033         
00034         /// Draw state to lcd.
00035         virtual void render();
00036         
00037         
00038     private:
00039         void init();    // Sets some initial values
00040         void spawnEnemy();  // Spawns a new enemy
00041         void moveEnemies(); // Movement and AI for all enemies
00042         void moveWithCollisionTest(Entity* entity, const int map[HEIGHT][WIDTH]); // Moves entity in map. If collision occurs, entity can not move further.
00043         bool hitTestRect(Rectangle r1, Rectangle r2); // Returns true if two rectangles overlap @see https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection#Axis-Aligned_Bounding_Box
00044         bool bulletHitMap(Rectangle &bulletColRect, const int map[HEIGHT][WIDTH]); // Help function for detecting collision between moving bullet and map.
00045         void renderScore(); // Draws the current score in upper right corner
00046         void respawnPlayer(); // Respawns player at start position
00047         
00048         int livesLeft; // The number of lives left
00049         bool paused;   // True if the game is paused
00050         
00051         int spawnRate;  // Probability of enemy spawning in a single frame/update.
00052         static const int spawnPoints[3][2]; // Positions where enemies can spawn.
00053         
00054         Entity player;  // Player object
00055         std::vector<Point*> bullets;    // Container for bullets
00056         std::vector<Enemy*> enemies;    // Container for enemies
00057         
00058         bool releasedBtnB;  // True if button B has been released after being pressed down
00059         bool releasedBtnC;  // True if button C has been released after being pressed down
00060 };
00061 
00062 #endif