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:
- 23:ff9073e12106
- Parent:
- 21:20478f086bc2
- Child:
- 26:4253656c0755
diff -r 20478f086bc2 -r ff9073e12106 Engine/Engine.cpp --- a/Engine/Engine.cpp Sat Apr 20 14:46:50 2019 +0000 +++ b/Engine/Engine.cpp Mon Apr 22 16:33:29 2019 +0000 @@ -1,5 +1,8 @@ #include "Engine.h" +// Reference for the technique used to generate random numbers. +// [1] "rand" cplusplus. [Online] Available: http://www.cplusplus.com/reference/cstdlib/rand/ [Accessed: 22 April 2019]. + // Buffer to print updated score. char buffer[14]; @@ -11,7 +14,7 @@ void Engine::init() { reset_skater(); reset_engine(); - srand(time(NULL)); // Set up for generating random numbers + srand(time(NULL)); // Set up for generating random numbers, [1]. } void Engine::check_reset(N5110 &lcd, Gamepad &gamepad) { @@ -29,7 +32,7 @@ lcd.clear(); for (int i = 0; i < 40; i = i + 8) { // Counter for y direction, sweeps top // to bottom. - for (int j = 0; j < 84; j++) { // Counter for x direction, sweeps L to R + for (int j = 0; j < 84; j++) { // Counter for x direction, sweeps L to R. lcd.setPixel(j,i,true); lcd.setPixel(i,j,true); lcd.printString("TRY AGAIN",30,5); @@ -45,7 +48,7 @@ void Engine::reset_skater() { _skater_direction = Left; - _start_platform_flag = true; // For printing start text in EngineController + _start_platform_flag = true; // For printing start text in EngineController. _skater.set_reset_flag(false); _moving_counter = 0; _jump_counter = 20; @@ -149,13 +152,13 @@ void Engine::generate_lower_lines() { // Use a scaled random number to generate the length of the lower lines. - _length_1 = (rand() %20) + 10; + _length_1 = (rand() %20) + 10; // [1]. _lower_platforms.set_line_1(_length_1); _lower_line_1 = _lower_platforms.get_line_1(); - _length_2 = (rand() %20) + 10; + _length_2 = (rand() %20) + 10; // [1]. _lower_platforms.set_line_2(_length_2); _lower_line_2 = _lower_platforms.get_line_2(); - _length_3 = (rand() %20) + 10; + _length_3 = (rand() %20) + 10; // [1]. _lower_platforms.set_line_3(_length_3); _lower_line_3 = _lower_platforms.get_line_3(); } @@ -213,7 +216,7 @@ _coin_collision_flag = true; _player_score++; _coin.set_coin((rand() % 100),(abs(rand() % 100 - 20))); // Place coin - // on a constrained random position + // on a constrained random position, [1]. gamepad.tone(1500, 0.05); // Make noise on buzzer. wait(0.05); gamepad.tone(3000, 0.05);