diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2006-08-21 16:06:50 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2006-08-21 16:06:50 +0000 |
commit | 7eef0aaedefc5d3c73301bcb02834e165124c7e6 (patch) | |
tree | 3ac39dbb0bc92db2cdf9d90db700662627f6d8df /src/map.cpp | |
parent | e8c3de13e9f850498b9ab2dfaca758c851566d3a (diff) | |
download | mana-7eef0aaedefc5d3c73301bcb02834e165124c7e6.tar.gz mana-7eef0aaedefc5d3c73301bcb02834e165124c7e6.tar.bz2 mana-7eef0aaedefc5d3c73301bcb02834e165124c7e6.tar.xz mana-7eef0aaedefc5d3c73301bcb02834e165124c7e6.zip |
added overlays and smooth scrolling. (someone who knows what he is doing has to create the makefiles for the unix users)
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 86 |
1 files changed, 83 insertions, 3 deletions
diff --git a/src/map.cpp b/src/map.cpp index 531b0f15..6eec4865 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -60,7 +60,8 @@ struct Location Map::Map(int width, int height, int tileWidth, int tileHeight): mWidth(width), mHeight(height), mTileWidth(tileWidth), mTileHeight(tileHeight), - mOnClosedList(1), mOnOpenList(2) + mOnClosedList(1), mOnOpenList(2), + mLastScrollX(0.0f), mLastScrollY(0.0f) { mMetaTiles = new MetaTile[mWidth * mHeight]; mTiles = new Image*[mWidth * mHeight * 3]; @@ -68,12 +69,18 @@ Map::Map(int width, int height, int tileWidth, int tileHeight): Map::~Map() { + // clean up map data delete[] mMetaTiles; delete[] mTiles; - - // Clean up tilesets + // clean up tilesets for_each(mTilesets.begin(), mTilesets.end(), make_dtor(mTilesets)); mTilesets.clear(); + // clean up overlays + std::list<AmbientOverlay>::iterator i; + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + (*i).image->decRef(); + } } void @@ -160,6 +167,79 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) } void +Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY) +{ + std::list<AmbientOverlay>::iterator i; + + if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) + { + mLastScrollX = scrollX; + mLastScrollY = scrollY; + } + + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + + if ((*i).image != NULL) + { + //apply self scrolling + (*i).scrollX -= (*i).scrollSpeedX; + (*i).scrollY -= (*i).scrollSpeedY; + + //apply parallaxing + (*i).scrollX += (scrollX - mLastScrollX) * (*i).parallax; + (*i).scrollY += (scrollY - mLastScrollY) * (*i).parallax; + + //keep the image pattern on the screen + while ((*i).scrollX > (*i).image->getWidth()) + { + (*i).scrollX -= (*i).image->getWidth(); + } + while ((*i).scrollY > (*i).image->getHeight()) + { + (*i).scrollY -= (*i).image->getHeight(); + } + while ((*i).scrollX < 0) + { + (*i).scrollX += (*i).image->getWidth(); + } + while ((*i).scrollY < 0) + { + (*i).scrollY += (*i).image->getHeight(); + } + + graphics->drawImagePattern ( (*i).image, + 0 - (int)(*i).scrollX, + 0 - (int)(*i).scrollY, + graphics->getWidth() + (int)(*i).scrollX, + graphics->getHeight() + (int)(*i).scrollY + ); + } + } + + mLastScrollX = scrollX; + mLastScrollY = scrollY; +} + +void +Map::setOverlay(Image *image, float speedX, float speedY, float parallax) +{ + if (image != NULL) + { + AmbientOverlay newOverlay; + + newOverlay.image = image; + newOverlay.parallax = parallax; + newOverlay.scrollSpeedX = speedX; + newOverlay.scrollSpeedY = speedY; + newOverlay.scrollX = 0; + newOverlay.scrollY = 0; + + mOverlays.push_back(newOverlay); + } +} + +void Map::setTileWithGid(int x, int y, int layer, int gid) { if (layer == 3) |