summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-01-06 14:33:20 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-01-06 16:40:46 +0100
commit6b60673b0805fbab747924d1a0b6d9c66fc96f64 (patch)
treee40cc55a4d952bfb9bc89a41c3205c1d7bd90616 /src/map.cpp
parent090b4893a57a1b7e9c83f7db043843d35016fcff (diff)
downloadmana-6b60673b0805fbab747924d1a0b6d9c66fc96f64.tar.gz
mana-6b60673b0805fbab747924d1a0b6d9c66fc96f64.tar.bz2
mana-6b60673b0805fbab747924d1a0b6d9c66fc96f64.tar.xz
mana-6b60673b0805fbab747924d1a0b6d9c66fc96f64.zip
Added support for animated tiles.
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 6170adef..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,
@@ -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;
+ }
+}