summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-08-27 19:05:07 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2006-08-27 19:05:07 +0000
commit6f6d061b23c6c70c632fb3ec6aa3735325f701e0 (patch)
treea0d57853d826ebca0abe9ec86973c64bec688427 /src/localplayer.cpp
parenta544d1b3bf1d133d5877aa97d59d7128555e69fc (diff)
downloadMana-6f6d061b23c6c70c632fb3ec6aa3735325f701e0.tar.gz
Mana-6f6d061b23c6c70c632fb3ec6aa3735325f701e0.tar.bz2
Mana-6f6d061b23c6c70c632fb3ec6aa3735325f701e0.tar.xz
Mana-6f6d061b23c6c70c632fb3ec6aa3735325f701e0.zip
Implemented pixel-grained movements.
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 368bc8e3..9df3ac3f 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -161,30 +161,30 @@ void LocalPlayer::walk(unsigned char dir)
return;
}
- Sint16 dx = 0, dy = 0;
+ int dx = 0, dy = 0;
if (dir & UP)
- dy--;
+ dy -= 32;
if (dir & DOWN)
- dy++;
+ dy += 32;
if (dir & LEFT)
- dx--;
+ dx -= 32;
if (dir & RIGHT)
- dx++;
+ dx += 32;
// Prevent skipping corners over colliding tiles
- if (dx && mMap->tileCollides(mX / 32 + dx, mY / 32))
- dx = 0;
- if (dy && mMap->tileCollides(mX / 32, mY / 32 + dy))
- dy = 0;
+ if (dx && mMap->tileCollides((mX + dx) / 32, mY / 32))
+ dx = 16 - mX % 32;
+ if (dy && mMap->tileCollides(mX / 32, (mY + dy) / 32))
+ dy = 16 - mY % 32;
// Choose a straight direction when diagonal target is blocked
- if (dx && dy && !mMap->getWalk(mX / 32 + dx, mY / 32 + dy))
- dx = 0;
+ if (dx && dy && !mMap->getWalk((mX + dx) / 32, (mY + dy) / 32))
+ dx = 16 - mX % 32;
// Walk to where the player can actually go
- if ((dx || dy) && mMap->getWalk(mX / 32 + dx, mY / 32 + dy))
+ if ((dx || dy) && mMap->getWalk((mX + dx) / 32, (mY + dy) / 32))
{
- setDestination(mX + dx * 32, mY + dy * 32);
+ setDestination(mX + dx, mY + dy);
}
else if (dir)
{
@@ -198,6 +198,14 @@ void LocalPlayer::walk(unsigned char dir)
void LocalPlayer::setDestination(Uint16 x, Uint16 y)
{
+ // Fix coordinates so that the player does not seem to dig into walls.
+ int tx = x / 32, ty = y / 32, fx = x % 32, fy = y % 32;
+ if (fx != 16 && !mMap->getWalk(tx + fx / 16 * 2 - 1, ty)) fx = 16;
+ if (fy != 16 && !mMap->getWalk(tx, ty + fy / 16 * 2 - 1)) fy = 16;
+ if (fx != 16 && fy != 16 && !mMap->getWalk(tx + fx / 16 * 2 - 1, ty + fy / 16 * 2 - 1)) fx = 16;
+ x = tx * 32 + fx;
+ y = ty * 32 + fy;
+
MessageOut msg(PGMSG_WALK);
msg.writeShort(x);
msg.writeShort(y);