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@19:89c3eeb3761b, 2021-03-25 (annotated)
- Committer:
- hugohu
- Date:
- Thu Mar 25 03:43:10 2021 +0000
- Revision:
- 19:89c3eeb3761b
- Parent:
- 18:709ea375b0df
A more complex game in developing.
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" |
| hugohu | 19:89c3eeb3761b | 9 | #include "Sprites.h" |
| hugohu | 19:89c3eeb3761b | 10 | #include "ShiftReg.h" |
| hugohu | 19:89c3eeb3761b | 11 | #include "Global.h" |
| Siriagus | 17:d6a3b29cab31 | 12 | #include <sstream> |
| Siriagus | 7:678873947b29 | 13 | |
| Siriagus | 12:8178fad5e660 | 14 | /// State: Game |
| Siriagus | 5:100d960fc6d5 | 15 | class Game : public State |
| Siriagus | 5:100d960fc6d5 | 16 | { |
| Siriagus | 5:100d960fc6d5 | 17 | public: |
| Siriagus | 12:8178fad5e660 | 18 | /// Creates the Game state |
| hugohu | 19:89c3eeb3761b | 19 | Game(StateManager* fsm, N5110 *lcd, InputManager* input, Sound *sound, ShiftReg *shiftreg) |
| hugohu | 19:89c3eeb3761b | 20 | : State(fsm, lcd, input, sound, shiftreg) |
| hugohu | 19:89c3eeb3761b | 21 | { |
| hugohu | 19:89c3eeb3761b | 22 | gameProperty.currentLayer = 1; |
| hugohu | 19:89c3eeb3761b | 23 | clearAll(); |
| hugohu | 19:89c3eeb3761b | 24 | init(); |
| hugohu | 19:89c3eeb3761b | 25 | } |
| Siriagus | 17:d6a3b29cab31 | 26 | |
| Siriagus | 17:d6a3b29cab31 | 27 | /// Deconstructor: Frees all memory that was temporarely allocated by the Game state. |
| Siriagus | 17:d6a3b29cab31 | 28 | ~Game(); |
| Siriagus | 12:8178fad5e660 | 29 | |
| Siriagus | 17:d6a3b29cab31 | 30 | /// Handle input and update logic. |
| Siriagus | 7:678873947b29 | 31 | virtual void update(float dt); |
| Siriagus | 12:8178fad5e660 | 32 | |
| Siriagus | 17:d6a3b29cab31 | 33 | /// Draw state to lcd. |
| Siriagus | 7:678873947b29 | 34 | virtual void render(); |
| Siriagus | 8:9ac6a428fa26 | 35 | |
| Siriagus | 8:9ac6a428fa26 | 36 | |
| Siriagus | 5:100d960fc6d5 | 37 | private: |
| Siriagus | 18:709ea375b0df | 38 | void init(); // Sets some initial values |
| Siriagus | 18:709ea375b0df | 39 | void spawnEnemy(); // Spawns a new enemy |
| Siriagus | 18:709ea375b0df | 40 | void moveEnemies(); // Movement and AI for all enemies |
| hugohu | 19:89c3eeb3761b | 41 | void moveWithCollisionTest(Entity* entity, const bool map[HEIGHT][WIDTH]); // Moves entity in map. If collision occurs, entity can not move further. |
| Siriagus | 18:709ea375b0df | 42 | 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 |
| hugohu | 19:89c3eeb3761b | 43 | bool bulletHitMap(Rectangle &bulletColRect, const bool map[HEIGHT][WIDTH]); // Help function for detecting collision between moving bullet and map. |
| Siriagus | 18:709ea375b0df | 44 | void renderScore(); // Draws the current score in upper right corner |
| Siriagus | 18:709ea375b0df | 45 | void respawnPlayer(); // Respawns player at start position |
| hugohu | 19:89c3eeb3761b | 46 | void clearAll(); // Clear all entities |
| hugohu | 19:89c3eeb3761b | 47 | |
| hugohu | 19:89c3eeb3761b | 48 | Map::MapProperty mapProperty; |
| hugohu | 19:89c3eeb3761b | 49 | GameX::GameProperty gameProperty; |
| Siriagus | 17:d6a3b29cab31 | 50 | |
| hugohu | 19:89c3eeb3761b | 51 | ShiftReg shift; |
| Siriagus | 8:9ac6a428fa26 | 52 | |
| Siriagus | 18:709ea375b0df | 53 | bool releasedBtnB; // True if button B has been released after being pressed down |
| Siriagus | 18:709ea375b0df | 54 | bool releasedBtnC; // True if button C has been released after being pressed down |
| hugohu | 19:89c3eeb3761b | 55 | bool releasedBtnD; // True if button D has been released after being pressed down |
| Siriagus | 5:100d960fc6d5 | 56 | }; |
| Siriagus | 5:100d960fc6d5 | 57 | |
| Siriagus | 5:100d960fc6d5 | 58 | #endif |