-
- delete *i;
- i = gameobjects.erase(i);
- } else {
- ++i;
- }
- }
-}
-
-/* the space that it takes for the screen to start scrolling, regarding */
-/* screen bounds (in pixels) */
-// should be higher than screen->w/2 (400)
-#define X_SPACE (500-16)
-// should be less than screen->h/2 (300)
-#define Y_SPACE 250
-
-// the time it takes to move the camera (in ms)
-#define CHANGE_DIR_SCROLL_SPEED 2000
-
-/* This functions takes cares of the scrolling */
-void World::scrolling(double frame_ratio)
-{
- /* Y-axis scrolling */
-
- float tux_pos_y = tux->base.y + (tux->base.height/2);
-
- if(level->height > VISIBLE_TILES_Y-1 && !tux->dying)
- {
- if (scroll_y < tux_pos_y - (screen->h - Y_SPACE))
- scroll_y = tux_pos_y - (screen->h - Y_SPACE);
- else if (scroll_y > tux_pos_y - Y_SPACE)
- scroll_y = tux_pos_y - Y_SPACE;
- }
-
- // this code prevent the screen to scroll before the start or after the level's end
- if(scroll_y > level->height * 32 - screen->h)
- scroll_y = level->height * 32 - screen->h;
- if(scroll_y < 0)
- scroll_y = 0;
-
- /* X-axis scrolling */
-
- /* Auto scrolling */
- if(level->hor_autoscroll_speed)
- {
- scroll_x += level->hor_autoscroll_speed * frame_ratio;
- return;
- }
-
-
- /* Horizontal backscrolling */
- float tux_pos_x = tux->base.x + (tux->base.width/2);
-
- if(tux->old_dir != tux->dir && level->back_scrolling)
- scrolling_timer.start(CHANGE_DIR_SCROLL_SPEED);
-
- bool right = false;
- bool left = false;
- if (tux->physic.get_velocity_x() > 0)
- right = true;
- else if (tux->physic.get_velocity_x() < 0)
- left = true;
- else
- {
- if (tux->dir == RIGHT)
- right = true;
- else
- left = true;
- }
-
- if(scrolling_timer.check())
- {
- float final_scroll_x;
- float constant1;
- float constant2;
- if (right)
- final_scroll_x = tux_pos_x - (screen->w - X_SPACE);
- else
- final_scroll_x = tux_pos_x - X_SPACE;
-
- if((tux->physic.get_velocity_x() > 0 && tux->dir == RIGHT)
- || (tux->physic.get_velocity_x() < 0 && tux->dir == LEFT))
- {
- constant1 = 1.0;
- constant2 = .4;
- }
- else
- {
- constant1 = 0.;
- constant2 = 0.;
- }
-
- float number = 2.5/(frame_ratio * CHANGE_DIR_SCROLL_SPEED/1000)*exp((CHANGE_DIR_SCROLL_SPEED-scrolling_timer.get_left())/1400.);
- if(left) number *= -1.;
-
- scroll_x += number
- + constant1 * tux->physic.get_velocity_x() * frame_ratio
- + constant2 * tux->physic.get_acceleration_x() * frame_ratio * frame_ratio;
-
- if ((right && final_scroll_x - scroll_x < 0) || (left && final_scroll_x - scroll_x > 0))
- scroll_x = final_scroll_x;
-