summaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-01-06 14:33:20 +0100
committerIra Rice <irarice@gmail.com>2009-01-06 10:48:20 -0700
commit394989d94081cbc462ba7d567fc88d0c4dff8134 (patch)
tree49c43dd2bcceb0cf204b13e7ed88132623910d2c /src/map.cpp
parent3e40c30cdd3a7b3942131fc8b72b268aa0e98f77 (diff)
downloadMana-394989d94081cbc462ba7d567fc88d0c4dff8134.tar.gz
Mana-394989d94081cbc462ba7d567fc88d0c4dff8134.tar.bz2
Mana-394989d94081cbc462ba7d567fc88d0c4dff8134.tar.xz
Mana-394989d94081cbc462ba7d567fc88d0c4dff8134.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 217a14e3..5d36d772 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
@@ -156,6 +184,7 @@ Map::~Map()
delete_all(mLayers);
delete_all(mTilesets);
delete_all(mOverlays);
+ delete_all(mTileAnimations);
}
void Map::initializeOverlays()
@@ -217,6 +246,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)
{
@@ -514,3 +552,14 @@ void Map::initializeParticleEffects(Particle* particleEngine)
}
}
}
+
+TileAnimation* Map::getAnimationForGid(int gid)
+{
+ std::map<int, TileAnimation*>::iterator i = mTileAnimations.find(gid);
+ if (i == mTileAnimations.end())
+ {
+ return NULL;
+ } else {
+ return i->second;
+ }
+}