Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Player/Player.cpp
- Revision:
- 7:530ca713d2b2
- Parent:
- 5:928c2eee4109
- Child:
- 8:d19b30a6cd69
--- 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);
}