ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lewisgw
Date:
Tue May 07 17:21:00 2019 +0000
Parent:
28:be77ad6c0bda
Commit message:
Final Submission. I have read and agreed with the Statement of Academic Integrity.

Changed in this revision

Coin/Coin.cpp Show annotated file Show diff for this revision Revisions of this file
Engine/Engine.cpp Show annotated file Show diff for this revision Revisions of this file
EngineController/EngineController.cpp Show annotated file Show diff for this revision Revisions of this file
Fire/Fire.cpp Show annotated file Show diff for this revision Revisions of this file
Menu/Menu.cpp Show annotated file Show diff for this revision Revisions of this file
Platforms/Platforms.cpp Show annotated file Show diff for this revision Revisions of this file
Skateboarder/Stakeboarder.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Coin/Coin.cpp	Tue May 07 08:39:38 2019 +0000
+++ b/Coin/Coin.cpp	Tue May 07 17:21:00 2019 +0000
@@ -30,8 +30,8 @@
 }
 
 void Coin::generate_coin() {
-  // Toggle the state of the coin every 3 loop iterations so it looks like it is
-  // rotating.
+  // Toggle the state of the coin every 3 loop iterations. This will be used to  
+  // print different coin sprites so it looks like it is rotating.
   if (_coin_counter == 2) {
     _coin_counter = 0;
     _rotate_coin = !_rotate_coin;
@@ -40,6 +40,7 @@
 }
 
 void Coin::set_coin(int rand_x, int rand_y) {
+  // Set the coin coords based on input values.
   if (rand_y > 40) {  
     _y = 15;  // Set the coin on the top platforms.
   } else {
--- a/Engine/Engine.cpp	Tue May 07 08:39:38 2019 +0000
+++ b/Engine/Engine.cpp	Tue May 07 17:21:00 2019 +0000
@@ -13,6 +13,7 @@
 Engine::~Engine() {}
 
 void Engine::init() {
+  // Reset functions are used for init.
   reset_skater();
   reset_engine();
   srand(time(NULL));  // Set up for generating random numbers, [1].
@@ -30,6 +31,7 @@
 }
 
 void Engine::execute_dying_sequence(N5110 &lcd, Gamepad &gamepad) {
+  // Player has died and game needs to restart, printing their score.
   wait(1);  // Short pause.
   gamepad.leds_off();
   lcd.clear();
@@ -50,6 +52,7 @@
 }
 
 void Engine::reset_skater() {
+  // Initial values for skater.
   _skater_direction = Left;
   _start_platform_flag = true;  // For printing start text in EngineController.
   _skater.set_reset_flag(false);
@@ -59,6 +62,7 @@
 }  
 
 void Engine::reset_engine() {
+  // Inital values for engine (and gamepad input).
   _input.coord.x = 0;
   _input.coord.y = 0;
   _input.A_flag = false;
@@ -72,7 +76,7 @@
 }  
 
 void Engine::read_input(Gamepad &gamepad) {
-  // Set up the input struct.
+  // Set up the input struct for use.
   _input.coord = gamepad.get_mapped_coord(); 
   _input.A_flag = gamepad.check_event(Gamepad::A_PRESSED);
 } 
@@ -81,7 +85,7 @@
   // Sets the y coord by first checking if the skater should be falling.
   set_fall_flag();  // Update the fall flag dependent on skater position.
   if (_fall_flag) {
-    _skater.fall(_fall_flag, gamepad);
+    _skater.fall(_fall_flag, gamepad);  // Fall if the skater should be.
   } else {
     _skater.set_y_position(_input.A_flag, _jump_counter, _level_condition, 
                            gamepad);
@@ -114,7 +118,7 @@
 }
     
 void Engine::process_x(int game_counter) {
-  // Sets the x coord.
+  // Sets the x coord from input.
   _skater.set_x_position_and_sprite(_input.coord.x, 
     _moving_counter, 
     _skater_direction,
@@ -244,6 +248,7 @@
                _upper_line_1.y,FILL_BLACK);
   lcd.drawLine(_upper_line_3.x_start,_upper_line_3.y,_upper_line_3.x_end,
                _upper_line_3.y,FILL_BLACK);
+  // Print the score.
   sprintf(buffer,"%2d",_player_score);
   lcd.printString(buffer,0,0);
   draw_screen_fire(game_counter, lcd);
--- a/EngineController/EngineController.cpp	Tue May 07 08:39:38 2019 +0000
+++ b/EngineController/EngineController.cpp	Tue May 07 17:21:00 2019 +0000
@@ -34,6 +34,7 @@
 EngineController::~EngineController() {}
 
 void EngineController::init() {
+  // Statrting values for the controller.
   _game_engine.init();
   _game_counter = 0;
   _speed_divider = 10;
--- a/Fire/Fire.cpp	Tue May 07 08:39:38 2019 +0000
+++ b/Fire/Fire.cpp	Tue May 07 17:21:00 2019 +0000
@@ -23,11 +23,13 @@
 Fire::~Fire() {}
 
 void Fire::init() {
+  // Starting position of the fire (Y coord is calculated externally).
   _x = -10;  // Start fire off screen.
   _fire_counter = false;
 }
 
 void Fire::generate_fire() {
+  // Sets the X coord so it moves independently.
   _x++;  // Keep fire moving from L to R.
   _fire_counter = !_fire_counter;  // Toggle fire counter to generate different 
   // sprites each iteration.
@@ -36,7 +38,7 @@
 }
 
 int * Fire::get_fire_sprite() {
-  // Return different fire sprites.
+  // Return different fire sprites for dynamic effect.
   if (_fire_counter) {
     return *fire_one;
   } else {
--- a/Menu/Menu.cpp	Tue May 07 08:39:38 2019 +0000
+++ b/Menu/Menu.cpp	Tue May 07 17:21:00 2019 +0000
@@ -91,6 +91,7 @@
 Menu::~Menu() {}
 
 void Menu::init() { 
+  // Starting setup of menu.
   _state = 1;  // Starting state is the menu.  
   _controller.init();
   // Initialise counters for musical tune.
@@ -113,11 +114,11 @@
 void Menu::output(N5110 &lcd, Gamepad &gamepad) {
   // 0, 1 and 2 have been assigned to the output of each state respectively.
   if (_output == 0) {
-    run_game(lcd, gamepad);
+    run_game(lcd, gamepad);  // Runs the main game loop.
   } else if (_output == 1) {
-    display_menu(lcd, gamepad);
+    display_menu(lcd, gamepad);  // Displays the main menu.
   } else {
-    display_controls(lcd, gamepad);
+    display_controls(lcd, gamepad);  // Displayes the control page.
   }
 }
 
@@ -139,6 +140,7 @@
 }
 
 void Menu::display_controls(N5110 &lcd, Gamepad &gamepad) {
+  // Print lines for aesthetics, and print controls text.
   lcd.drawLine(0,0,84,0,FILL_BLACK);
   lcd.drawLine(0,6,84,6,FILL_BLACK);
   lcd.drawLine(0,24,84,24,FILL_BLACK);
@@ -149,10 +151,11 @@
   lcd.printString("Collect Coins!",0,5);
   lcd.printString("A:",0,3);
   lcd.printString("-Jump",0,4);
-  play_tone(gamepad);
+  play_tone(gamepad);  // Play the tune.
 }
 
 void Menu::display_menu(N5110 &lcd, Gamepad &gamepad) {
+  // Print lines and sprite for aesthetics, and print menu text.
   lcd.drawLine(0,0,84,0,FILL_BLACK);
   lcd.drawLine(0,6,84,6,FILL_BLACK);
   lcd.drawLine(0,24,84,24,FILL_BLACK);
@@ -160,7 +163,7 @@
   lcd.printString("START- Play!",0,1);   
   lcd.printString("X- Controls",0,2); 
   lcd.drawSprite(1,25,23,80,(int*)menu_sprite); 
-  play_tone(gamepad);
+  play_tone(gamepad);  // Play the tune.
 }
 
 void Menu::play_tone(Gamepad &gamepad) {
@@ -199,9 +202,10 @@
 } 
 
 void Menu::play_chord_b(Gamepad &gamepad) {
+  // Same as play_chord_a, just different notes. 
   if (_tone_counter < 5) {
     if (_tone_flag) {
-      gamepad.tone(174.61, 0.5);
+      gamepad.tone(174.61, 0.5);  
     } else {
       gamepad.tone(349.23, 0.1);
     }
--- a/Platforms/Platforms.cpp	Tue May 07 08:39:38 2019 +0000
+++ b/Platforms/Platforms.cpp	Tue May 07 17:21:00 2019 +0000
@@ -33,6 +33,7 @@
 }
            
 void Platforms::set_line_2(int length) {
+  // Same as set_line_1.
   _line_2.x_start--;
   if (_line_2.x_start < 80 - length) _line_2.x_end--;
   if (_line_2.x_start <= 0) _line_2.x_start = 0;
@@ -43,6 +44,7 @@
 }
     
 void Platforms::set_line_3(int length) {
+  // Same as set_line_1.
   _line_3.x_start--;
   if (_line_3.x_start < 80 - length) _line_3.x_end--;
   if (_line_3.x_start <= 0) _line_3.x_start = 0;
--- a/Skateboarder/Stakeboarder.cpp	Tue May 07 08:39:38 2019 +0000
+++ b/Skateboarder/Stakeboarder.cpp	Tue May 07 17:21:00 2019 +0000
@@ -130,12 +130,13 @@
     float joy_x, 
     int moving_counter, 
     Skate_direction direction, 
-    float joy_y) {     
+    float joy_y) {
+  // Set up the new x coord and use that to set the sprite.           
   _skate_direction = direction;
   _moving_counter = moving_counter;
   process_x_variables(joy_x);      
   _x = 40 + 0.4*_moving_counter;  // Moving counter is scaled for speed control.
-  check_duck(joy_y); 
+  check_duck(joy_y);  // Needed to overwrite sprite if ducking.
 }
     
 void Skateboarder::process_x_variables(float joy_x) {