ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Revision:
8:5327418f823a
Parent:
7:bbc2b75c1418
Child:
9:fff2009f826e
--- a/Engine/Engine.cpp	Wed Mar 20 17:56:55 2019 +0000
+++ b/Engine/Engine.cpp	Sat Mar 23 15:36:56 2019 +0000
@@ -4,6 +4,20 @@
 
 Engine::~Engine(){}
 
+void Engine::check_reset() {
+    if(_skater.get_reset_flag()) {
+    _moving_counter = 0;
+    _jump_counter = 0;
+    _direction = Left;
+    _level = 0;
+    _x = 40;
+    _y = 40;
+    _map.init();
+    _skater.set_reset_flag(false);
+    wait(1);
+    }
+    }
+
 void Engine::init() {
     _moving_counter = 0;
     _jump_counter = 0;
@@ -22,12 +36,29 @@
     } 
 
 void Engine::process_y() {
+    if ( ( (_line_1.x_end < _x) && (_x < (_line_2.x_start - 6) ) )  && _y == 23 ) {
+    _fall_flag = true; 
+    } else if ( ( (_line_2.x_end < _x) && (_x < (_line_3.x_start - 6) ) ) && _y == 23 ) {
+    _fall_flag = true;
+    } else if ( ( (_line_3.x_end < _x) && (_x < (_line_1.x_start - 6) ) ) && _y == 23 ) {
+    _fall_flag = true;
+    } 
+    
+    if(_fall_flag) {
+    _skater.fall(_fall_flag);
+    } else {
     _skater.set_y_position( _input.A_flag, _jump_counter, _level );
+    }
+    
+    _fall_flag = _skater.get_fall_flag();
     _y = _skater.get_y_position();
     _jump_counter = _skater.get_jump_counter();
     }
     
 void Engine::process_x(int t) {
+    if ( _x < -10 || _x > 84 ) {
+    _skater.set_reset_flag(true);
+    } else {
     _skater.set_x_position( _input.coord.x, _moving_counter, _direction, _input.coord.y );
     _x = _skater.get_x_position();
     _moving_counter = _skater.get_moving_counter();
@@ -36,6 +67,7 @@
     _moving_counter--;
     }
     }
+    }
     
 void Engine::process_sprite() {
     _sprite = _skater.get_sprite_value();