static const float IDLE_TIME = 2.5f;
/** acceleration in horizontal direction when walking
- * (all acceleratiosn are in pixel/s^2) */
+ * (all accelerations are in pixel/s^2) */
static const float WALK_ACCELERATION_X = 300;
/** acceleration in horizontal direction when running */
static const float RUN_ACCELERATION_X = 400;
static const float SKID_TIME = .3f;
/** maximum walk velocity (pixel/s) */
static const float MAX_WALK_XM = 230;
-/** maximum run velcoity (pixel/s) */
+/** maximum run velocity (pixel/s) */
static const float MAX_RUN_XM = 320;
/** maximum horizontal climb velocity */
static const float MAX_CLIMB_XM = 48;
/** if Tux cannot unduck for this long, he will get hurt */
static const float UNDUCK_HURT_TIME = 0.25f;
+/** gravity is higher after the jump key is released before
+ the apex of the jump is reached */
+static const float JUMP_EARLY_APEX_FACTOR = 3.0;
namespace{
bool no_water = true;
sound_manager->preload("sounds/hurt.wav");
sound_manager->preload("sounds/skid.wav");
sound_manager->preload("sounds/flip.wav");
- sound_manager->preload("sounds/invincible.wav");
+ sound_manager->preload("sounds/invincible_start.ogg");
sound_manager->preload("sounds/splash.ogg");
- sound_manager->preload("sounds/shoot.wav");
init();
}
dead = false;
dying = false;
- peeking = AUTO;
+ peekingX = AUTO;
+ peekingY = AUTO;
last_ground_y = 0;
fall_mode = ON_GROUND;
jumping = false;
+ jump_early_apex = false;
can_jump = true;
wants_buttjump = false;
does_buttjump = false;
Vector paccel = Vector(0, 0);
// draw bright sparkle when there is lots of time left, dark sparkle when invincibility is about to end
if (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING) {
- // make every other a longer sparkle to make trail a bit fuzzy
- if (size_t(game_time*20)%2) {
- Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
- } else {
- Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
- }
+ // make every other a longer sparkle to make trail a bit fuzzy
+ if (size_t(game_time*20)%2) {
+ Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "small", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+ } else {
+ Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "medium", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
+ }
} else {
Sector::current()->add_object(new SpriteParticle("images/objects/particles/sparkle.sprite", "dark", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS+1+5));
}
}
void
+Player::early_jump_apex() {
+ if(jump_early_apex) {
+ return;
+ }
+ jump_early_apex = true;
+ physic.set_gravity(physic.get_gravity() * JUMP_EARLY_APEX_FACTOR);
+};
+
+void
+Player::do_jump_apex() {
+ if(!jump_early_apex) {
+ return;
+ }
+ jump_early_apex = false;
+ physic.set_gravity(physic.get_gravity() / JUMP_EARLY_APEX_FACTOR);
+}
+
+void
Player::handle_vertical_input()
{
// Press jump key
else if(!controller->hold(Controller::JUMP)) {
if (!backflipping && jumping && physic.get_velocity_y() < 0) {
jumping = false;
- physic.set_velocity_y(0);
+ early_jump_apex();
}
}
+ if(jump_early_apex && physic.get_velocity_y() >= 0) {
+ do_jump_apex();
+ }
+
/* In case the player has pressed Down while in a certain range of air,
enable butt jump action */
if (controller->hold(Controller::DOWN) && !duck && is_big() && !on_ground()) {
/* Peeking */
if( controller->released( Controller::PEEK_LEFT ) ) {
- peeking = AUTO;
+ peekingX = AUTO;
}
if( controller->released( Controller::PEEK_RIGHT ) ) {
- peeking = AUTO;
+ peekingX = AUTO;
}
- if( controller->released( Controller::UP ) ) {
- peeking = AUTO;
+ if( controller->released( Controller::PEEK_UP ) ) {
+ peekingY = AUTO;
}
- if( controller->released( Controller::DOWN ) ) {
- peeking = AUTO;
+ if( controller->released( Controller::PEEK_DOWN ) ) {
+ peekingY = AUTO;
}
if( controller->pressed( Controller::PEEK_LEFT ) ) {
- peeking = LEFT;
+ peekingX = LEFT;
}
if( controller->pressed( Controller::PEEK_RIGHT ) ) {
- peeking = RIGHT;
+ peekingX = RIGHT;
}
- if( controller->pressed( Controller::UP ) ) {
- peeking = UP;
- }
- if( controller->pressed( Controller::DOWN ) ) {
- peeking = DOWN;
+ if(!backflipping && !jumping && on_ground()) {
+ if( controller->pressed( Controller::PEEK_UP ) ) {
+ peekingY = UP;
+ } else if( controller->pressed( Controller::PEEK_DOWN ) ) {
+ peekingY = DOWN;
+ }
}
/* Handle horizontal movement: */
void
Player::make_invincible()
{
- sound_manager->play("sounds/invincible.wav");
+ sound_manager->play("sounds/invincible_start.ogg");
invincible_timer.start(TUX_INVINCIBLE_TIME);
Sector::current()->play_music(HERRING_MUSIC);
}
safe_timer.start(TUX_SAFE_TIME /* + GROWING_TIME */);
adjust_height(30.8f);
duck = false;
+ backflipping = false;
set_bonus(NO_BONUS, true);
} else if(player_status->bonus == NO_BONUS) {
safe_timer.start(TUX_SAFE_TIME);