#include "sprite.h"
#include "screen.h"
+#define AUTOSCROLL_DEAD_INTERVAL 300
+
Surface* tux_life;
Sprite* smalltux_gameover;
base.ym = 0;
previous_base = old_base = base;
dir = RIGHT;
+ old_dir = dir;
duck = false;
dying = DYING_NOT;
base.x += frame_ratio * WALK_SPEED * (dir ? 1 : -1);
previous_base = old_base = base;
}
- keep_in_bounds();
+ check_bounds();
// Land:
if (!on_ground())
float dirsign = 0;
if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
+ old_dir = dir;
dir = LEFT;
dirsign = -1;
} else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
+ old_dir = dir;
dir = RIGHT;
dirsign = 1;
}
if (on_ground())
{
// jump higher if we are running
- if (physic.get_velocity_x() > MAX_WALK_XM)
+ if (fabs(physic.get_velocity_x()) > MAX_WALK_XM)
physic.set_velocity_y(5.8);
else
physic.set_velocity_y(5.2);
bool Player::is_dead()
{
- if(base.y > screen->h)
+ if(base.y > screen->h || base.x < scroll_x - AUTOSCROLL_DEAD_INTERVAL) // last condition can happen in auto-scrolling
return true;
else
return false;
}
void
-Player::keep_in_bounds()
+Player::check_bounds()
{
- Level* plevel = World::current()->get_level();
-
/* Keep tux in bounds: */
if (base.x < 0)
{ // Lock Tux to the size of the level, so that he doesn't fall of
// on the left side
base.x = 0;
}
- else if (base.x < scroll_x)
- {
- base.x = scroll_x;
- }
/* Keep in-bounds, vertically: */
if (base.y > screen->h)
kill(KILL);
}
- int scroll_threshold = screen->w/2 - 80;
- if (debug_mode)
- {
- scroll_x += screen->w/2;
- // Backscrolling for debug mode
- if (scroll_x < base.x - 80)
- scroll_x = base.x - 80;
- else if (scroll_x > base.x + 80)
- scroll_x = base.x + 80;
- scroll_x -= screen->w/2;
-
- if(scroll_x < 0)
- scroll_x = 0;
- }
- else
- {
- if (base.x > scroll_threshold + scroll_x
- && scroll_x < ((World::current()->get_level()->width * 32) - screen->w))
- {
- // FIXME: Scrolling needs to be handled by a seperate View
- // class, doing it as a player huck is ugly
-
- // Scroll the screen in past center:
- scroll_x = base.x - scroll_threshold;
-
- // Lock the scrolling to the levelsize, so that we don't
- // scroll over the right border
- if (scroll_x > 32 * plevel->width - screen->w)
- scroll_x = 32 * plevel->width - screen->w;
- }
- }
+ if(base.x < scroll_x) // can happen if back scrolling is disabled
+ base.x = scroll_x;
+
+ if(base.x == scroll_x)
+ if(issolid(base.x, base.y) || issolid(base.x, base.y+32))
+ kill(KILL);
+
+ if(base.x + base.width > scroll_x + screen->w)
+ base.x = scroll_x + screen->w - base.width;
+
+
}
// EOF //