#include "screen.h"
texture_type tux_life;
-texture_type tux_right[3];
-texture_type tux_left[3];
+std::vector<texture_type> tux_right;
+std::vector<texture_type> tux_left;
+texture_type smalltux_jump_left;
+texture_type smalltux_jump_right;
+texture_type smalltux_stand_left;
+texture_type smalltux_stand_right;
+
texture_type bigtux_right[3];
texture_type bigtux_left[3];
texture_type bigtux_right_jump;
keymap.right = SDLK_RIGHT;
keymap.fire = SDLK_LCTRL;
- timer_init(&invincible_timer,true);
- timer_init(&skidding_timer,true);
- timer_init(&safe_timer,true);
- timer_init(&frame_timer,true);
+ invincible_timer.init(true);
+ skidding_timer.init(true);
+ safe_timer.init(true);
+ frame_timer.init(true);
+
physic.reset();
}
player_input_init(&input);
- timer_init(&invincible_timer,true);
- timer_init(&skidding_timer,true);
- timer_init(&safe_timer,true);
- timer_init(&frame_timer,true);
+ invincible_timer.init(true);
+ skidding_timer.init(true);
+ safe_timer.init(true);
+ frame_timer.init(true);
+
physic.reset();
}
void
-Player::action()
+Player::action(double frame_ratio)
{
bool jumped_in_solid = false;
/* Move tux: */
previous_base = base;
- physic.apply(base.x, base.y);
+ physic.apply(frame_ratio, base.x, base.y);
if (!dying)
{
physic.enable_gravity(false);
/* Reset score multiplier (for multi-hits): */
- score_multiplier = 1;
+ player_status.score_multiplier = 1;
}
if(jumped_in_solid)
if (isbrick(base.x, base.y) ||
isfullbox(base.x, base.y))
{
- trygrabdistro(base.x, base.y - 32,BOUNCE);
- trybumpbadguy(base.x, base.y - 64);
+ World::current()->trygrabdistro(base.x, base.y - 32,BOUNCE);
+ World::current()->trybumpbadguy(base.x, base.y - 64);
- trybreakbrick(base.x, base.y, size == SMALL);
+ World::current()->trybreakbrick(base.x, base.y, size == SMALL);
bumpbrick(base.x, base.y);
- tryemptybox(base.x, base.y, RIGHT);
+ World::current()->tryemptybox(base.x, base.y, RIGHT);
}
if (isbrick(base.x+ 31, base.y) ||
isfullbox(base.x+ 31, base.y))
{
- trygrabdistro(base.x+ 31, base.y - 32,BOUNCE);
- trybumpbadguy(base.x+ 31, base.y - 64);
+ World::current()->trygrabdistro(base.x+ 31, base.y - 32,BOUNCE);
+ World::current()->trybumpbadguy(base.x+ 31, base.y - 64);
if(size == BIG)
- trybreakbrick(base.x+ 31, base.y, size == SMALL);
+ World::current()->trybreakbrick(base.x+ 31, base.y, size == SMALL);
bumpbrick(base.x+ 31, base.y);
- tryemptybox(base.x+ 31, base.y, LEFT);
+ World::current()->tryemptybox(base.x+ 31, base.y, LEFT);
}
}
}
- timer_check(&safe_timer);
+ safe_timer.check();
/* ---- DONE HANDLING TUX! --- */
/* Handle invincibility timer: */
-
-
- if (get_current_music() == HERRING_MUSIC && !timer_check(&invincible_timer))
+ if (get_current_music() == HERRING_MUSIC && !invincible_timer.check())
{
/*
no, we are no more invincible
but are we in hurry ?
*/
-
- if (timer_get_left(&time_left) < TIME_WARNING)
+ // FIXME: Move this to gamesession
+ if (GameSession::current()->time_left.get_left() < TIME_WARNING)
{
/* yes, we are in hurry
stop the herring_song, prepare to play the correct
// timer_check(&skidding_timer); // disabled
/* End of level? */
-
- if (base.x >= endpos && endpos != 0)
+ if (base.x >= World::current()->get_level()->endpos
+ && World::current()->get_level()->endpos != 0)
{
- next_level = 1;
+ player_status.next_level = 1;
}
}
// skid if we're too fast
if(dir != newdir && on_ground() && fabs(physic.get_velocity_x()) > SKID_XM
- && !timer_started(&skidding_timer))
+ && !skidding_timer.started())
{
- timer_start(&skidding_timer, SKID_TIME);
+ skidding_timer.start(SKID_TIME);
play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
return;
}
if ((newdir ? (vx < 0) : (vx > 0)) && !isice(base.x, base.y + base.height) &&
- !timer_started(&skidding_timer))
+ !skidding_timer.started())
{
//vx = 0;
}
if (input.fire == DOWN && input.old_fire == UP && got_coffee)
{
- add_bullet(base.x, base.y, physic.get_velocity_x(), dir);
+ World::current()->add_bullet(base.x, base.y, physic.get_velocity_x(), dir);
}
/* (Tux): */
- if(!timer_check(&frame_timer))
+ if(!frame_timer.check())
{
- timer_start(&frame_timer,25);
+ frame_timer.start(25);
if (input.right == UP && input.left == UP)
{
frame_main = 1;
/* Grab distros: */
if (!dying)
{
- trygrabdistro(base.x, base.y, NO_BOUNCE);
- trygrabdistro(base.x+ 31, base.y, NO_BOUNCE);
+ World::current()->trygrabdistro(base.x, base.y, NO_BOUNCE);
+ World::current()->trygrabdistro(base.x+ 31, base.y, NO_BOUNCE);
- trygrabdistro(base.x, base.y + base.height, NO_BOUNCE);
- trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE);
+ World::current()->trygrabdistro(base.x, base.y + base.height, NO_BOUNCE);
+ World::current()->trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE);
if(size == BIG)
{
- trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE);
- trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE);
+ World::current()->trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE);
+ World::current()->trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE);
}
}
void
Player::draw()
{
- if (!timer_started(&safe_timer) || (global_frame_counter % 2) == 0)
+ if (!safe_timer.started() || (global_frame_counter % 2) == 0)
{
if (size == SMALL)
{
- if (timer_started(&invincible_timer))
+ if (invincible_timer.started())
{
/* Draw cape: */
if (!got_coffee)
{
- if (dir == RIGHT)
+ if (physic.get_velocity_y() != 0)
{
- texture_draw(&tux_right[frame_], base.x- scroll_x, base.y);
+ if (dir == RIGHT)
+ texture_draw(&smalltux_jump_right, base.x - scroll_x, base.y - 10);
+ else
+ texture_draw(&smalltux_jump_left, base.x - scroll_x, base.y - 10);
}
else
{
- texture_draw(&tux_left[frame_], base.x- scroll_x, base.y);
+ if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
+ {
+ if (dir == RIGHT)
+ texture_draw(&smalltux_stand_right, base.x - scroll_x, base.y - 9);
+ else
+ texture_draw(&smalltux_stand_left, base.x - scroll_x, base.y - 9);
+ }
+ else // moving
+ {
+ if (dir == RIGHT)
+ texture_draw(&tux_right[(global_frame_counter/2) % tux_right.size()],
+ base.x - scroll_x, base.y - 9);
+ else
+ texture_draw(&tux_left[(global_frame_counter/2) % tux_left.size()],
+ base.x - scroll_x, base.y - 9);
+ }
}
}
else
}
else
{
- if (timer_started(&invincible_timer))
+ if (invincible_timer.started())
{
/* Draw cape: */
if (dir == RIGHT)
{
if (!duck)
{
- if (!timer_started(&skidding_timer))
+ if (!skidding_timer.started())
{
if (!jumping || physic.get_velocity_y() > 0)
{
if (!duck)
{
- if (!timer_started(&skidding_timer))
+ if (!skidding_timer.started())
{
if (!jumping || physic.get_velocity_y() > 0)
{
/* Hurt the player if he just touched it: */
if (!pbad_c->dying && !dying &&
- !timer_started(&safe_timer) &&
+ !safe_timer.started() &&
pbad_c->mode != HELD)
{
if (pbad_c->mode == FLAT && input.fire == DOWN)
else
{
/* Hurt if you get hit by kicked laptop: */
- if (!timer_started(&invincible_timer))
+ if (!invincible_timer.started())
{
kill(SHRINK);
}
{
pbad_c->dying = DYING_FALLING;
play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
- add_score(pbad_c->base.x - scroll_x,
- pbad_c->base.y,
- 25 * score_multiplier);
+ World::current()->add_score(pbad_c->base.x - scroll_x,
+ pbad_c->base.y,
+ 25 * player_status.score_multiplier);
}
}
}
else
{
- if (!timer_started(&invincible_timer ))
+ if (!invincible_timer.started())
{
kill(SHRINK);
}
pbad_c->kill_me();
}
}
- score_multiplier++;
+ player_status.score_multiplier++;
}
break;
default:
size = SMALL;
base.height = 32;
- timer_start(&safe_timer,TUX_SAFE_TIME);
+ safe_timer.start(TUX_SAFE_TIME);
}
else
{
void
Player::keep_in_bounds()
{
+ Level* plevel = World::current()->get_level();
+
/* Keep tux in bounds: */
if (base.x< 0)
base.x= 0;
scroll_x = 0;
}
- else if (base.x> screen->w / 2 + scroll_x && scroll_x < ((current_level.width * 32) - screen->w))
+ else if (base.x > screen->w / 2 + scroll_x
+ && scroll_x < ((World::current()->get_level()->width * 32) - screen->w))
{
- /* Scroll the screen in past center: */
+ // FIXME: Scrolling needs to be handled by a seperate View
+ // class, doing it as a player huck is ugly
- scroll_x = base.x- screen->w / 2;
- /*base.x= 320 + scroll_x;*/
+ // Scroll the screen in past center:
+ scroll_x = base.x - screen->w / 2;
- if (scroll_x > ((current_level.width * 32) - screen->w))
- scroll_x = ((current_level.width * 32) - screen->w);
+ if (scroll_x > ((plevel->width * 32) - screen->w))
+ scroll_x = ((plevel->width * 32) - screen->w);
}
else if (base.x> 608 + scroll_x)
{