ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jb

Dependencies:   mbed Gamepad2

Revision:
7:530ca713d2b2
Parent:
5:928c2eee4109
Child:
8:d19b30a6cd69
diff -r 00d20886e4f8 -r 530ca713d2b2 Player/Player.cpp
--- a/Player/Player.cpp	Mon May 25 16:17:58 2020 +0000
+++ b/Player/Player.cpp	Tue May 26 01:45:20 2020 +0000
@@ -20,12 +20,6 @@
 
 
 
-//Player jumps if A is pressed
-bool Player::jump(Gamepad &pad)
-{
-    
-}
-
 
 
 //Draw the sprites depending on the orientation
@@ -46,18 +40,38 @@
 }
 
 //Update player movement and set screen restrictions
-void Player::update(Direction d, float mag)
+void Player::update(Direction d, float mag, int Ypos, bool fall, bool jump)
 {
-    int _vx = int(mag*4.0f);
+     _vx = int(mag*4.0f);
+    //GO RIGHT
     if(d == E) {
         _playerX = _playerX + _vx;
         _dir = E;
     }
-
+    //GO LEFT
     if(d == W) {
         _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;}
+            }
+        
+        }
+    
+    //SCREEN RESTRICTIONS
     if (_playerX > WIDTH - 9) {
         _playerX = WIDTH - 9;
     }
@@ -65,6 +79,8 @@
         _playerX = 0;
     }
     
+    
+    
     //debug
     //printf("x: %i, y: %i \n", _playerX, _playerY);
 }