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
Gameengine/Gameengine.h@49:9bea7089b657, 2019-04-24 (annotated)
- Committer:
- el17arm
- Date:
- Wed Apr 24 16:45:47 2019 +0000
- Revision:
- 49:9bea7089b657
- Parent:
- 48:bd1f31fbfee3
- Child:
- 56:8c827d1cae3b
Sprites documentation
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el17arm | 29:d85886364643 | 1 | #ifndef GAMEENGINE_H |
| el17arm | 29:d85886364643 | 2 | #define GAMEENGINE_H |
| el17arm | 29:d85886364643 | 3 | |
| el17arm | 29:d85886364643 | 4 | #include "mbed.h" |
| el17arm | 29:d85886364643 | 5 | #include "N5110.h" |
| el17arm | 29:d85886364643 | 6 | #include "Gamepad.h" |
| el17arm | 33:023f57d52b1c | 7 | #include "Sprites.h" |
| el17arm | 42:d81c008b0436 | 8 | #include "Levels.h" |
| el17arm | 32:5dc769ba4a58 | 9 | |
| el17arm | 45:bad704c546d4 | 10 | /** Gameengine Class |
| el17arm | 46:de3462ad5aef | 11 | @brief Builds all levels and sets all default values. Updates all game settings |
| el17arm | 46:de3462ad5aef | 12 | and contains functions for all game conditions |
| el17arm | 46:de3462ad5aef | 13 | |
| el17arm | 45:bad704c546d4 | 14 | @author Andrew Milner University of Leeds |
| el17arm | 46:de3462ad5aef | 15 | |
| el17arm | 45:bad704c546d4 | 16 | @date April 2019 |
| el17arm | 45:bad704c546d4 | 17 | */ |
| el17arm | 41:0cf320f73424 | 18 | |
| el17arm | 29:d85886364643 | 19 | class Gameengine |
| el17arm | 29:d85886364643 | 20 | { |
| el17arm | 29:d85886364643 | 21 | |
| el17arm | 29:d85886364643 | 22 | public: |
| el17arm | 49:9bea7089b657 | 23 | /** constructor |
| el17arm | 49:9bea7089b657 | 24 | */ |
| el17arm | 29:d85886364643 | 25 | Gameengine(); |
| el17arm | 49:9bea7089b657 | 26 | /** deconstructor |
| el17arm | 49:9bea7089b657 | 27 | */ |
| el17arm | 29:d85886364643 | 28 | ~Gameengine(); |
| el17arm | 49:9bea7089b657 | 29 | /** Initialises all default game settings. |
| el17arm | 49:9bea7089b657 | 30 | * @details Sets player starting position, number of lives, level start and timer. |
| el17arm | 49:9bea7089b657 | 31 | */ |
| el17arm | 46:de3462ad5aef | 32 | void game_init(); |
| el17arm | 49:9bea7089b657 | 33 | /** Updates all game game settings. |
| el17arm | 49:9bea7089b657 | 34 | * @details Contains all functions that update player position and game conditions |
| el17arm | 49:9bea7089b657 | 35 | such as lives left, timer, game over and level complete. |
| el17arm | 49:9bea7089b657 | 36 | */ |
| el17arm | 46:de3462ad5aef | 37 | void update(N5110 &lcd, Gamepad &pad); |
| el17arm | 49:9bea7089b657 | 38 | /** Updates and renders all level objects for level 1. |
| el17arm | 49:9bea7089b657 | 39 | */ |
| el17arm | 46:de3462ad5aef | 40 | void draw_l1(N5110 &lcd, Gamepad &pad); |
| el17arm | 49:9bea7089b657 | 41 | /** Updates and renders all level objects for level 2. |
| el17arm | 49:9bea7089b657 | 42 | */ |
| el17arm | 46:de3462ad5aef | 43 | void draw_l2(N5110 &lcd, Gamepad &pad); |
| el17arm | 49:9bea7089b657 | 44 | /** Updates and renders all level objects for level 3. |
| el17arm | 49:9bea7089b657 | 45 | */ |
| el17arm | 46:de3462ad5aef | 46 | void draw_l3(N5110 &lcd, Gamepad &pad); |
| el17arm | 49:9bea7089b657 | 47 | /** |
| el17arm | 49:9bea7089b657 | 48 | * @brief Reads direction the player is moving. |
| el17arm | 49:9bea7089b657 | 49 | * @details Uses getdirection() function from Gamepad library. |
| el17arm | 49:9bea7089b657 | 50 | */ |
| el17arm | 29:d85886364643 | 51 | void read_direction(Gamepad &pad); |
| el17arm | 49:9bea7089b657 | 52 | /** Calculates lives remaining. |
| el17arm | 49:9bea7089b657 | 53 | * @returns integer calue to control lives fsm state in leds() main.cpp |
| el17arm | 49:9bea7089b657 | 54 | */ |
| el17arm | 49:9bea7089b657 | 55 | int lives_leds(); |
| el17arm | 49:9bea7089b657 | 56 | /** Calculates time remaining. |
| el17arm | 49:9bea7089b657 | 57 | * @details Calculates time remaining, every 1/3 of total time passed the return |
| el17arm | 49:9bea7089b657 | 58 | * value changes. |
| el17arm | 49:9bea7089b657 | 59 | * @return integer value to control oxygen fsm state in leds() main.cpp |
| el17arm | 49:9bea7089b657 | 60 | */ |
| el17arm | 46:de3462ad5aef | 61 | int oxygen_leds(); |
| el17arm | 49:9bea7089b657 | 62 | /** |
| el17arm | 49:9bea7089b657 | 63 | * @brief Calculates and displays player score. |
| el17arm | 49:9bea7089b657 | 64 | * @details At game over or game completed the players score is calculated and |
| el17arm | 49:9bea7089b657 | 65 | * displayed. It takes time remaining and multiplies this by lives remaining, then |
| el17arm | 49:9bea7089b657 | 66 | * adds on 10 points for every key collected. |
| el17arm | 49:9bea7089b657 | 67 | */ |
| el17arm | 46:de3462ad5aef | 68 | void get_score(N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 69 | /** Returns true if game completed. |
| el17arm | 49:9bea7089b657 | 70 | * @details calculates when _level variable has gone beyond number of levels in game. |
| el17arm | 49:9bea7089b657 | 71 | * @return true if game complete |
| el17arm | 49:9bea7089b657 | 72 | */ |
| el17arm | 46:de3462ad5aef | 73 | bool game_complete(N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 74 | /** Reduces number of lives on player death. |
| el17arm | 49:9bea7089b657 | 75 | * @details After reducing lives, makes tone to signify player death, resets player |
| el17arm | 49:9bea7089b657 | 76 | * back to start, creates small pause. |
| el17arm | 49:9bea7089b657 | 77 | */ |
| el17arm | 41:0cf320f73424 | 78 | void lose_life(Gamepad &pad, N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 79 | /** States whether game over condition met |
| el17arm | 49:9bea7089b657 | 80 | * @return returns true if game over. |
| el17arm | 49:9bea7089b657 | 81 | */ |
| el17arm | 29:d85886364643 | 82 | bool game_over(); |
| el17arm | 49:9bea7089b657 | 83 | /** Returns true when player at exit. |
| el17arm | 49:9bea7089b657 | 84 | * @return Function returns true when the player is in contact with the level exit. |
| el17arm | 49:9bea7089b657 | 85 | */ |
| el17arm | 46:de3462ad5aef | 86 | bool level_exit(N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 87 | /** Returns true when level complete conditions met. |
| el17arm | 49:9bea7089b657 | 88 | * @details Function returns true when all 5 keys have been collected using _sprites.keys_collected() |
| el17arm | 49:9bea7089b657 | 89 | * and player is in contact with the level exit using level_exit() function. |
| el17arm | 49:9bea7089b657 | 90 | * Calculates time reamining then resets, resets enemy and key flags |
| el17arm | 49:9bea7089b657 | 91 | * so they can be initialised for the next level, increases _level by 1 so next |
| el17arm | 49:9bea7089b657 | 92 | * level will be drawn, keys needed increased by 5 and miner position reset. |
| el17arm | 49:9bea7089b657 | 93 | */ |
| el17arm | 33:023f57d52b1c | 94 | void next_level(N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 95 | /** Returns true if player in contact with trap |
| el17arm | 49:9bea7089b657 | 96 | * @details Function sets all trap poisitons and collision rules. Usues int i |
| el17arm | 49:9bea7089b657 | 97 | * to select which level positions to use. |
| el17arm | 49:9bea7089b657 | 98 | */ |
| el17arm | 34:c5a042973e0c | 99 | bool trap_death(N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 100 | /** Returns true if player in contact with trap. |
| el17arm | 49:9bea7089b657 | 101 | * @details Function sets all trap positons and collision rules stated in |
| el17arm | 49:9bea7089b657 | 102 | * Sprites class. Uses int i to select which level positions to use, these are |
| el17arm | 49:9bea7089b657 | 103 | * specified in Level class. |
| el17arm | 49:9bea7089b657 | 104 | */ |
| el17arm | 37:4d525a37d5d2 | 105 | void key_draw(N5110 &lcd,Gamepad &pad); |
| el17arm | 49:9bea7089b657 | 106 | /** Sets all block positions and collision rules. |
| el17arm | 49:9bea7089b657 | 107 | * @details Function sets all block positons and collision rules stated in |
| el17arm | 49:9bea7089b657 | 108 | * Sprites class. Blocks are indexed so each one is treated independently |
| el17arm | 49:9bea7089b657 | 109 | * otherwise all will disappear if one is collected. Uses int i to select which |
| el17arm | 49:9bea7089b657 | 110 | * level positions to use, these are specified in Level class. Int i is set _level |
| el17arm | 49:9bea7089b657 | 111 | * so function knows which level settings to use. |
| el17arm | 49:9bea7089b657 | 112 | */ |
| el17arm | 38:55bb9da08a52 | 113 | void blocks(N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 114 | /** Initialises enemies, updates movements and detects collision with player. |
| el17arm | 49:9bea7089b657 | 115 | * @details Only initialises enemies when enem_flag set to false and sets it true |
| el17arm | 49:9bea7089b657 | 116 | * once done. Function also updates enemy position and detects collision with players, |
| el17arm | 49:9bea7089b657 | 117 | * int i states which level settings to use. |
| el17arm | 49:9bea7089b657 | 118 | * @return true if player collides with enemy. |
| el17arm | 49:9bea7089b657 | 119 | */ |
| el17arm | 38:55bb9da08a52 | 120 | bool enemies(N5110 &lcd); |
| el17arm | 49:9bea7089b657 | 121 | /** Reinitialises keys once new level starts. |
| el17arm | 49:9bea7089b657 | 122 | * @details Once level is complete the _key_reint flag is set to false and all |
| el17arm | 49:9bea7089b657 | 123 | * 5 level keys are set to false. This means they are drawn in new positions as |
| el17arm | 49:9bea7089b657 | 124 | * per int i which states which level settings to use in key_draw(). |
| el17arm | 49:9bea7089b657 | 125 | */ |
| el17arm | 40:913339e324b8 | 126 | void key_reinit(); |
| el17arm | 29:d85886364643 | 127 | |
| el17arm | 29:d85886364643 | 128 | private: |
| el17arm | 29:d85886364643 | 129 | |
| el17arm | 40:913339e324b8 | 130 | int _level; |
| el17arm | 29:d85886364643 | 131 | int _lives; |
| el17arm | 40:913339e324b8 | 132 | bool _enem_flag; |
| el17arm | 40:913339e324b8 | 133 | int _five_keys; |
| el17arm | 40:913339e324b8 | 134 | bool _key_reinit; |
| el17arm | 41:0cf320f73424 | 135 | int _oxy_state; |
| el17arm | 41:0cf320f73424 | 136 | int _life_state; |
| el17arm | 41:0cf320f73424 | 137 | float _total_time; |
| el17arm | 41:0cf320f73424 | 138 | float _time; |
| el17arm | 29:d85886364643 | 139 | |
| el17arm | 33:023f57d52b1c | 140 | Sprites _sprites; |
| el17arm | 29:d85886364643 | 141 | Direction _d; |
| el17arm | 42:d81c008b0436 | 142 | Levels _lev; |
| el17arm | 41:0cf320f73424 | 143 | Timer _t; |
| el17arm | 41:0cf320f73424 | 144 | |
| el17arm | 40:913339e324b8 | 145 | |
| el17arm | 29:d85886364643 | 146 | }; |
| el17arm | 29:d85886364643 | 147 | #endif |