aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Hesse2012-06-03 03:29:35 +0200
committerSven Hesse2012-06-03 03:29:35 +0200
commit627e870629cdab1009d3279453d082a3c44acd03 (patch)
tree8bd0e1a01edb670b1316b7f323d9f6583f606115
parent95e467d82cb36ee0d98624dd2cdd6d79b544c50c (diff)
downloadscummvm-rg350-627e870629cdab1009d3279453d082a3c44acd03.tar.gz
scummvm-rg350-627e870629cdab1009d3279453d082a3c44acd03.tar.bz2
scummvm-rg350-627e870629cdab1009d3279453d082a3c44acd03.zip
GOB: Limit Penetration movement to walkable tiles
-rw-r--r--engines/gob/minigames/geisha/penetration.cpp36
-rw-r--r--engines/gob/minigames/geisha/penetration.h2
2 files changed, 34 insertions, 4 deletions
diff --git a/engines/gob/minigames/geisha/penetration.cpp b/engines/gob/minigames/geisha/penetration.cpp
index 377835c45f..c8fbe31249 100644
--- a/engines/gob/minigames/geisha/penetration.cpp
+++ b/engines/gob/minigames/geisha/penetration.cpp
@@ -423,6 +423,15 @@ int16 Penetration::checkInput(int16 &mouseX, int16 &mouseY, MouseButtons &mouseB
return _vm->_util->checkKey();
}
+bool Penetration::isWalkable(byte tile) const {
+ // Only walls are nonwalkable
+
+ if (tile == 50)
+ return false;
+
+ return true;
+}
+
void Penetration::handleSub(int16 key) {
if (key == kKeyLeft)
moveSub(-5, 0, kAnimationDriveW);
@@ -435,11 +444,30 @@ void Penetration::handleSub(int16 key) {
}
void Penetration::moveSub(int x, int y, uint16 animation) {
- _mapX = CLIP<int16>(_mapX + x, 0, kMapWidth * kMapTileWidth);
- _mapY = CLIP<int16>(_mapY + y, 0, kMapHeight * kMapTileHeight);
+ // Limit the movement to walkable tiles
+
+ int16 minX = 0;
+ if ((_subTileX > 0) && !isWalkable(_mapTiles[_subTileY * kMapWidth + (_subTileX - 1)]))
+ minX = _subTileX * kMapTileWidth;
+
+ int16 maxX = kMapWidth * kMapTileWidth;
+ if ((_subTileX < (kMapWidth - 1)) && !isWalkable(_mapTiles[_subTileY * kMapWidth + (_subTileX + 1)]))
+ maxX = _subTileX * kMapTileWidth;
+
+ int16 minY = 0;
+ if ((_subTileY > 0) && !isWalkable(_mapTiles[(_subTileY - 1) * kMapWidth + _subTileX]))
+ minY = _subTileY * kMapTileHeight;
+
+ int16 maxY = kMapHeight * kMapTileHeight;
+ if ((_subTileY < (kMapHeight - 1)) && !isWalkable(_mapTiles[(_subTileY + 1) * kMapWidth + _subTileX]))
+ maxY = _subTileY * kMapTileHeight;
+
+ _mapX = CLIP<int16>(_mapX + x, minX, maxX);
+ _mapY = CLIP<int16>(_mapY + y, minY, maxY);
- _subTileX = _mapX / kMapTileWidth;
- _subTileY = _mapY / kMapTileHeight;
+ // The tile the sub is on is where its mid-point is
+ _subTileX = (_mapX + (kMapTileWidth / 2)) / kMapTileWidth;
+ _subTileY = (_mapY + (kMapTileHeight / 2)) / kMapTileHeight;
_mapUpdate = true;
diff --git a/engines/gob/minigames/geisha/penetration.h b/engines/gob/minigames/geisha/penetration.h
index 28a288928b..9109cb5c68 100644
--- a/engines/gob/minigames/geisha/penetration.h
+++ b/engines/gob/minigames/geisha/penetration.h
@@ -96,6 +96,8 @@ private:
void handleSub(int16 key);
void moveSub(int x, int y, uint16 animation);
+
+ bool isWalkable(byte tile) const;
};
} // End of namespace Geisha