diff options
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 87 |
1 files changed, 53 insertions, 34 deletions
diff --git a/src/map.cpp b/src/map.cpp index 6eec4865..463a8c8e 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -171,54 +171,73 @@ Map::drawOverlay(Graphics *graphics, float scrollX, float scrollY) { std::list<AmbientOverlay>::iterator i; + static int lastTick = tick_time; + + // Avoid freaking out when tick_time overflows + if (tick_time < lastTick) + { + lastTick = tick_time; + } + if (mLastScrollX == 0.0f && mLastScrollY == 0.0f) { + // first call - initialisation mLastScrollX = scrollX; mLastScrollY = scrollY; } - for (i = mOverlays.begin(); i != mOverlays.end(); i++) + //update Overlays + while (lastTick < tick_time) { - - if ((*i).image != NULL) + for (i = mOverlays.begin(); i != mOverlays.end(); i++) { - //apply self scrolling - (*i).scrollX -= (*i).scrollSpeedX; - (*i).scrollY -= (*i).scrollSpeedY; + 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; + //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(); + //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; + lastTick++; } - mLastScrollX = scrollX; - mLastScrollY = scrollY; + //draw overlays + for (i = mOverlays.begin(); i != mOverlays.end(); i++) + { + if ((*i).image != NULL) + { + graphics->drawImagePattern ( (*i).image, + 0 - (int)(*i).scrollX, + 0 - (int)(*i).scrollY, + graphics->getWidth() + (int)(*i).scrollX, + graphics->getHeight() + (int)(*i).scrollY + ); + }; + }; } void |