ELEC2645 (2018/19) / Mbed 2 deprecated el17lw

Dependencies:   mbed

Revision:
20:a8cad4e044ea
Parent:
19:f35887b14c23
Child:
21:20478f086bc2
diff -r f35887b14c23 -r a8cad4e044ea Engine/Engine.cpp
--- a/Engine/Engine.cpp	Mon Apr 15 18:49:35 2019 +0000
+++ b/Engine/Engine.cpp	Tue Apr 16 19:19:43 2019 +0000
@@ -14,12 +14,10 @@
   srand(time(NULL));
 }
 
-void Engine::check_reset(N5110 &lcd) {
+void Engine::check_reset(N5110 &lcd, Gamepad &gamepad) {
   // Reset the game if the skater has fallen (i.e. reset flag = TRUE).
   // 40 and 22 refer to the inital lengths of lower and upper platfroms respectivly.
   if (_skater.get_reset_flag()) {
-    reset_skater();
-    reset_engine();
     wait(1);
     lcd.clear();
     for (int i = 0; i < 40; i = i + 8) {
@@ -28,10 +26,15 @@
         lcd.setPixel(i,j,true);
         lcd.printString("TRY AGAIN",30,5);  
         lcd.refresh();
+        gamepad.tone(int(1099 - 15.4*j - 1.2*i), 0.05);
         wait(0.001);
+        sprintf(buffer,"%2d",_player_score);
+        lcd.printString(buffer,0,5);
       }  
     }
     wait(1);
+    reset_skater();
+    reset_engine();
   }
 }
 
@@ -61,14 +64,14 @@
   _input.A_flag = gamepad.check_event(Gamepad::A_PRESSED);
 } 
 
-void Engine::process_y() {
+void Engine::process_y(Gamepad &gamepad) {
   // Sets the y coordinate by checking if the skater should be falling, and
   // updating the fall flag and jump counter.
   set_fall_flag();
   if (_fall_flag) {
-    _skater.fall(_fall_flag);
+    _skater.fall(_fall_flag, gamepad);
   } else {
-    _skater.set_y_position( _input.A_flag, _jump_counter, _level_condition );
+    _skater.set_y_position( _input.A_flag, _jump_counter, _level_condition, gamepad);
   }
   _fall_flag = _skater.get_fall_flag();
   _skater_y = _skater.get_y_position();
@@ -185,23 +188,30 @@
   return _start_platform;
 }
 
-void Engine::check_coin_collision() {
+void Engine::check_coin_collision(Gamepad &gamepad) {
   // If the skater coords match the coins, add 1 to the players score and print
   // a new coin in a random position
   if (_skater_x == _coin.get_coin_x() && (_skater_y == _coin.get_coin_y() - 10)) {
     _coin_collision_flag = true;
     _player_score++;
-    _coin.update_coin((rand() % 100),(abs(rand() % 100 - 20)));   
+    _coin.update_coin((rand() % 100),(abs(rand() % 100 - 20)));
+    gamepad.tone(1500, 0.05);
+    wait(0.05);
+    gamepad.tone(3000, 0.05);   
   }
 }
 
-void Engine::check_fire_collision() {
+void Engine::check_fire_collision(Gamepad &gamepad) {
   // If the skaters coord match the fire and he is not ducking, the player has died
   // and the game is reset. Game will also reset if skater goes off the screen.
   if (_input.coord.y > -0.1 && _skater_x == _fire.get_fire_x() && _skater_y > _fire_y - 10 && _skater_y < _fire_y + 10) {
     _skater.set_reset_flag(true);
+    gamepad.tone(400, 0.25);
+    wait(0.05);
+    gamepad.tone(200, 0.25);
   } else if ( _skater_x < -10 || _skater_x > 84 ) {
     _skater.set_reset_flag(true);
+    gamepad.tone(200, 0.5);
   }
 }