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:
- 9:96969b1c6bde
- Parent:
- 8:21b6d4dbce44
- Child:
- 10:58cf89dd878c
--- a/Player/Player.cpp Fri Apr 19 17:54:09 2019 +0000
+++ b/Player/Player.cpp Wed Apr 24 10:18:45 2019 +0000
@@ -17,11 +17,31 @@
_height = height;
_width = width;
_pos = pos;
+ _initial_pos = pos;
_bitmap = (int *) player_bitmap_left; // Default
_orientation = 1;
_direction = -1;
}
+void Player::check_out_of_range()
+{
+ if (_pos.x < -5 || _pos.x > 89 || _pos.y < -5 || _pos.y > 53) {
+ _pos = _initial_pos;
+ _orientation = 1;
+ }
+}
+
+bool Player::check_goal_reached(Vector2D goal)
+{
+ bool goal_reached = false;
+ int x_distance = abs(goal.x - _pos.x);
+ int y_distance = abs(goal.y - _pos.y);
+
+ if (x_distance < 2 && y_distance < 6) {
+ goal_reached = true;
+ }
+ return goal_reached;
+}
bool Player::can_move_down(Block blocks [],int number_of_blocks)
{
@@ -99,11 +119,13 @@
if (_direction == 1 && _orientation == -1) {
_bitmap = (int *) player_bitmap_right_flipped;
}
+
+ check_out_of_range();
if (pad.check_event(Gamepad::A_PRESSED) &&
- (!can_move_down(blocks,number_of_blocks) || !can_move_up(blocks,number_of_blocks))
- ) {
+ (!can_move_down(blocks,number_of_blocks) || !can_move_up(blocks,number_of_blocks))
+ ) {
if (_orientation == 1) {
_orientation = -1;
@@ -113,14 +135,14 @@
}
if (_orientation == 1 && can_move_down( blocks,
- number_of_blocks)) {
- _pos.y += GRAVITY;
+ number_of_blocks)) {
+ _pos.y += GRAVITY;
}
- if (_orientation == -1 && can_move_up(blocks,
- number_of_blocks)) {
- _pos.y -= GRAVITY;
+ if (_orientation == -1 && can_move_up(blocks,
+ number_of_blocks)) {
+ _pos.y -= GRAVITY;
}
-
+
if (pad.get_coord().x < -0.7f && can_move_left(blocks,number_of_blocks)) {
_pos.x -= 2;