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:68e06dda79f7
- Parent:
- 4:afbf3dd71403
- Child:
- 8:21b6d4dbce44
--- a/Player/Player.cpp Wed Apr 10 11:03:07 2019 +0000
+++ b/Player/Player.cpp Wed Apr 17 12:39:46 2019 +0000
@@ -4,7 +4,7 @@
Player::Player()
{
-
+ _orientation = 1;
}
Player::~Player()
@@ -12,13 +12,39 @@
}
-void Player::update(Gamepad &pad)
+void Player::update(Gamepad &pad, Block blocks [],int number_of_blocks)
{
-
+// if orientation = 1 then
+// for block
+// if in x range of the block
+// if y - height is equal to block y
+// then dont move down
+// else move down
+
- //if (_pos.y < 30) {
- // _pos.y -= GRAVITY;
- // }
+ if (pad.check_event(Gamepad::L_PRESSED)) {
+ _pos.x -= 2;
+ }
+ if (pad.check_event(Gamepad::R_PRESSED)) {
+ _pos.x += 2;
+ }
+ if (pad.check_event(Gamepad::A_PRESSED)) {
+ flip();
+ }
+ bool can_move_down = false;
+ for (int i = 0; i < number_of_blocks;i++) {
+ if (_pos.x + _width > blocks[i].first.x &&
+ _pos.x - _width < blocks[i].second.x) {
+
+ if ( (_pos.y + _height) == blocks[i].first.y ) {
+ can_move_down = false;
+ }
+ }
+ }
+
+ if (can_move_down) {
+ _pos.y += GRAVITY;
+ }