summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Walch <[email protected]>2015-10-14 14:58:44 +0200
committerMartin Walch <[email protected]>2015-10-14 14:58:44 +0200
commit7393fe984f421635f48e077b1f009febfa098d8b (patch)
treef5d0a193fa2df4dec9ec2511ac04968f655d37b6
parente9eed59bdaf65b0128ecb19f5bac099d411a49e1 (diff)
Fix bug #181081: "avatar is caught in an unreachable area"
When Kapman makes a half-turn right after taking a turn at a corner, it may go through an opposing wall. This fix is rather ugly, but a better solution would probably need quite some refactoring. So, just fix it for now. Also merge duplicate code paths in the same function. BUG: 181081
-rw-r--r--character.cpp10
-rw-r--r--character.h7
-rw-r--r--kapman.cpp39
3 files changed, 32 insertions, 24 deletions
diff --git a/character.cpp b/character.cpp
index 7e6577a..32af623 100644
--- a/character.cpp
+++ b/character.cpp
@@ -233,6 +233,16 @@ bool Character::onCenter()
return willGoPast;
}
+bool Character::isOnCenter()
+{
+ // Get the current cell center coordinates
+ qreal centerX = (m_maze->getColFromX(m_x) + 0.5) * Cell::SIZE;
+ qreal centerY = (m_maze->getRowFromY(m_y) + 0.5) * Cell::SIZE;
+
+ return m_x == centerX && m_y == centerY;
+}
+
+
void Character::moveOnCenter()
{
setX((m_maze->getColFromX(m_x) + 0.5) * Cell::SIZE);
diff --git a/character.h b/character.h
index 1a9fbcf..cddb22d 100644
--- a/character.h
+++ b/character.h
@@ -193,6 +193,12 @@ protected:
bool onCenter();
/**
+ * Checks whether the Character is currently on a Cell center.
+ * @return true if the Character is on a Cell center, false otherwise
+ */
+ bool isOnCenter();
+
+ /**
* Moves the character on the center of its current Cell.
*/
void moveOnCenter();
@@ -206,4 +212,3 @@ signals:
};
#endif
-
diff --git a/kapman.cpp b/kapman.cpp
index a2bb315..9c6ba13 100644
--- a/kapman.cpp
+++ b/kapman.cpp
@@ -95,31 +95,25 @@ void Kapman::updateMove()
if ((m_xSpeed != 0 && m_askedXSpeed == -m_xSpeed) || (m_ySpeed != 0 && m_askedYSpeed == -m_ySpeed)) {
// Go back
updateDirection();
- // Move the kapman
- move();
+ // If the kapman just turned at a corner and instantly makes a half-turn, do not run into a wall
+ if (isOnCenter() && getNextCell().getType() != Cell::CORRIDOR) {
+ // Stop moving
+ stopMoving();
+ } else {
+ // Move the kapman
+ move();
+ }
} else {
// If the kapman gets on a cell center
if (onCenter()) {
- // If there is an asked direction (but not a half-turn)
- if ((m_askedXSpeed != 0 || m_askedYSpeed != 0) && (m_askedXSpeed != m_xSpeed || m_askedYSpeed != m_ySpeed)) {
- // Check the next cell with the kapman asked direction
- if (getAskedNextCell().getType() == Cell::CORRIDOR) {
- // Move the kapman on the cell center
- moveOnCenter();
- // Update the direction
- updateDirection();
- } else {
- // Check the next cell with the kapman current direction
- if (getNextCell().getType() != Cell::CORRIDOR) {
- // Move the kapman on the cell center
- moveOnCenter();
- // Stop moving
- stopMoving();
- } else {
- // Move the kapman
- move();
- }
- }
+ // If there is an asked direction (not a half-turn) and the corresponding next cell is accessible
+ if ((m_askedXSpeed != 0 || m_askedYSpeed != 0)
+ && (m_askedXSpeed != m_xSpeed || m_askedYSpeed != m_ySpeed)
+ && (getAskedNextCell().getType() == Cell::CORRIDOR)) {
+ // Move the kapman on the cell center
+ moveOnCenter();
+ // Update the direction
+ updateDirection();
} else {
// Check the next cell with the kapman current direction
if (getNextCell().getType() != Cell::CORRIDOR) {
@@ -211,4 +205,3 @@ void Kapman::initSpeedInc()
break;
}
}
-