From 3c8e99cdfeee6b4db1dc56941659b94445601618 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Thu, 17 Mar 2011 20:07:03 +0100 Subject: Fixed pick up using keyboard for both servers. The character picks up one item at a time (to remain kinda realistic) and turns to the item picked up. --- src/game.cpp | 50 ++++++++++++++++++++++++++++++-------------------- src/localplayer.cpp | 4 ++-- 2 files changed, 32 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index fd453434..206be6c5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -631,31 +631,41 @@ void Game::handleInput() { int x = player_node->getTileX(); int y = player_node->getTileY(); - - FloorItem *item = - actorSpriteManager->findItem(x, y); - - // If none below the player, try the tile in front - // of the player - if (!item) + // Let's look for items around until you find one. + bool found = false; + for (int xX = x - 1; xX < x + 2; ++xX) { - // Temporary until tile-based picking is - // removed. - switch (player_node->getSpriteDirection()) + for (int yY = y - 1; yY < y + 2; ++yY) { - case DIRECTION_UP : --y; break; - case DIRECTION_DOWN : ++y; break; - case DIRECTION_LEFT : --x; break; - case DIRECTION_RIGHT: ++x; break; - default: break; + FloorItem *item = + actorSpriteManager->findItem(xX, yY); + if (item) + { + found = true; + player_node->pickUp(item); + // We found it, so set the player + // direction accordingly, + Uint8 dir = 0; + if (xX < x) + dir |= Being::LEFT; + else if (xX > x) + dir |= Being::RIGHT; + if (yY < y) + dir |= Being::UP; + else if (yY > y) + dir |= Being::DOWN; + + if (dir) + player_node->setDirection(dir); + + // Get out of the loops + break; + } } - - item = actorSpriteManager->findItem(x, y); + if (found) + break; } - if (item) - player_node->pickUp(item); - used = true; } break; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 7daceb0f..8e75333f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -604,8 +604,8 @@ void LocalPlayer::pickUp(FloorItem *item) } else { - setDestination(item->getPixelX() + tileWidth / 2, - item->getPixelY() + tileHeight / 2); + setDestination(item->getTileX() * tileWidth + tileWidth / 2, + item->getTileY() * tileHeight + tileHeight / 2); mPickUpTarget = item; } } -- cgit v1.2.3-70-g09d2