ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jb

Dependencies:   mbed Gamepad2

Revision:
8:d19b30a6cd69
Parent:
7:530ca713d2b2
Child:
9:9830d3a78572
--- a/Player/Player.cpp	Tue May 26 01:45:20 2020 +0000
+++ b/Player/Player.cpp	Tue May 26 22:15:42 2020 +0000
@@ -42,7 +42,7 @@
 //Update player movement and set screen restrictions
 void Player::update(Direction d, float mag, int Ypos, bool fall, bool jump)
 {
-     _vx = int(mag*4.0f);
+    _vx = int(mag*4.0f);
     //GO RIGHT
     if(d == E) {
         _playerX = _playerX + _vx;
@@ -53,36 +53,40 @@
         _playerX = _playerX - _vx;
         _dir = W;
     }
-    
-    //GRAVITY
-    if( fall == true){
-        _playerY = _playerY + 1;
-        }
-    
-    //FLOOR COLLISION
-    else if ( fall == false){
-        _playerY  = Ypos;
-        int _oldY = _playerY;
-        if (jump == true){
-                _playerY -= 2;
-                
-                if (_oldY - _playerY > 20) {jump = false;}
+
+    switch(jump) {
+        case 0:
+            //FREE FALL
+            if( fall == true) {
+                _playerY = _playerY + 3;
+            }
+
+            //FLOOR COLLISION
+            if ( fall == false) {
+                _playerY  = Ypos;
             }
-        
-        }
-    
-    //SCREEN RESTRICTIONS
+            break;
+
+        case 1:
+            //JUMP UNTIL TWICE PLAYER HEIGHT
+            _playerY -=4;
+
+            break;
+
+    }
+
+//SCREEN RESTRICTIONS
     if (_playerX > WIDTH - 9) {
         _playerX = WIDTH - 9;
     }
     if(_playerX < 0) {
         _playerX = 0;
     }
-    
-    
-    
-    //debug
-    //printf("x: %i, y: %i \n", _playerX, _playerY);
+
+
+
+//debug
+//printf("x: %i, y: %i \n", _playerX, _playerY);
 }
 
 //get the position of the player in a 2D vector
@@ -90,4 +94,5 @@
 {
     Vector2D pos = {_playerX, _playerY};
     return pos;
-}
\ No newline at end of file
+}
+