summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp43
-rw-r--r--src/map.cpp87
-rw-r--r--src/map.h2
3 files changed, 83 insertions, 49 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index 9a93b03e..a80351d4 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -161,6 +161,14 @@ void Engine::logic()
void Engine::draw(Graphics *graphics)
{
+ static int lastTick = tick_time;
+
+ // Avoid freaking out when tick_time overflows
+ if (tick_time < lastTick)
+ {
+ lastTick = tick_time;
+ }
+
// calculate viewpoint
int midTileX = graphics->getWidth() / 32 / 2;
int midTileY = graphics->getHeight() / 32 / 2;
@@ -174,22 +182,27 @@ void Engine::draw(Graphics *graphics)
if (scrollLaziness < 1)
scrollLaziness = 1; //avoids division by zero
- if (player_x > view_x + scrollRadius)
- {
- view_x += (player_x - view_x - scrollRadius) / scrollLaziness;
- };
- if (player_x < view_x - scrollRadius)
- {
- view_x += (player_x - view_x + scrollRadius) / scrollLaziness;
- };
- if (player_y > view_y + scrollRadius)
- {
- view_y += (player_y - view_y - scrollRadius) / scrollLaziness;
- };
- if (player_y < view_y - scrollRadius)
+ //apply lazy scrolling
+ while (lastTick < tick_time)
{
- view_y += (player_y - view_y + scrollRadius) / scrollLaziness;
- };
+ if (player_x > view_x + scrollRadius)
+ {
+ view_x += (player_x - view_x - scrollRadius) / scrollLaziness;
+ }
+ if (player_x < view_x - scrollRadius)
+ {
+ view_x += (player_x - view_x + scrollRadius) / scrollLaziness;
+ }
+ if (player_y > view_y + scrollRadius)
+ {
+ view_y += (player_y - view_y - scrollRadius) / scrollLaziness;
+ }
+ if (player_y < view_y - scrollRadius)
+ {
+ view_y += (player_y - view_y + scrollRadius) / scrollLaziness;
+ }
+ lastTick++;
+ }
//auto center when player is off screen
if ( player_x - view_x > graphics->getWidth() / 2
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
diff --git a/src/map.h b/src/map.h
index 51756ee7..46bf4c23 100644
--- a/src/map.h
+++ b/src/map.h
@@ -41,6 +41,8 @@ typedef Tilesets::iterator TilesetIterator;
typedef std::list<Sprite*> Sprites;
typedef Sprites::iterator SpriteIterator;
+extern volatile int tick_time;
+
/**
* A meta tile stores additional information about a location on a tile map.
* This is information that doesn't need to be repeated for each tile in each