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 Class Reference
Gameengine Class. More...
#include <Gameengine.h>
Public Member Functions | |
| Gameengine () | |
| constructor | |
| ~Gameengine () | |
| deconstructor | |
| void | game_init () |
| Initialises all default game settings. | |
| void | update (N5110 &lcd, Gamepad &pad) |
| Updates all game game settings. | |
| void | draw_l1 (N5110 &lcd, Gamepad &pad) |
| Updates and renders all level objects for level 1. | |
| void | draw_l2 (N5110 &lcd, Gamepad &pad) |
| Updates and renders all level objects for level 2. | |
| void | draw_l3 (N5110 &lcd, Gamepad &pad) |
| Updates and renders all level objects for level 3. | |
| void | draw_l4 (N5110 &lcd, Gamepad &pad) |
| Updates and renders all level objects for level 4. | |
| void | read_direction (Gamepad &pad) |
| Reads direction the player is moving. | |
| int | lives_leds () |
| Calculates lives remaining. | |
| int | oxygen_leds () |
| Calculates time remaining. | |
| void | get_score (N5110 &lcd) |
| Calculates and displays player score. | |
| bool | game_complete (N5110 &lcd) |
| Returns true if game completed. | |
| void | lose_life (Gamepad &pad, N5110 &lcd) |
| Reduces number of lives on player death. | |
| bool | game_over () |
| States whether game over condition met. | |
| bool | level_exit (N5110 &lcd) |
| Returns true when player at exit. | |
| void | next_level (N5110 &lcd, Gamepad &pad) |
| Moves player to next level when level complete conditions met. | |
| bool | trap_death (N5110 &lcd) |
| Returns true if player in contact with trap. | |
| void | key_draw (N5110 &lcd, Gamepad &pad) |
| Draws keys for each level. | |
| void | blocks (N5110 &lcd) |
| Sets all block positions and collision rules. | |
| bool | enemies (N5110 &lcd) |
| Initialises enemies, updates movements and detects collision with player. | |
| void | key_reinit () |
| Reinitialises keys once new level starts. | |
Detailed Description
Gameengine Class.
Builds all levels and sets game default values. Updates all game settings and contains functions for game conditions.
- Date:
- April 2019
Definition at line 18 of file Gameengine.h.
Constructor & Destructor Documentation
| Gameengine | ( | ) |
constructor
Definition at line 3 of file Gameengine.cpp.
| ~Gameengine | ( | ) |
deconstructor
Definition at line 6 of file Gameengine.cpp.
Member Function Documentation
| void blocks | ( | N5110 & | lcd ) |
Sets all block positions and collision rules.
Function sets all block positons and collision rules stated in Sprites class. Blocks 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. Int i is set _level so function knows which level settings to use.
Definition at line 235 of file Gameengine.cpp.
Updates and renders all level objects for level 1.
Definition at line 42 of file Gameengine.cpp.
Updates and renders all level objects for level 2.
Definition at line 58 of file Gameengine.cpp.
Updates and renders all level objects for level 3.
Definition at line 75 of file Gameengine.cpp.
Updates and renders all level objects for level 4.
Definition at line 91 of file Gameengine.cpp.
| bool enemies | ( | N5110 & | lcd ) |
Initialises enemies, updates movements and detects collision with player.
Only initialises enemies when enem_flag set to false and sets it true once done. Function also updates enemy position and detects collision with players, int i states which level settings to use.
- Returns:
- true if player collides with enemy.
Definition at line 253 of file Gameengine.cpp.
| bool game_complete | ( | N5110 & | lcd ) |
Returns true if game completed.
calculates when _level variable has gone beyond number of levels in game.
- Returns:
- true if game complete
Definition at line 152 of file Gameengine.cpp.
| void game_init | ( | ) |
Initialises all default game settings.
Sets player starting position, number of lives, level start and timer.
Definition at line 10 of file Gameengine.cpp.
| bool game_over | ( | ) |
States whether game over condition met.
- Returns:
- returns true if game over.
Definition at line 171 of file Gameengine.cpp.
| void get_score | ( | N5110 & | lcd ) |
Calculates and displays player score.
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.
Definition at line 140 of file Gameengine.cpp.
Draws keys for each level.
Function sets key positions and collision rules stated in Sprites class. Uses int i to select which level positions to use, these are specified in Level class.
Definition at line 223 of file Gameengine.cpp.
| void key_reinit | ( | ) |
Reinitialises keys once new level starts.
Once level is complete the _key_reint flag is set to false and all 5 level keys are set to false. This means they are drawn in new positions as per int i which states which level settings to use in key_draw().
Definition at line 276 of file Gameengine.cpp.
| bool level_exit | ( | N5110 & | lcd ) |
Returns true when player at exit.
- Returns:
- Function returns true when the player is in contact with the level exit.
Definition at line 183 of file Gameengine.cpp.
| int lives_leds | ( | ) |
Calculates lives remaining.
- Returns:
- integer value to control lives fsm state in leds() main.cpp
Definition at line 133 of file Gameengine.cpp.
Reduces number of lives on player death.
After reducing lives, makes tone to signify player death, resets player back to start, creates small pause.
Definition at line 160 of file Gameengine.cpp.
Moves player to next level when level complete conditions met.
When all 5 keys have been collected using _sprites.keys_collected() and player is in contact with the level exit using level_exit() function. Calculates time reamining (for score) then resets, resets enemy and key flags so they can be initialised for the next level, increases _level by 1 so next level will be drawn, keys needed increased by 5 and miner position reset.
Definition at line 193 of file Gameengine.cpp.
| int oxygen_leds | ( | ) |
Calculates time remaining.
Calculates time remaining, every 1/3 of total time passed the return value changes.
- Returns:
- integer value to control oxygen fsm state in leds() main.cpp
Definition at line 115 of file Gameengine.cpp.
| void read_direction | ( | Gamepad & | pad ) |
Reads direction the player is moving.
Uses get_direction() function from Gamepad library.
Definition at line 109 of file Gameengine.cpp.
| bool trap_death | ( | N5110 & | lcd ) |
Returns true if player in contact with trap.
Function sets all trap poisitons and collision rules. Usues int i to select which level positions to use.
Definition at line 209 of file Gameengine.cpp.
Updates all game game settings.
Contains all functions that update player position and game conditions such as lives left, timer, game over and level complete.
Definition at line 23 of file Gameengine.cpp.
Generated on Wed Jul 13 2022 01:25:32 by
1.7.2