ELEC2645 (2018/19) / Mbed 2 deprecated el17arm

Dependencies:   mbed

Committer:
el17arm
Date:
Tue May 07 23:51:54 2019 +0000
Revision:
60:3df033345059
Parent:
58:4a826093d9e9
Child:
61:f17216566c0c
Hopefully final commit

Who changed what in which revision?

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