diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-17 20:07:03 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-03-17 20:07:03 +0100 |
commit | 3c8e99cdfeee6b4db1dc56941659b94445601618 (patch) | |
tree | 5bff0aeb5f033d5cd0c2580275182e826ecbfd67 /src/game.cpp | |
parent | 7e8d7f89c5d0aa07159e9b43ea39334907bcab1f (diff) | |
download | mana-client-3c8e99cdfeee6b4db1dc56941659b94445601618.tar.gz mana-client-3c8e99cdfeee6b4db1dc56941659b94445601618.tar.bz2 mana-client-3c8e99cdfeee6b4db1dc56941659b94445601618.tar.xz mana-client-3c8e99cdfeee6b4db1dc56941659b94445601618.zip |
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.
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 50 |
1 files changed, 30 insertions, 20 deletions
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; |