Hugo Hu / Mbed 2 deprecated BRAVEHEART

Dependencies:   mbed N5110 ShiftReg PinDetect

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 "Sprites.h"
00010 #include "ShiftReg.h"
00011 #include "Global.h"
00012 #include <sstream>
00013 
00014 /// State: Game
00015 class Game : public State
00016 {
00017     public:
00018         /// Creates the Game state
00019         Game(StateManager* fsm, N5110 *lcd, InputManager* input, Sound *sound, ShiftReg *shiftreg)
00020                 : State(fsm, lcd, input, sound, shiftreg) 
00021                 {
00022                     gameProperty.currentLayer = 1;
00023                     clearAll();
00024                     init();
00025                 }
00026                 
00027         /// Deconstructor: Frees all memory that was temporarely allocated by the Game state.
00028         ~Game();
00029                                 
00030         /// Handle input and update logic.
00031         virtual void update(float dt);
00032         
00033         /// Draw state to lcd.
00034         virtual void render();
00035         
00036         
00037     private:
00038         void init();    // Sets some initial values
00039         void spawnEnemy();  // Spawns a new enemy
00040         void moveEnemies(); // Movement and AI for all enemies
00041         void moveWithCollisionTest(Entity* entity, const bool map[HEIGHT][WIDTH]); // Moves entity in map. If collision occurs, entity can not move further.
00042         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
00043         bool bulletHitMap(Rectangle &bulletColRect, const bool map[HEIGHT][WIDTH]); // Help function for detecting collision between moving bullet and map.
00044         void renderScore(); // Draws the current score in upper right corner
00045         void respawnPlayer(); // Respawns player at start position
00046         void clearAll(); // Clear all entities
00047     
00048         Map::MapProperty mapProperty;
00049         GameX::GameProperty gameProperty;
00050         
00051         ShiftReg shift;
00052         
00053         bool releasedBtnB;  // True if button B has been released after being pressed down
00054         bool releasedBtnC;  // True if button C has been released after being pressed down
00055         bool releasedBtnD;  // True if button D has been released after being pressed down
00056 };
00057 
00058 #endif