ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Revision:
14:9861fe85c803
Parent:
12:ebaefda53dd0
Child:
15:876c047a6ec9
--- a/EngineController/EngineController.cpp	Wed Apr 03 13:42:58 2019 +0000
+++ b/EngineController/EngineController.cpp	Thu Apr 04 18:19:26 2019 +0000
@@ -15,32 +15,46 @@
   { 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
 EngineController::EngineController() {}
 
 EngineController::~EngineController() {}
 
 void EngineController::init() {
+  // Initialise the game engine, game counter and starting text flag.
   _game_engine.init();
   _game_counter = 0;
   _start_platform = true;
 }
 
 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);
+  update_game(lcd, gamepad);
+  if(_game_counter == 100) _game_counter = 0;
+  if (_game_counter % 10 == 0) _game_engine.generate_map();  
+  _game_counter++;
+}
+
+void EngineController::check_for_start(N5110 &lcd) {
+  // Print the intro text if the game has just started.
   if(_start_platform) print_intro_text(lcd);
-  if(_game_counter == 100) _game_counter = 0;
   _game_engine.check_reset();
+  _start_platform = _game_engine.get_start_platform();
+}
+
+void EngineController::print_intro_text(N5110 &lcd) {
+  lcd.drawLine(0,17,80,17,FILL_WHITE);
+  lcd.drawSprite(40,4,12,42,(int *)intro_text);    
+}
+
+void EngineController::update_game(N5110 &lcd, Gamepad &gamepad) {
+  // Run the game engine.
   _game_engine.read_input(gamepad);
-  _start_platform = _game_engine.get_start_platform();
-  if (_game_counter % 10 == 0) _game_engine.generate_map();  
   _game_engine.set_level_condition();
   _game_engine.process_y();
   _game_engine.process_x(_game_counter);
   _game_engine.process_sprite();
   _game_engine.update_lcd(lcd);
-  _game_counter++;
 }
-
-void EngineController::print_intro_text(N5110 &lcd) {
-  lcd.drawLine(0,17,80,17,FILL_WHITE);
-  lcd.drawSprite(40,4,12,42,(int *)intro_text);    
-}
\ No newline at end of file