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
- Committer:
- el17arm
- Date:
- 2019-04-24
- Revision:
- 47:3425159c0211
- Parent:
- 46:de3462ad5aef
- Child:
- 48:bd1f31fbfee3
File content as of revision 47:3425159c0211:
#ifndef GAMEENGINE_H
#define GAMEENGINE_H
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Sprites.h"
#include "Levels.h"
/** Gameengine Class
@brief Builds all levels and sets all default values. Updates all game settings
and contains functions for all game conditions
@author Andrew Milner University of Leeds
@date April 2019
*/
class Gameengine
{
public:
Gameengine();
~Gameengine();
/**
* @brief Initialises all default game settings.
*/
void game_init();
/** updates all game game settings.
*/
void update(N5110 &lcd, Gamepad &pad);
/**
* @brief updates and renders all level objects for level 1.
*/
void draw_l1(N5110 &lcd, Gamepad &pad);
/**
* @brief updates and renders all level objects for level 2.
*/
void draw_l2(N5110 &lcd, Gamepad &pad);
/**
* @brief updates and renders all level objects for level 3.
*/
void draw_l3(N5110 &lcd, Gamepad &pad);
/**
* @brief Reads direction the player is moving.
* @details Uses getdirection() function from Gamepad library.
*/
void read_direction(Gamepad &pad);
/**
* @brief Calculates lives remaining.
* @returns integer calue to control lives fsm state in leds() main.cpp
*/
int oxygen_leds();
/**
* @brief Calculates time remaining.
* @details Calculates time remaining, every 1/3 of total time passed the return
* value changes.
* @return integer value to control oxygen fsm state in leds() main.cpp
*/
int lives_leds();
/**
* @brief Calculates and displays player score.
* @details At game over or game completed the players score is calculated and
* displayed. It takes time remaining and multiplies this by lives remaining, then
* adds on 10 points for every key collected.
*/
void get_score(N5110 &lcd);
/**
* @brief Returns true if game completed.
* @details calculates when _level variable has gone beyond number of levels in game.
* @return true if game complete
*/
bool game_complete(N5110 &lcd);
/**
* @brief Reduces number of lives on player death.
* @details After reducing lives, makes tone to signify player death, resets player
* back to start, creates small pause so gameplay is slightly paused.
*/
void lose_life(Gamepad &pad, N5110 &lcd);
/**
* @brief States whether game over condition met
* @return returns true if game over.
*/
bool game_over();
/**
* @brief Function returns true when player at exit.
* @details Function returns true when the player is in contact with the level exit.
*/
bool level_exit(N5110 &lcd);
/**
* @brief Function returns true when level complete conditions met.
* @details Function returns true when all 5 keys have been collected using _sprites.keys_collected()
* and player is in contact with the level exit using level_exit() function
* The calculates time reamining then resets, resets enemy and key flags
* so they can be initialised for the next level, increases _level by 1 so next
* level can be drawn, keys needed increased by 5 and miner position reset.
*/
void next_level(N5110 &lcd);
/**
* @brief Function returns true if player in contact with trap
* @details Function sets all trap poisitons and collision rules. Usues int i
* to select which level positions to use.
*/
bool trap_death(N5110 &lcd);
/**
* @brief Function returns true if player in contact with trap.
* @details Function sets all trap positons and collision rules stated in
* Sprites class. Uses int i to select which level positions to use, these are
* specified in Level class.
*/
void key_draw(N5110 &lcd,Gamepad &pad);
/**
* @brief Function sets all block positions and collision rules.
* @details Function sets all block positons and collision rules stated in
* Sprites class. Keys are indexed so each one is treated independently
* otherwise all will disappear if one is collected. Uses int i to select which
* level positions to use, these are specified in Level class
*/
void blocks(N5110 &lcd);
bool enemies(N5110 &lcd);
void key_reinit();
private:
int _level;
int _lives;
double _x;
double _y;
int _distance;
int _turn_flag;
int _counter;
bool _enem_flag;
int _five_keys;
bool _key_reinit;
int _oxy_state;
int _life_state;
float _total_time;
float _time_total;
float _time;
Sprites _sprites;
Direction _d;
Levels _lev;
Timer _t;
};
#endif