diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-08-27 11:21:10 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2006-08-27 11:21:10 +0000 |
commit | d3cba1c4beac4a1c98f38bbca076a98f9c90bbc4 (patch) | |
tree | e7d1ea0a7575d0dd28802e7dfe2a322e818729fc | |
parent | 5980dba7ace73e6587b9966bc2076ad2b2eaa5f0 (diff) | |
download | Mana-d3cba1c4beac4a1c98f38bbca076a98f9c90bbc4.tar.gz Mana-d3cba1c4beac4a1c98f38bbca076a98f9c90bbc4.tar.bz2 Mana-d3cba1c4beac4a1c98f38bbca076a98f9c90bbc4.tar.xz Mana-d3cba1c4beac4a1c98f38bbca076a98f9c90bbc4.zip |
Changed to pixel-based coordinates for beings.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/being.cpp | 18 | ||||
-rw-r--r-- | src/being.h | 2 | ||||
-rw-r--r-- | src/beingmanager.cpp | 4 | ||||
-rw-r--r-- | src/engine.cpp | 16 | ||||
-rw-r--r-- | src/game.cpp | 14 | ||||
-rw-r--r-- | src/gui/gui.cpp | 2 | ||||
-rw-r--r-- | src/localplayer.cpp | 20 | ||||
-rw-r--r-- | src/map.cpp | 2 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 8 | ||||
-rw-r--r-- | src/net/playerhandler.cpp | 6 |
11 files changed, 48 insertions, 49 deletions
@@ -3,6 +3,11 @@ * src/localplayer.cpp, src/net/protocol.h: Send move message whenever a destination is selected. * src/beinghandler.cpp: Smoothed being trajectories. + * src/localplayer.cpp, src/game.cpp, src/map.cpp, src/gui/gui.cpp, + src/engine.cpp, src/beingmanager.cpp, src/being.cpp, src/being.h, + src/net/beinghandler.cpp, src/net/playerhandler.cpp: Changed beings + tile-based coordinates to pixel-based coordinates (almost, they point + to tile centers for now). 2006-08-27 Bjørn Lindeijer <bjorn@lindeijer.nl> diff --git a/src/being.cpp b/src/being.cpp index 87332c7a..b49f790e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -79,7 +79,7 @@ Being::setDestination(Uint16 destX, Uint16 destY) { if (mMap) { - setPath(mMap->findPath(mX, mY, destX, destY)); + setPath(mMap->findPath(mX / 32, mY / 32, destX / 32, destY / 32)); } } @@ -265,19 +265,19 @@ Being::nextStep() mPath.pop_front(); int dir = 0; - if (node.x > mX) + if (node.x > mX / 32) dir |= RIGHT; - else if (node.x < mX) + else if (node.x < mX / 32) dir |= LEFT; - if (node.y > mY) + if (node.y > mY / 32) dir |= DOWN; - else if (node.y < mY) + else if (node.y < mY / 32) dir |= UP; setDirection(dir); - mX = node.x; - mY = node.y; + mX = node.x * 32 + 16; + mY = node.y * 32 + 16; setAction(WALK); mWalkTime += mWalkSpeed / 10; } @@ -298,8 +298,8 @@ Being::logic() } // Update pixel coordinates - mPx = mX * 32 + getXOffset(); - mPy = mY * 32 + getYOffset(); + mPx = mX - 16 + getXOffset(); + mPy = mY - 16 + getYOffset(); if (mEmotion != 0) { diff --git a/src/being.h b/src/being.h index b99f85a3..7e5645ae 100644 --- a/src/being.h +++ b/src/being.h @@ -100,7 +100,7 @@ class Being : public Sprite std::string mName; /**< Name of character */ Uint16 mJob; /**< Job (player job, npc, monster, ) */ - Uint16 mX, mY; /**< Tile coordinates */ + Uint16 mX, mY; /**< Pixel coordinates (tile center) */ Uint8 mDirection; /**< Facing direction */ Uint8 mAction; /**< Action the being is performing */ Uint8 mFrame; diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index a6c7974d..74709fdf 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -39,8 +39,8 @@ class FindBeingFunctor bool operator() (Being *being) { Uint16 other_y = y + ((being->getType() == Being::NPC) ? 1 : 0); - return (being->mX == x && - (being->mY == y || being->mY == other_y) && + return (being->mX / 32 == x && + (being->mY / 32 == y || being->mY / 32 == other_y) && being->mAction != Being::MONSTER_DEAD && (type == Being::UNKNOWN || being->getType() == type)); } diff --git a/src/engine.cpp b/src/engine.cpp index 7a33dd3d..f3aff6ce 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -155,11 +155,11 @@ void Engine::logic() void Engine::draw(Graphics *graphics) { - int midTileX = graphics->getWidth() / 32 / 2; - int midTileY = graphics->getHeight() / 32 / 2; + int midTileX = graphics->getWidth() / 2; + int midTileY = graphics->getHeight() / 2; - int map_x = (player_node->mX - midTileX) * 32 + player_node->getXOffset(); - int map_y = (player_node->mY - midTileY) * 32 + player_node->getYOffset(); + int map_x = (player_node->mX - midTileX) + player_node->getXOffset(); + int map_y = (player_node->mY - midTileY) + player_node->getYOffset(); if (mCurrentMap) { if (map_x < 0) { @@ -168,11 +168,11 @@ void Engine::draw(Graphics *graphics) if (map_y < 0) { map_y = 0; } - if (map_x > (mCurrentMap->getWidth() - midTileX) * 32) { - map_x = (mCurrentMap->getWidth() - midTileX) * 32; + if (map_x > mCurrentMap->getWidth() * 32 - midTileX) { + map_x = mCurrentMap->getWidth() * 32 - midTileX; } - if (map_y > (mCurrentMap->getHeight() - midTileY) * 32) { - map_y = (mCurrentMap->getHeight() - midTileY) * 32; + if (map_y > mCurrentMap->getHeight() * 32 - midTileY) { + map_y = mCurrentMap->getHeight() * 32 - midTileY; } } diff --git a/src/game.cpp b/src/game.cpp index f83e9c1f..3e789728 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -462,14 +462,12 @@ void Game::handleInput() case SDLK_z: if (!chatWindow->isFocused()) { - FloorItem *item = floorItemManager->findByCoordinates( - player_node->mX, player_node->mY); + Uint16 x = player_node->mX / 32, y = player_node->mY / 32; + FloorItem *item = floorItemManager->findByCoordinates(x, y); // If none below the player, try the tile in front of // the player if (!item) { - Uint16 x = player_node->mX; - Uint16 y = player_node->mY; if (player_node->mDirection & Being::UP) y--; if (player_node->mDirection & Being::DOWN) @@ -591,8 +589,7 @@ void Game::handleInput() current_npc == 0 && !chatWindow->isFocused()) { - Uint16 x = player_node->mX; - Uint16 y = player_node->mY; + Uint16 x = player_node->mX / 32, y = player_node->mY / 32; unsigned char Direction = 0; // Translate pressed keys to movement and direction @@ -644,7 +641,7 @@ void Game::handleInput() if (player_node->mDirection & Being::RIGHT) targetX++; - // Attack priorioty is: Monster, Player, auto target + // Attack priority is: Monster, Player, auto target target = beingManager->findBeing( targetX, targetY, Being::MONSTER); if (!target) @@ -659,8 +656,7 @@ void Game::handleInput() { if (joystick->buttonPressed(1)) { - FloorItem *item = floorItemManager->findByCoordinates( - player_node->mX, player_node->mY); + FloorItem *item = floorItemManager->findByCoordinates(x, y); if (item) player_node->pickUp(item); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 0e200db3..a3ec299b 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -313,7 +313,7 @@ Gui::mousePress(int mx, int my, int button) Uint8 *keys = SDL_GetKeyState(NULL); if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT])) { - player_node->setDestination(tilex, tiley); + player_node->setDestination(tilex * 32 + 16, tiley * 32 + 16); player_node->stopAttack(); } } diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 55f536db..72e2a369 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -152,15 +152,15 @@ void LocalPlayer::dropItem(Item *item, int quantity) void LocalPlayer::pickUp(FloorItem *item) { - int dx = item->getX() - mX; - int dy = item->getY() - mY; + int dx = item->getX() - mX / 32; + int dy = item->getY() - mY / 32; if (dx * dx + dy * dy < 4) { MessageOut outMsg(CMSG_ITEM_PICKUP); outMsg.writeLong(item->getId()); mPickUpTarget = NULL; } else { - setDestination(item->getX(), item->getY()); + setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16); mPickUpTarget = item; stopAttack(); } @@ -189,19 +189,19 @@ void LocalPlayer::walk(unsigned char dir) dx++; // Prevent skipping corners over colliding tiles - if (dx && mMap->tileCollides(mX + dx, mY)) + if (dx && mMap->tileCollides(mX / 32 + dx, mY / 32)) dx = 0; - if (dy && mMap->tileCollides(mX, mY + dy)) + if (dy && mMap->tileCollides(mX / 32, mY / 32 + dy)) dy = 0; // Choose a straight direction when diagonal target is blocked - if (dx && dy && !mMap->getWalk(mX + dx, mY + dy)) + if (dx && dy && !mMap->getWalk(mX / 32 + dx, mY / 32 + dy)) dx = 0; // Walk to where the player can actually go - if ((dx || dy) && mMap->getWalk(mX + dx, mY + dy)) + if ((dx || dy) && mMap->getWalk(mX / 32 + dx, mY / 32 + dy)) { - setDestination(mX + dx, mY + dy); + setDestination(mX + dx * 32, mY + dy * 32); } else if (dir) { @@ -216,8 +216,8 @@ void LocalPlayer::walk(unsigned char dir) void LocalPlayer::setDestination(Uint16 x, Uint16 y) { MessageOut msg(PGMSG_WALK); - msg.writeShort(x * 32 + 16); - msg.writeShort(y * 32 + 16); + msg.writeShort(x); + msg.writeShort(y); Network::send(Network::GAME, msg); mPickUpTarget = NULL; diff --git a/src/map.cpp b/src/map.cpp index 531b0f15..1b2ce1e8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -225,7 +225,7 @@ Map::getWalk(int x, int y) Beings *beings = beingManager->getAll(); for (BeingIterator i = beings->begin(); i != beings->end(); i++) { // job 45 is a portal, they don't collide - if ((*i)->mX == x && (*i)->mY == y && (*i)->mJob != 45) { + if ((*i)->mX / 32 == x && (*i)->mY / 32 == y && (*i)->mJob != 45) { return false; } } diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 4ff92b63..ac2801c2 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -422,16 +422,16 @@ void BeingHandler::handleBeingsMoveMessage(MessageIn &msg) int sx = msg.readShort(), sy = msg.readShort(), dx = msg.readShort(), dy = msg.readShort(); bool update = being != player_node; // the local player already knows where he wants to go - if (abs(being->mX - sx / 32) + abs(being->mY - sy / 32) > 4) + if (abs(being->mX - sx) + abs(being->mY - sy) > 4 * 32) { // crude handling of synchronization messages - being->mX = sx / 32; - being->mY = sy / 32; + being->mX = sx; + being->mY = sy; update = true; } if (update) { - being->setDestination(dx / 32, dy / 32); + being->setDestination(dx, dy); } } } diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index c73aa2da..fc6bb37d 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -321,10 +321,8 @@ PlayerHandler::handleMapChangeMessage(MessageIn &msg) player_node->stopAttack(); player_node->mFrame = 0; - // TODO: Server is sending pixel coordinates. Client will need to work with - // these instead of converting them to tile coordinates. - player_node->mX = x / 32; - player_node->mY = y / 32; + player_node->mX = x; + player_node->mY = y; if (newServer) { |