ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Revision:
21:20478f086bc2
Parent:
20:a8cad4e044ea
Child:
26:4253656c0755
--- a/EngineController/EngineController.cpp	Tue Apr 16 19:19:43 2019 +0000
+++ b/EngineController/EngineController.cpp	Sat Apr 20 14:46:50 2019 +0000
@@ -1,51 +1,68 @@
 #include "EngineController.h"
 
 int intro_text[12][42] =   { 
-  { 1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
-  { 1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
-  { 1,1,0,0,0,0,0,1,1,0,0,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1 },
-  { 1,1,0,0,0,0,0,1,1,0,1,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,0,0,1,1 },
-  { 1,1,0,0,0,0,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,1,1,1,1,1 },
-  { 1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
-  { 1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0 },
-  { 0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,1,1,0,0,0 },
-  { 0,0,0,0,0,1,1,1,1,0,1,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,1,1,0,0 },
-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,0,1,1,1,1,0,1,1,1,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,
+  1,1,0,0 },
+  { 0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,1,0,
+  1,1,0,0 },
+  { 1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,
+  1,1,1,0 },
+  { 1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0,
+  1,1,1,1 }
 };
 
-// Constructor and destructor
+// Constructor and destructor.
 EngineController::EngineController() {}
 
 EngineController::~EngineController() {}
 
 void EngineController::init() {
-  // Initialise the game engine, game counter and starting text flag.
   _game_engine.init();
   _game_counter = 0;
   _speed_divider = 10;
-  _start_platform = true;
+  _start_platform_flag = true;
   _change_speed_flag = false;
 }
 
 void EngineController::run_game_engine(N5110 &lcd, Gamepad &gamepad) {
-  // The main game loop that first checks if the game has just started and runs
-  // the game.
-  check_for_start(lcd, gamepad);
-  if(_game_counter == 100) _game_counter = 0;
+  // The main game loop.
+  check_for_start(lcd, gamepad);  // Check to see if it should print starting 
+  // text.
+  if (_game_counter == 100) _game_counter = 0;
   update_game(lcd, gamepad);
-  if (_game_counter % _speed_divider == 0) _game_engine.generate_level(_game_counter);  
+  if (_game_counter % _speed_divider == 0) 
+  _game_engine.generate_level(_game_counter);  // Level speed is determined by 
+  // speed divider.
   _game_counter++;
   _player_score = _game_engine.get_player_score();
-  _speed_divider = int(-0.25*_player_score + 10);
+  _speed_divider = int(-0.25*_player_score + 10);  // Speed divider is dependent 
+  // on how many coins you have
 }
 
 void EngineController::check_for_start(N5110 &lcd, Gamepad &gamepad) {
-  // Print the intro text if the game has just started.
-  if(_start_platform) print_intro_text(lcd);
-  _game_engine.check_reset(lcd, gamepad);
-  _start_platform = _game_engine.get_start_platform();
+  // Print the intro text if the game has just started or jump has not been 
+  // pressed.
+  if (_start_platform_flag) print_intro_text(lcd);
+  _game_engine.check_reset(lcd, gamepad);  // Resets the game if skater has 
+  // died.
+  _start_platform_flag = _game_engine.get_start_platform_flag();  // Returns 
+  // false when jump is pressed.
 }
 
 void EngineController::print_intro_text(N5110 &lcd) {
@@ -56,7 +73,8 @@
 void EngineController::update_game(N5110 &lcd, Gamepad &gamepad) {
   // Run the game engine.
   _game_engine.read_input(gamepad);
-  _game_engine.set_level_condition();
+  _game_engine.set_level_condition();  // Determines if the skater is under 
+  // upper platforms.
   _game_engine.process_y(gamepad);
   _game_engine.process_x(_game_counter);
   _game_engine.process_sprite();
@@ -64,3 +82,4 @@
   _game_engine.check_fire_collision(gamepad);
   _game_engine.update_lcd(lcd);
 }
+