summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp53
1 files changed, 51 insertions, 2 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 6e33d255..abe87dfd 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -62,6 +62,34 @@ struct Location
MetaTile *tile;
};
+TileAnimation::TileAnimation(Animation *ani):
+ mAnimation(ani),
+ mLastUpdate(tick_time),
+ mLastImage(NULL)
+{
+}
+
+void TileAnimation::update()
+{
+ //update animation
+ mAnimation.update(tick_time - mLastUpdate);
+ mLastUpdate = tick_time;
+
+ // exchange images
+ Image *img = mAnimation.getCurrentImage();
+ if (img != mLastImage)
+ {
+ for (std::list<std::pair<MapLayer*, int> >::iterator i = mAffected.begin();
+ i != mAffected.end();
+ i++)
+ {
+ i->first->setTile(i->second, img);
+ }
+ mLastImage = img;
+ }
+
+}
+
MapLayer::MapLayer(int x, int y, int width, int height, bool isFringeLayer):
mX(x), mY(y),
mWidth(width), mHeight(height),
@@ -79,7 +107,7 @@ MapLayer::~MapLayer()
void MapLayer::setTile(int x, int y, Image *img)
{
- mTiles[x + y * mWidth] = img;
+ setTile(x + y * mWidth, img);
}
Image* MapLayer::getTile(int x, int y) const
@@ -155,6 +183,7 @@ Map::~Map()
delete_all(mLayers);
delete_all(mTilesets);
delete_all(mOverlays);
+ delete_all(mTileAnimations);
}
void Map::initializeOverlays()
@@ -216,6 +245,15 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY)
// Make sure sprites are sorted
mSprites.sort(spriteCompare);
+ //update animated tiles
+ for (std::map<int, TileAnimation*>::iterator iAni = mTileAnimations.begin();
+ iAni != mTileAnimations.end();
+ iAni++)
+ {
+ iAni->second->update();
+ }
+
+ // draw the game world
Layers::const_iterator layeri = mLayers.begin();
for (; layeri != mLayers.end(); ++layeri) {
(*layeri)->draw(graphics,
@@ -485,7 +523,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY)
while (pathX != startX || pathY != startY)
{
// Add the new path node to the start of the path list
- path.push_front(PATH_NODE(pathX, pathY));
+ path.push_front(Position(pathX, pathY));
// Find out the next parent
MetaTile *tile = getMetaTile(pathX, pathY);
@@ -516,3 +554,14 @@ void Map::initializeParticleEffects(Particle* particleEngine)
particleEngine->addEffect(i->file, i->x, i->y);
}
}
+
+TileAnimation* Map::getAnimationForGid(int gid)
+{
+ std::map<int, TileAnimation*>::iterator i = mTileAnimations.find(gid);
+ if (i == mTileAnimations.end())
+ {
+ return NULL;
+ } else {
+ return i->second;
+ }
+}