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.
Diff: Game/Game.cpp
- Revision:
- 10:58cf89dd878c
- Parent:
- 9:96969b1c6bde
- Child:
- 11:db27d3838514
--- a/Game/Game.cpp Wed Apr 24 10:18:45 2019 +0000 +++ b/Game/Game.cpp Mon May 06 10:11:42 2019 +0000 @@ -1,16 +1,31 @@ #include "Game.h" -// Objects +/** Game Class + +@brief Class for the main game. Responsible for level loading, updating and +drawing the game screen. + +@version 1.0 + + +// constructor Game::Game() { +} +//deconstructor +Game::~Game() +{ + +} -} - void Game::load_level(int level_number) { + // I would of done this large switch statement with a an array + // of LevelDefiniton as it would be a lot neater. However this causes + // issue with the infamous "empty execution error" bug LevelDefinition level_def; switch(level_number) { case 1 : @@ -35,13 +50,19 @@ level_def = level_7; break; case 8: + level_def = level_8; + break; + case 9: + // Then the game is complete _game_won = true; return; } - _player.init(6,6,level_def.initial_pos); + // Initialises the player position + _player.init(level_def.initial_pos); + // Initalises level _level.init(level_def.blocks, level_def.number_of_blocks, level_def.goal); @@ -56,38 +77,41 @@ void Game::init() { - + // Loads the first level load_level(1); _current_level = 1; + _game_won = false; } -Game::~Game() -{ - -} - void Game::update(Gamepad &pad) { + // Update player position based on gamepad presses/ collisions _player.update(pad, _level.get_blocks(),_level.get_number_of_blocks()); + // Update location of any moving blocks _level.update_moving_blocks(); + + // If the player has reached the goal if (_player.check_goal_reached(_level.get_goal())) { + // Load next level _current_level += 1; load_level(_current_level); } - - } void Game::draw(N5110 &lcd) { - + // Clear screen buffer lcd.clear(); + + // Render Level And Player _level.render(lcd); _player.render(lcd); + + // refresh screen lcd.refresh(); }