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
Diff: Engine/Engine.cpp
- Revision:
- 14:9861fe85c803
- Parent:
- 11:b66170249a26
- Child:
- 15:876c047a6ec9
diff -r bcf6bb69c597 -r 9861fe85c803 Engine/Engine.cpp --- a/Engine/Engine.cpp Wed Apr 03 13:42:58 2019 +0000 +++ b/Engine/Engine.cpp Thu Apr 04 18:19:26 2019 +0000 @@ -1,10 +1,13 @@ #include "Engine.h" +// Constructor and destructor Engine::Engine() {} Engine::~Engine() {} void Engine::check_reset() { + // Reset the game if the skater has fallen (i.e. reset flag = TRUE). + // 40 and 22 refer to the inital lengths of lower and upper platfroms respectivly. if (_skater.get_reset_flag()) { reset_skater(); _lower_map.init(40); @@ -25,6 +28,7 @@ } void Engine::init() { + // Initialisation of the game. 40 and 22 refer to inital line lengths. reset_skater(); _lower_map.init(40); _upper_map.init(22); @@ -38,6 +42,8 @@ } void Engine::process_y() { + // Sets the y coordinate by checking if the skater should be falling, and + // updating the fall flag and jump counter. set_fall_flag(); if (_fall_flag) { _skater.fall(_fall_flag); @@ -48,8 +54,9 @@ _y = _skater.get_y_position(); _jump_counter = _skater.get_jump_counter(); } - + void Engine::set_fall_flag() { + // Set the fall flag to true if the skater is not on one of the platforms. if (((_lower_line_1.x_end < _x) && (_x < (_lower_line_2.x_start - 6))) && _y == 23) { _fall_flag = true; } else if (((_lower_line_2.x_end < _x) && (_x < (_lower_line_3.x_start - 6))) && _y == 23) { @@ -60,6 +67,9 @@ } void Engine::process_x(int t) { + // Reset the game if the skater goes off the screen, and update x coordinate. + // Will move the skater to the left along with the platforms (if he is not moving + // left already). if ( _x < -10 || _x > 84 ) { _skater.set_reset_flag(true); } else { @@ -76,12 +86,15 @@ } void Engine::process_sprite() { + // Update the sprite and direction. _sprite = _skater.get_sprite_value(); _direction = _skater.get_direction(); } void Engine::set_level_condition() { + // If the skater is under or on top of any of the upper platforms, set + // level condition to 1. if (((_upper_line_1.x_start - 6) <= _x) && (_x <= _upper_line_1.x_end)) { _level_condition = 1; } else if (((_upper_line_2.x_start - 6) <= _x) && (_x <= _upper_line_2.x_end)) { @@ -99,6 +112,7 @@ } void Engine::generate_lower_lines() { + // Use a scaled random number to generate the length of the lower lines. _length_1 = (rand() %20) + 10; _lower_map.generate_line_1(_length_1); _lower_line_1 = _lower_map.get_line_1(); @@ -111,6 +125,8 @@ } void Engine::generate_upper_lines() { + // Set the length of the lower lines to be proportionally smaller to + // the length of the upper lines. _upper_map.generate_line_1(_length_1 / 2); _upper_line_1 = _upper_map.get_line_1(); _upper_map.generate_line_2(_length_2 / 2); @@ -131,6 +147,8 @@ } bool Engine::get_start_platform() { + // Set start platform flag to be false if the button A is pressed + // (so the starting text goes away after the first jump). if(_input.A_flag) _start_platform = false; return _start_platform; } \ No newline at end of file