Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed N5110 ShiftReg PinDetect
Game.h@18:709ea375b0df, 2015-05-11 (annotated)
- Committer:
- Siriagus
- Date:
- Mon May 11 04:40:23 2015 +0000
- Revision:
- 18:709ea375b0df
- Parent:
- 17:d6a3b29cab31
- Child:
- 19:89c3eeb3761b
Fixed some formatting errors in documentation.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Siriagus | 5:100d960fc6d5 | 1 | #ifndef GAME_H |
| Siriagus | 5:100d960fc6d5 | 2 | #define GAME_H |
| Siriagus | 5:100d960fc6d5 | 3 | |
| Siriagus | 12:8178fad5e660 | 4 | /** @file Game.h |
| Siriagus | 12:8178fad5e660 | 5 | * @author Andreas Garmannslund |
| Siriagus | 12:8178fad5e660 | 6 | */ |
| Siriagus | 12:8178fad5e660 | 7 | |
| Siriagus | 7:678873947b29 | 8 | #include "State.h" |
| Siriagus | 9:da608ae65df9 | 9 | #include "Entity.h" |
| Siriagus | 17:d6a3b29cab31 | 10 | #include "Enemy.h" |
| Siriagus | 11:adb68da98262 | 11 | #include "map.h" |
| Siriagus | 17:d6a3b29cab31 | 12 | #include "Geometry.h" // Rectangle and Point structs |
| Siriagus | 8:9ac6a428fa26 | 13 | #include <vector> |
| Siriagus | 17:d6a3b29cab31 | 14 | #include <sstream> |
| Siriagus | 17:d6a3b29cab31 | 15 | #include "Global.h" |
| Siriagus | 8:9ac6a428fa26 | 16 | |
| Siriagus | 14:b4fed570abaf | 17 | #define TERMINAL_VELOCITY 3 |
| Siriagus | 14:b4fed570abaf | 18 | |
| Siriagus | 7:678873947b29 | 19 | |
| Siriagus | 12:8178fad5e660 | 20 | /// State: Game |
| Siriagus | 5:100d960fc6d5 | 21 | class Game : public State |
| Siriagus | 5:100d960fc6d5 | 22 | { |
| Siriagus | 5:100d960fc6d5 | 23 | public: |
| Siriagus | 12:8178fad5e660 | 24 | /// Creates the Game state |
| Siriagus | 17:d6a3b29cab31 | 25 | Game(StateManager* fsm, N5110 *lcd, InputManager* input, Sound *sound) |
| Siriagus | 17:d6a3b29cab31 | 26 | : State(fsm, lcd, input, sound) {init();} |
| Siriagus | 17:d6a3b29cab31 | 27 | |
| Siriagus | 17:d6a3b29cab31 | 28 | /// Deconstructor: Frees all memory that was temporarely allocated by the Game state. |
| Siriagus | 17:d6a3b29cab31 | 29 | ~Game(); |
| Siriagus | 12:8178fad5e660 | 30 | |
| Siriagus | 17:d6a3b29cab31 | 31 | /// Handle input and update logic. |
| Siriagus | 7:678873947b29 | 32 | virtual void update(float dt); |
| Siriagus | 12:8178fad5e660 | 33 | |
| Siriagus | 17:d6a3b29cab31 | 34 | /// Draw state to lcd. |
| Siriagus | 7:678873947b29 | 35 | virtual void render(); |
| Siriagus | 8:9ac6a428fa26 | 36 | |
| Siriagus | 8:9ac6a428fa26 | 37 | |
| Siriagus | 5:100d960fc6d5 | 38 | private: |
| Siriagus | 18:709ea375b0df | 39 | void init(); // Sets some initial values |
| Siriagus | 18:709ea375b0df | 40 | void spawnEnemy(); // Spawns a new enemy |
| Siriagus | 18:709ea375b0df | 41 | void moveEnemies(); // Movement and AI for all enemies |
| Siriagus | 18:709ea375b0df | 42 | void moveWithCollisionTest(Entity* entity, const int map[HEIGHT][WIDTH]); // Moves entity in map. If collision occurs, entity can not move further. |
| Siriagus | 18:709ea375b0df | 43 | 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 |
| Siriagus | 18:709ea375b0df | 44 | bool bulletHitMap(Rectangle &bulletColRect, const int map[HEIGHT][WIDTH]); // Help function for detecting collision between moving bullet and map. |
| Siriagus | 18:709ea375b0df | 45 | void renderScore(); // Draws the current score in upper right corner |
| Siriagus | 18:709ea375b0df | 46 | void respawnPlayer(); // Respawns player at start position |
| Siriagus | 17:d6a3b29cab31 | 47 | |
| Siriagus | 18:709ea375b0df | 48 | int livesLeft; // The number of lives left |
| Siriagus | 18:709ea375b0df | 49 | bool paused; // True if the game is paused |
| Siriagus | 17:d6a3b29cab31 | 50 | |
| Siriagus | 18:709ea375b0df | 51 | int spawnRate; // Probability of enemy spawning in a single frame/update. |
| Siriagus | 18:709ea375b0df | 52 | static const int spawnPoints[3][2]; // Positions where enemies can spawn. |
| Siriagus | 17:d6a3b29cab31 | 53 | |
| Siriagus | 18:709ea375b0df | 54 | Entity player; // Player object |
| Siriagus | 18:709ea375b0df | 55 | std::vector<Point*> bullets; // Container for bullets |
| Siriagus | 18:709ea375b0df | 56 | std::vector<Enemy*> enemies; // Container for enemies |
| Siriagus | 8:9ac6a428fa26 | 57 | |
| Siriagus | 18:709ea375b0df | 58 | bool releasedBtnB; // True if button B has been released after being pressed down |
| Siriagus | 18:709ea375b0df | 59 | bool releasedBtnC; // True if button C has been released after being pressed down |
| Siriagus | 5:100d960fc6d5 | 60 | }; |
| Siriagus | 5:100d960fc6d5 | 61 | |
| Siriagus | 5:100d960fc6d5 | 62 | #endif |