summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-17 16:46:06 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-06-17 16:46:06 +0200
commit914d3de7c324cb1ec456892702689718352a7842 (patch)
treeeb05c251adb6f012a40f3d7de4eb42ab854b7d94
parentfaf0a45d6b8b85acd2836cf5e8e7f7c5b161931d (diff)
downloadmana-914d3de7c324cb1ec456892702689718352a7842.tar.gz
mana-914d3de7c324cb1ec456892702689718352a7842.tar.bz2
mana-914d3de7c324cb1ec456892702689718352a7842.tar.xz
mana-914d3de7c324cb1ec456892702689718352a7842.zip
First pass on removing tile hard coded values.
Every files has been checked against the hard coded 32 values except the map.cpp file. I also added convenience functions in the Game class, centralized the default item icon size, and removed two unused defines in being.cpp.
-rw-r--r--src/actorspritemanager.cpp16
-rw-r--r--src/being.cpp6
-rw-r--r--src/commandhandler.cpp4
-rw-r--r--src/game.cpp16
-rw-r--r--src/game.h6
-rw-r--r--src/gui/minimap.cpp24
-rw-r--r--src/gui/minimap.h1
-rw-r--r--src/gui/outfitwindow.cpp8
-rw-r--r--src/gui/viewport.cpp3
-rw-r--r--src/gui/widgets/shoplistbox.cpp2
-rw-r--r--src/item.h2
-rw-r--r--src/localplayer.cpp116
-rw-r--r--src/map.h2
-rw-r--r--src/net/manaserv/playerhandler.cpp11
-rw-r--r--src/particleemitter.cpp9
-rw-r--r--src/simpleanimation.cpp13
16 files changed, 160 insertions, 79 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index 0134dd63..fedf880c 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -21,6 +21,7 @@
#include "actorspritemanager.h"
+#include "game.h"
#include "localplayer.h"
#include "utils/dtor.h"
@@ -37,12 +38,17 @@ class FindBeingFunctor
{
if (actor->getType() == ActorSprite::FLOOR_ITEM)
return false;
+ Game *game = Game::instance();
+ if (!game)
+ return false;
+
Being* b = static_cast<Being*>(actor);
uint16_t other_y = y + ((b->getType() == ActorSprite::NPC) ? 1 : 0);
const Vector &pos = b->getPosition();
- return ((int) pos.x / 32 == x &&
- ((int) pos.y / 32 == y || (int) pos.y / 32 == other_y) &&
+ return ((int) pos.x / game->getCurrentTileWidth() == x &&
+ ((int) pos.y / game->getCurrentTileHeight() == y
+ || (int) pos.y / game->getCurrentTileHeight() == other_y) &&
b->isAlive() &&
(type == ActorSprite::UNKNOWN || b->getType() == type));
}
@@ -272,10 +278,14 @@ Being *ActorSpriteManager::findNearestLivingBeing(int x, int y,
ActorSprite::Type type,
Being *excluded) const
{
+ Game *game = Game::instance();
+ if (!game)
+ return 0;
+
Being *closestBeing = 0;
int dist = 0;
- const int maxDist = maxTileDist * 32;
+ const int maxDist = maxTileDist * game->getCurrentTileWidth();
for_actors
{
diff --git a/src/being.cpp b/src/being.cpp
index d9180bc9..69c233f2 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -27,6 +27,7 @@
#include "configuration.h"
#include "effectmanager.h"
#include "event.h"
+#include "game.h"
#include "graphics.h"
#include "guild.h"
#include "localplayer.h"
@@ -67,8 +68,6 @@
#define HAIR_FILE "hair.xml"
-static const int DEFAULT_BEING_WIDTH = 32;
-static const int DEFAULT_BEING_HEIGHT = 32;
int Being::mNumberOfHairstyles = 1;
Being::Being(int id, Type type, int subtype, Map *map):
@@ -592,7 +591,8 @@ void Being::fireMissile(Being *victim, const std::string &particle)
if (missile)
{
Particle *target = particleEngine->createChild();
- target->moveBy(Vector(0.0f, 0.0f, 32.0f));
+ target->moveBy(Vector(0.0f, 0.0f,
+ Game::instance()->getCurrentTileWidth()));
target->setLifetime(1000);
victim->controlParticle(target);
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index f5864a24..25067fca 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -339,8 +339,8 @@ void CommandHandler::handleWhere(const std::string &args, ChatTab *tab)
{
std::ostringstream where;
where << Game::instance()->getCurrentMapName() << ", coordinates: "
- << ((player_node->getPixelX() - 16) / 32) << ", "
- << ((player_node->getPixelY() - 32) / 32);
+ << player_node->getTileX() << ", "
+ << player_node->getTileY();
tab->chatLog(where.str(), BY_SERVER);
}
diff --git a/src/game.cpp b/src/game.cpp
index 5bbe2d07..af9c2c39 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -979,3 +979,19 @@ void Game::changeMap(const std::string &mapPath)
event.setString("mapPath", mapPath);
event.trigger(Event::GameChannel);
}
+
+int Game::getCurrentTileWidth() const
+{
+ if (mCurrentMap)
+ return mCurrentMap->getTileWidth();
+
+ return DEFAULT_TILE_LENGTH;
+}
+
+int Game::getCurrentTileHeight() const
+{
+ if (mCurrentMap)
+ return mCurrentMap->getTileHeight();
+
+ return DEFAULT_TILE_LENGTH;
+}
diff --git a/src/game.h b/src/game.h
index b2fae121..22e242c9 100644
--- a/src/game.h
+++ b/src/game.h
@@ -67,6 +67,12 @@ class Game
const std::string &getCurrentMapName() { return mMapName; }
+ /**
+ * Convenience functions used to get the current tile width and height.
+ */
+ int getCurrentTileWidth() const;
+ int getCurrentTileHeight() const;
+
private:
int mLastTarget;
bool mDisconnected;
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 993814ea..7ad034e4 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -43,6 +43,7 @@ bool Minimap::mShow = true;
Minimap::Minimap():
Window(_("Map")),
+ mMap(0),
mMapImage(0),
mWidthProportion(0.5),
mHeightProportion(0.5)
@@ -96,6 +97,7 @@ void Minimap::setMap(Map *map)
if (map)
{
+ mMap = map;
std::string tempname =
"graphics/minimaps/" + map->getFilename() + ".png";
ResourceManager *resman = ResourceManager::getInstance();
@@ -159,14 +161,17 @@ void Minimap::draw(gcn::Graphics *graphics)
int mapOriginX = 0;
int mapOriginY = 0;
- if (mMapImage)
+ if (mMapImage && mMap)
{
if (mMapImage->getWidth() > a.width ||
mMapImage->getHeight() > a.height)
{
const Vector &p = player_node->getPosition();
- mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mWidthProportion) / 32);
- mapOriginY = (int) (((a.height) / 2) - (int) (p.y * mHeightProportion) / 32);
+ mapOriginX = (int) (((a.width) / 2) - (int) (p.x * mWidthProportion)
+ / mMap->getTileWidth());
+ mapOriginY = (int) (((a.height) / 2)
+ - (int) (p.y * mHeightProportion)
+ / mMap->getTileHeight());
const int minOriginX = a.width - mMapImage->getWidth();
const int minOriginY = a.height - mMapImage->getHeight();
@@ -230,10 +235,15 @@ void Minimap::draw(gcn::Graphics *graphics)
const int offsetWidth = (int) ((dotSize - 1) * mWidthProportion);
const Vector &pos = being->getPosition();
- graphics->fillRectangle(gcn::Rectangle(
- (int) (pos.x * mWidthProportion) / 32 + mapOriginX - offsetWidth,
- (int) (pos.y * mHeightProportion) / 32 + mapOriginY - offsetHeight,
- dotSize, dotSize));
+ if (mMap)
+ {
+ graphics->fillRectangle(gcn::Rectangle(
+ (int) (pos.x * mWidthProportion) / mMap->getTileWidth()
+ + mapOriginX - offsetWidth,
+ (int) (pos.y * mHeightProportion) / mMap->getTileHeight()
+ + mapOriginY - offsetHeight,
+ dotSize, dotSize));
+ }
}
graphics->popClipArea();
diff --git a/src/gui/minimap.h b/src/gui/minimap.h
index a376a15c..0916a1da 100644
--- a/src/gui/minimap.h
+++ b/src/gui/minimap.h
@@ -58,6 +58,7 @@ class Minimap : public Window
void draw(gcn::Graphics *graphics);
private:
+ Map *mMap;
Image *mMapImage;
float mWidthProportion;
float mHeightProportion;
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index efa0e08b..053c6659 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -196,9 +196,13 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
const int itemY = 25 + (i / mGridWidth) * mBoxHeight;
graphics->setColor(gcn::Color(0, 0, 0, 64));
- graphics->drawRectangle(gcn::Rectangle(itemX, itemY, 32, 32));
+ graphics->drawRectangle(gcn::Rectangle(itemX, itemY,
+ ITEM_ICON_SIZE,
+ ITEM_ICON_SIZE));
graphics->setColor(gcn::Color(255, 255, 255, 32));
- graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32));
+ graphics->fillRectangle(gcn::Rectangle(itemX, itemY,
+ ITEM_ICON_SIZE,
+ ITEM_ICON_SIZE));
if (mItems[mCurrentOutfit][i] < 0)
{
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index e10a1a60..0353fd44 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -402,7 +402,8 @@ void Viewport::_drawPath(Graphics *graphics, const Path &path,
graphics->fillRectangle(gcn::Rectangle(squareX - 4, squareY - 4,
8, 8));
graphics->drawText(
- toString(mMap->getMetaTile(i->x / 32, i->y / 32)->Gcost),
+ toString(mMap->getMetaTile(i->x / mMap->getTileWidth(),
+ i->y / mMap->getTileHeight())->Gcost),
squareX + 4, squareY + 12, gcn::Graphics::CENTER);
}
}
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index ae7d4d9b..2d25185a 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -36,8 +36,6 @@
#include <guichan/font.hpp>
#include <guichan/listmodel.hpp>
-const int ITEM_ICON_SIZE = 32;
-
float ShopListBox::mAlpha = 1.0;
ShopListBox::ShopListBox(gcn::ListModel *listModel):
diff --git a/src/item.h b/src/item.h
index f6574f8c..adca4b79 100644
--- a/src/item.h
+++ b/src/item.h
@@ -28,6 +28,8 @@
class Image;
+const int ITEM_ICON_SIZE = 32;
+
/**
* Represents one or more instances of a certain item type.
*/
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index a375da92..d9eb3f1f 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -213,11 +213,14 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!mMap || (!dx && !dy))
return Position((int)pos.x, (int)pos.y);
+ int tileW = mMap->getTileWidth();
+ int tileH = mMap->getTileHeight();
+
// Get the current tile pos and its offset
- int tileX = (int)pos.x / mMap->getTileWidth();
- int tileY = (int)pos.y / mMap->getTileHeight();
- int offsetX = (int)pos.x % mMap->getTileWidth();
- int offsetY = (int)pos.y % mMap->getTileHeight();
+ int tileX = (int)pos.x / tileW;
+ int tileY = (int)pos.y / tileH;
+ int offsetX = (int)pos.x % tileW;
+ int offsetY = (int)pos.y % tileH;
// Get the walkability of every surrounding tiles.
bool wTopLeft = mMap->getWalk(tileX - 1, tileY - 1, getWalkMask());
@@ -262,14 +265,14 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wTop && !wRight)
dx = 0;
else if (!wTop && !wRight)
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + tileW
+ - getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
else // Both straight direction are walkable
{
// Go right when below the corner
- if (offsetY >= (offsetX / mMap->getTileHeight()
- - (offsetX / mMap->getTileWidth()
- * mMap->getTileHeight()) ))
+ if (offsetY >=
+ (offsetX / tileH - (offsetX / tileW * tileH)))
dy = 0;
else // Go up otherwise
dx = 0;
@@ -278,7 +281,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x + 32, (int)pos.y - 32));
+ Position((int)pos.x + tileW,
+ (int)pos.y - tileH));
}
// Going top-left
@@ -292,8 +296,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wTop && !wLeft)
dx = 0;
else if (!wTop && !wLeft)
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
else // Both straight direction are walkable
{
// Go left when below the corner
@@ -307,7 +311,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x - 32, (int)pos.y - 32));
+ Position((int)pos.x - tileW,
+ (int)pos.y - tileH));
}
// Going bottom-left
@@ -321,8 +326,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wBottom && !wLeft)
dx = 0;
else if (!wBottom && !wLeft)
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + tileH - getCollisionRadius());
else // Both straight direction are walkable
{
// Go down when below the corner
@@ -337,7 +342,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x - 32, (int)pos.y + 32));
+ Position((int)pos.x - tileW,
+ (int)pos.y + tileH));
}
// Going bottom-right
@@ -351,8 +357,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else if (wBottom && !wRight)
dx = 0;
else if (!wBottom && !wRight)
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW + tileW - getCollisionRadius(),
+ tileY * tileH + tileH - getCollisionRadius());
else // Both straight direction are walkable
{
// Go down when below the corner
@@ -366,7 +372,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
else // The diagonal is walkable
return mMap->checkNodeOffsets(getCollisionRadius(),
getWalkMask(),
- Position((int)pos.x + 32, (int)pos.y + 32));
+ Position((int)pos.x + tileW,
+ (int)pos.y + tileH));
}
} // End of diagonal cases
@@ -378,7 +385,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wRight)
- return Position(tileX * 32 + 32 - getCollisionRadius(), (int)pos.y);
+ return Position(tileX * tileW + tileW - getCollisionRadius(),
+ (int)pos.y);
else
{
if (!wTopRight)
@@ -388,8 +396,9 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
@@ -397,18 +406,21 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!wBottomRight)
{
// If we're going to collide with the bottom-right corner
- if (offsetY + getCollisionRadius() > 32)
+ if (offsetY + getCollisionRadius() > tileH)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x + 32, (int)pos.y));
+ Position((int)pos.x + tileW,
+ (int)pos.y));
}
}
@@ -418,7 +430,7 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wLeft)
- return Position(tileX * 32 + getCollisionRadius(), (int)pos.y);
+ return Position(tileX * tileW + getCollisionRadius(), (int)pos.y);
else
{
if (!wTopLeft)
@@ -428,8 +440,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
@@ -437,18 +449,20 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!wBottomLeft)
{
// If we're going to collide with the bottom-left corner
- if (offsetY + getCollisionRadius() > 32)
+ if (offsetY + getCollisionRadius() > tileH)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x - 32, (int)pos.y));
+ Position((int)pos.x - tileW,
+ (int)pos.y));
}
}
@@ -458,7 +472,7 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wTop)
- return Position((int)pos.x, tileY * 32 + getCollisionRadius());
+ return Position((int)pos.x, tileY * tileH + getCollisionRadius());
else
{
if (!wTopLeft)
@@ -468,8 +482,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
@@ -477,18 +491,20 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
if (!wTopRight)
{
// If we're going to collide with the top-right corner
- if (offsetX + getCollisionRadius() > 32)
+ if (offsetX + getCollisionRadius() > tileW)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH + getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x, (int)pos.y - 32));
+ Position((int)pos.x,
+ (int)pos.y - tileH));
}
}
@@ -498,7 +514,8 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
// If the straight destination is blocked,
// Make the player go the closest possible.
if (!wBottom)
- return Position((int)pos.x, tileY * 32 + 32 - getCollisionRadius());
+ return Position((int)pos.x, tileY * tileH
+ + tileH - getCollisionRadius());
else
{
if (!wBottomLeft)
@@ -508,27 +525,30 @@ Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
-
+ return Position(tileX * tileW + getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
if (!wBottomRight)
{
// If we're going to collide with the bottom-right corner
- if (offsetX + getCollisionRadius() > 32)
+ if (offsetX + getCollisionRadius() > tileW)
{
// We make the player corrects its offset
// before going further
- return Position(tileX * 32 + 32 - getCollisionRadius(),
- tileY * 32 + 32 - getCollisionRadius());
+ return Position(tileX * tileW
+ + tileW - getCollisionRadius(),
+ tileY * tileH
+ + tileH - getCollisionRadius());
}
}
// If the way is clear, step up one checked tile ahead.
return mMap->checkNodeOffsets(getCollisionRadius(), getWalkMask(),
- Position((int)pos.x, (int)pos.y + 32));
+ Position((int)pos.x,
+ (int)pos.y + tileH));
}
}
diff --git a/src/map.h b/src/map.h
index 7dbc14af..c2bb194f 100644
--- a/src/map.h
+++ b/src/map.h
@@ -40,6 +40,8 @@ class Tileset;
typedef std::vector<Tileset*> Tilesets;
typedef std::vector<MapLayer*> Layers;
+#define DEFAULT_TILE_LENGTH 32
+
/**
* A meta tile stores additional information about a location on a tile map.
* This is information that doesn't need to be repeated for each tile in each
diff --git a/src/net/manaserv/playerhandler.cpp b/src/net/manaserv/playerhandler.cpp
index 4249bac8..ec71143f 100644
--- a/src/net/manaserv/playerhandler.cpp
+++ b/src/net/manaserv/playerhandler.cpp
@@ -46,12 +46,11 @@
#include "net/manaserv/attributes.h"
/**
- * Max. distance we are willing to scroll after a teleport;
+ * Max. distance in tiles we are willing to scroll after a teleport;
* everything beyond will reset the port hard.
- * 32 is the nominal tile width/height.
* @todo: Make this parameter read from config.
*/
-static const int MAP_TELEPORT_SCROLL_DISTANCE = 8 * 32;
+static const int MAP_TELEPORT_SCROLL_DISTANCE = 8;
extern Net::PlayerHandler *playerHandler;
@@ -298,8 +297,10 @@ void PlayerHandler::handleMapChangeMessage(Net::MessageIn &msg)
/* Scroll if neccessary */
if (!sameMap
- || (abs(x - (int) playerPos.x) > MAP_TELEPORT_SCROLL_DISTANCE)
- || (abs(y - (int) playerPos.y) > MAP_TELEPORT_SCROLL_DISTANCE))
+ || (abs(x - (int) playerPos.x) > MAP_TELEPORT_SCROLL_DISTANCE
+ * game->getCurrentTileWidth())
+ || (abs(y - (int) playerPos.y) > MAP_TELEPORT_SCROLL_DISTANCE
+ * game->getCurrentTileHeight()))
{
scrollOffsetX = x - (int) playerPos.x;
scrollOffsetY = y - (int) playerPos.y;
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index b9855c10..32b63c9e 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -29,6 +29,7 @@
#include "resources/image.h"
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "map.h"
#include <cmath>
@@ -199,8 +200,12 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target, Map *
int delay = XML::getProperty(frameNode, "delay", 0);
int offsetX = XML::getProperty(frameNode, "offsetX", 0);
int offsetY = XML::getProperty(frameNode, "offsetY", 0);
- offsetY -= imageset->getHeight() - 32;
- offsetX -= imageset->getWidth() / 2 - 16;
+ if (mMap)
+ {
+ offsetX -= imageset->getWidth() / 2
+ - mMap->getTileWidth() / 2;
+ offsetY -= imageset->getHeight() - mMap->getTileHeight();
+ }
if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
{
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 7ef433ea..24a17ce7 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -21,6 +21,7 @@
#include "simpleanimation.h"
+#include "game.h"
#include "graphics.h"
#include "log.h"
@@ -132,15 +133,19 @@ void SimpleAnimation::initializeAnimation(xmlNodePtr animationNode)
return;
// Get animation frames
- for ( xmlNodePtr frameNode = animationNode->xmlChildrenNode;
- frameNode;
+ for (xmlNodePtr frameNode = animationNode->xmlChildrenNode; frameNode;
frameNode = frameNode->next)
{
int delay = XML::getProperty(frameNode, "delay", 0);
int offsetX = XML::getProperty(frameNode, "offsetX", 0);
int offsetY = XML::getProperty(frameNode, "offsetY", 0);
- offsetY -= imageset->getHeight() - 32;
- offsetX -= imageset->getWidth() / 2 - 16;
+ Game *game = Game::instance();
+ if (game)
+ {
+ offsetX -= imageset->getWidth() / 2
+ - game->getCurrentTileWidth() / 2;
+ offsetY -= imageset->getHeight() - game->getCurrentTileHeight();
+ }
if (xmlStrEqual(frameNode->name, BAD_CAST "frame"))
{