Player::Player(DisplayManager& display_manager)
{
- display_manager.add_drawable(this, LAYER_OBJECTS);
+ display_manager.add_drawable(this, LAYER_OBJECTS-1); // for tux himself
+ display_manager.add_drawable(this, LAYER_OBJECTS+1); // for the arm
init();
}
/* Shoot! */
if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER)
{
- holding_something = true;
World::current()->add_bullet(Vector(base.x, base.y + (base.height/2)),
physic.get_velocity_x(), dir);
input.old_fire = DOWN;
}
void
-Player::draw(ViewPort& viewport, int )
+Player::draw(ViewPort& viewport, int layer)
{
+ PlayerSprite* sprite;
+
+ if (size == SMALL)
+ sprite = &smalltux;
+ else if (got_power == FIRE_POWER)
+ sprite = &firetux;
+ else if (got_power == ICE_POWER)
+ sprite = &icetux;
+ else
+ sprite = &largetux;
+
Vector pos = viewport.world2screen(Vector(base.x, base.y));
+ if(layer == LAYER_OBJECTS + 1) {
+ // Draw arm overlay graphics when Tux is holding something
+ if (holding_something && physic.get_velocity_y() == 0)
+ {
+ if (dir == RIGHT)
+ sprite->grab_right->draw(pos);
+ else
+ sprite->grab_left->draw(pos);
+ }
+
+ // Draw blinking star overlay
+ if (invincible_timer.started() &&
+ (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3))
+ {
+ if (size == SMALL || duck)
+ smalltux_star->draw(pos);
+ else
+ largetux_star->draw(pos);
+ }
+
+ return;
+ }
+
if (!safe_timer.started() || (global_frame_counter % 2) == 0)
{
if (dying == DYING_SQUISHED)
}
else
{
- PlayerSprite* sprite;
-
- if (size == SMALL)
- sprite = &smalltux;
- else if (got_power == FIRE_POWER)
- sprite = &firetux;
- else if (got_power == ICE_POWER)
- sprite = &icetux;
- else
- sprite = &largetux;
-
if (duck && size != SMALL)
{
if (dir == RIGHT)
sprite->walk_left->draw(pos);
}
}
-
- // Draw arm overlay graphics when Tux is holding something
- if (holding_something && physic.get_velocity_y() == 0)
- {
- if (dir == RIGHT)
- sprite->grab_right->draw(pos);
- else
- sprite->grab_left->draw(pos);
- }
-
- // Draw blinking star overlay
- if (invincible_timer.started() &&
- (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3))
- {
- if (size == SMALL || duck)
- smalltux_star->draw(pos);
- else
- largetux_star->draw(pos);
- }
}
}
if (debug_mode)
- fillrect(base.x - scroll_x, base.y - scroll_y,
+ fillrect(base.x - viewport.get_translation().x,
+ base.y - viewport.get_translation().y,
base.width, base.height, 75,75,75, 150);
}
bool Player::is_dead()
{
+ float scroll_x =
+ World::current()->displaymanager.get_viewport().get_translation().x;
+ float scroll_y =
+ World::current()->displaymanager.get_viewport().get_translation().y;
if(base.y > screen->h + scroll_y || base.y > World::current()->get_level()->height*32 ||
base.x < scroll_x - AUTOSCROLL_DEAD_INTERVAL) // can happen in auto-scrolling
return true;
}
void
-Player::check_bounds(bool back_scrolling, bool hor_autoscroll)
+Player::check_bounds(ViewPort& viewport,
+ bool back_scrolling, bool hor_autoscroll)
{
/* Keep tux in bounds: */
if (base.x < 0)
kill(KILL);
}
- if(base.x < scroll_x && (!back_scrolling || hor_autoscroll)) // can happen if back scrolling is disabled
- base.x = scroll_x;
+ if(base.x < viewport.get_translation().x && (!back_scrolling || hor_autoscroll)) // can happen if back scrolling is disabled
+ base.x = viewport.get_translation().x;
if(hor_autoscroll)
{
- if(base.x == scroll_x)
+ if(base.x == viewport.get_translation().x)
if(issolid(base.x+32, base.y) || (size != SMALL && issolid(base.x+32, base.y+32)))
kill(KILL);
- if(base.x + base.width > scroll_x + screen->w)
- base.x = scroll_x + screen->w - base.width;
+ if(base.x + base.width > viewport.get_translation().x + screen->w)
+ base.x = viewport.get_translation().x + screen->w - base.width;
}
}