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@47:3425159c0211, 2019-04-24 (annotated)
- Committer:
- el17arm
- Date:
- Wed Apr 24 14:27:00 2019 +0000
- Revision:
- 47:3425159c0211
- Parent:
- 46:de3462ad5aef
- Child:
- 48:bd1f31fbfee3
test publish
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 | 29:d85886364643 | 23 | |
| el17arm | 29:d85886364643 | 24 | Gameengine(); |
| el17arm | 29:d85886364643 | 25 | ~Gameengine(); |
| el17arm | 46:de3462ad5aef | 26 | /** |
| el17arm | 46:de3462ad5aef | 27 | * @brief Initialises all default game settings. |
| el17arm | 46:de3462ad5aef | 28 | */ |
| el17arm | 46:de3462ad5aef | 29 | void game_init(); |
| el17arm | 47:3425159c0211 | 30 | /** updates all game game settings. |
| el17arm | 46:de3462ad5aef | 31 | */ |
| el17arm | 46:de3462ad5aef | 32 | void update(N5110 &lcd, Gamepad &pad); |
| el17arm | 46:de3462ad5aef | 33 | /** |
| el17arm | 46:de3462ad5aef | 34 | * @brief updates and renders all level objects for level 1. |
| el17arm | 46:de3462ad5aef | 35 | */ |
| el17arm | 46:de3462ad5aef | 36 | void draw_l1(N5110 &lcd, Gamepad &pad); |
| el17arm | 46:de3462ad5aef | 37 | /** |
| el17arm | 46:de3462ad5aef | 38 | * @brief updates and renders all level objects for level 2. |
| el17arm | 46:de3462ad5aef | 39 | */ |
| el17arm | 46:de3462ad5aef | 40 | void draw_l2(N5110 &lcd, Gamepad &pad); |
| el17arm | 46:de3462ad5aef | 41 | /** |
| el17arm | 46:de3462ad5aef | 42 | * @brief updates and renders all level objects for level 3. |
| el17arm | 46:de3462ad5aef | 43 | */ |
| el17arm | 46:de3462ad5aef | 44 | |
| el17arm | 46:de3462ad5aef | 45 | void draw_l3(N5110 &lcd, Gamepad &pad); |
| el17arm | 46:de3462ad5aef | 46 | /** |
| el17arm | 46:de3462ad5aef | 47 | * @brief Reads direction the player is moving. |
| el17arm | 46:de3462ad5aef | 48 | * @details Uses getdirection() function from Gamepad library. |
| el17arm | 45:bad704c546d4 | 49 | */ |
| el17arm | 29:d85886364643 | 50 | void read_direction(Gamepad &pad); |
| el17arm | 46:de3462ad5aef | 51 | /** |
| el17arm | 46:de3462ad5aef | 52 | * @brief Calculates lives remaining. |
| el17arm | 46:de3462ad5aef | 53 | * @returns integer calue to control lives fsm state in leds() main.cpp |
| el17arm | 46:de3462ad5aef | 54 | */ |
| el17arm | 46:de3462ad5aef | 55 | int oxygen_leds(); |
| el17arm | 46:de3462ad5aef | 56 | /** |
| el17arm | 46:de3462ad5aef | 57 | * @brief Calculates time remaining. |
| el17arm | 46:de3462ad5aef | 58 | * @details Calculates time remaining, every 1/3 of total time passed the return |
| el17arm | 46:de3462ad5aef | 59 | * value changes. |
| el17arm | 46:de3462ad5aef | 60 | * @return integer value to control oxygen fsm state in leds() main.cpp |
| el17arm | 46:de3462ad5aef | 61 | */ |
| el17arm | 46:de3462ad5aef | 62 | int lives_leds(); |
| el17arm | 46:de3462ad5aef | 63 | /** |
| el17arm | 46:de3462ad5aef | 64 | * @brief Calculates and displays player score. |
| el17arm | 46:de3462ad5aef | 65 | * @details At game over or game completed the players score is calculated and |
| el17arm | 46:de3462ad5aef | 66 | * displayed. It takes time remaining and multiplies this by lives remaining, then |
| el17arm | 46:de3462ad5aef | 67 | * adds on 10 points for every key collected. |
| el17arm | 46:de3462ad5aef | 68 | */ |
| el17arm | 46:de3462ad5aef | 69 | void get_score(N5110 &lcd); |
| el17arm | 46:de3462ad5aef | 70 | /** |
| el17arm | 46:de3462ad5aef | 71 | * @brief Returns true if game completed. |
| el17arm | 46:de3462ad5aef | 72 | * @details calculates when _level variable has gone beyond number of levels in game. |
| el17arm | 46:de3462ad5aef | 73 | * @return true if game complete |
| el17arm | 46:de3462ad5aef | 74 | */ |
| el17arm | 46:de3462ad5aef | 75 | bool game_complete(N5110 &lcd); |
| el17arm | 46:de3462ad5aef | 76 | |
| el17arm | 46:de3462ad5aef | 77 | /** |
| el17arm | 46:de3462ad5aef | 78 | * @brief Reduces number of lives on player death. |
| el17arm | 46:de3462ad5aef | 79 | * @details After reducing lives, makes tone to signify player death, resets player |
| el17arm | 46:de3462ad5aef | 80 | * back to start, creates small pause so gameplay is slightly paused. |
| el17arm | 46:de3462ad5aef | 81 | */ |
| el17arm | 41:0cf320f73424 | 82 | void lose_life(Gamepad &pad, N5110 &lcd); |
| el17arm | 46:de3462ad5aef | 83 | /** |
| el17arm | 46:de3462ad5aef | 84 | * @brief States whether game over condition met |
| el17arm | 46:de3462ad5aef | 85 | * @return returns true if game over. |
| el17arm | 46:de3462ad5aef | 86 | */ |
| el17arm | 29:d85886364643 | 87 | bool game_over(); |
| el17arm | 46:de3462ad5aef | 88 | /** |
| el17arm | 46:de3462ad5aef | 89 | * @brief Function returns true when player at exit. |
| el17arm | 46:de3462ad5aef | 90 | * @details Function returns true when the player is in contact with the level exit. |
| el17arm | 46:de3462ad5aef | 91 | */ |
| el17arm | 46:de3462ad5aef | 92 | bool level_exit(N5110 &lcd); |
| el17arm | 46:de3462ad5aef | 93 | /** |
| el17arm | 46:de3462ad5aef | 94 | * @brief Function returns true when level complete conditions met. |
| el17arm | 46:de3462ad5aef | 95 | * @details Function returns true when all 5 keys have been collected using _sprites.keys_collected() |
| el17arm | 46:de3462ad5aef | 96 | * and player is in contact with the level exit using level_exit() function |
| el17arm | 46:de3462ad5aef | 97 | * The calculates time reamining then resets, resets enemy and key flags |
| el17arm | 46:de3462ad5aef | 98 | * so they can be initialised for the next level, increases _level by 1 so next |
| el17arm | 46:de3462ad5aef | 99 | * level can be drawn, keys needed increased by 5 and miner position reset. |
| el17arm | 46:de3462ad5aef | 100 | */ |
| el17arm | 33:023f57d52b1c | 101 | void next_level(N5110 &lcd); |
| el17arm | 46:de3462ad5aef | 102 | /** |
| el17arm | 46:de3462ad5aef | 103 | * @brief Function returns true if player in contact with trap |
| el17arm | 46:de3462ad5aef | 104 | * @details Function sets all trap poisitons and collision rules. Usues int i |
| el17arm | 46:de3462ad5aef | 105 | * to select which level positions to use. |
| el17arm | 46:de3462ad5aef | 106 | */ |
| el17arm | 34:c5a042973e0c | 107 | bool trap_death(N5110 &lcd); |
| el17arm | 46:de3462ad5aef | 108 | /** |
| el17arm | 46:de3462ad5aef | 109 | * @brief Function returns true if player in contact with trap. |
| el17arm | 46:de3462ad5aef | 110 | * @details Function sets all trap positons and collision rules stated in |
| el17arm | 46:de3462ad5aef | 111 | * Sprites class. Uses int i to select which level positions to use, these are |
| el17arm | 46:de3462ad5aef | 112 | * specified in Level class. |
| el17arm | 46:de3462ad5aef | 113 | */ |
| el17arm | 37:4d525a37d5d2 | 114 | void key_draw(N5110 &lcd,Gamepad &pad); |
| el17arm | 46:de3462ad5aef | 115 | /** |
| el17arm | 46:de3462ad5aef | 116 | * @brief Function sets all block positions and collision rules. |
| el17arm | 46:de3462ad5aef | 117 | * @details Function sets all block positons and collision rules stated in |
| el17arm | 46:de3462ad5aef | 118 | * Sprites class. Keys are indexed so each one is treated independently |
| el17arm | 46:de3462ad5aef | 119 | * otherwise all will disappear if one is collected. Uses int i to select which |
| el17arm | 46:de3462ad5aef | 120 | * level positions to use, these are specified in Level class |
| el17arm | 46:de3462ad5aef | 121 | */ |
| el17arm | 38:55bb9da08a52 | 122 | void blocks(N5110 &lcd); |
| el17arm | 38:55bb9da08a52 | 123 | bool enemies(N5110 &lcd); |
| el17arm | 40:913339e324b8 | 124 | void key_reinit(); |
| el17arm | 29:d85886364643 | 125 | |
| el17arm | 29:d85886364643 | 126 | private: |
| el17arm | 29:d85886364643 | 127 | |
| el17arm | 40:913339e324b8 | 128 | int _level; |
| el17arm | 29:d85886364643 | 129 | int _lives; |
| el17arm | 29:d85886364643 | 130 | double _x; |
| el17arm | 29:d85886364643 | 131 | double _y; |
| el17arm | 29:d85886364643 | 132 | int _distance; |
| el17arm | 29:d85886364643 | 133 | int _turn_flag; |
| el17arm | 29:d85886364643 | 134 | int _counter; |
| el17arm | 40:913339e324b8 | 135 | bool _enem_flag; |
| el17arm | 40:913339e324b8 | 136 | int _five_keys; |
| el17arm | 40:913339e324b8 | 137 | bool _key_reinit; |
| el17arm | 41:0cf320f73424 | 138 | int _oxy_state; |
| el17arm | 41:0cf320f73424 | 139 | int _life_state; |
| el17arm | 41:0cf320f73424 | 140 | float _total_time; |
| el17arm | 41:0cf320f73424 | 141 | |
| el17arm | 41:0cf320f73424 | 142 | |
| el17arm | 41:0cf320f73424 | 143 | float _time_total; |
| el17arm | 41:0cf320f73424 | 144 | |
| el17arm | 41:0cf320f73424 | 145 | float _time; |
| el17arm | 29:d85886364643 | 146 | |
| el17arm | 33:023f57d52b1c | 147 | Sprites _sprites; |
| el17arm | 29:d85886364643 | 148 | Direction _d; |
| el17arm | 42:d81c008b0436 | 149 | Levels _lev; |
| el17arm | 41:0cf320f73424 | 150 | Timer _t; |
| el17arm | 41:0cf320f73424 | 151 | |
| el17arm | 40:913339e324b8 | 152 | |
| el17arm | 29:d85886364643 | 153 | }; |
| el17arm | 29:d85886364643 | 154 | #endif |