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