Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed handling of Tux movement #1680

Merged
merged 4 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/object/bumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Bumper::collision(GameObject& other, const CollisionHit& hit)
if (player)
{
float BOUNCE_DIR = left ? -BOUNCE_X : BOUNCE_X;
player->get_physic().set_velocity(BOUNCE_DIR, BOUNCE_Y);
player->get_physic().set_velocity(0.f, BOUNCE_Y);
player->sideways_push(BOUNCE_DIR);
SoundManager::current()->play(TRAMPOLINE_SOUND);
m_sprite->set_action((left ? "left-swinging" : "right-swinging"), 1);
}
Expand Down
42 changes: 30 additions & 12 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ const float MAX_GLIDE_YM = 128;
const float MAX_WALLCLING_YM = 64;
/** instant velocity when tux starts to walk */
const float WALK_SPEED = 100;
/** rate at which m_boost decreases */
const float BOOST_DECREASE_RATE = 500;
/** rate at which the speed decreases if going above maximum */
const float OVERSPEED_DECELERATION = 100;

/** multiplied by WALK_ACCELERATION to give friction */
const float NORMAL_FRICTION_MULTIPLIER = 1.5f;
Expand Down Expand Up @@ -154,6 +158,7 @@ Player::Player(PlayerStatus& player_status, const std::string& name_) :
m_on_right_wall(false),
m_in_walljump_tile(false),
m_can_walljump(false),
m_boost(0.f),
m_speedlimit(0), //no special limit
m_scripting_controller_old(nullptr),
m_jump_early_apex(false),
Expand Down Expand Up @@ -503,8 +508,16 @@ Player::update(float dt_sec)
m_physic.set_acceleration_y(-WATER_FALLOUT_FORCEBACK_STRENGTH);
}

if (m_boost != 0.f)
{
bool sign = std::signbit(m_boost);
m_boost = (sign ? -1.f : +1.f) * (std::abs(m_boost) - dt_sec * BOOST_DECREASE_RATE);
if (std::signbit(m_boost) != sign)
m_boost = 0.f;
}

// calculate movement for this frame
m_col.set_movement(m_physic.get_movement(dt_sec));
m_col.set_movement(m_physic.get_movement(dt_sec) + Vector(m_boost * dt_sec, 0));

if (m_grabbed_object != nullptr && !m_dying) {
position_grabbed_object();
Expand Down Expand Up @@ -763,11 +776,9 @@ Player::handle_horizontal_input()
ax = dirsign * WALK_ACCELERATION_X;
// limit speed
if (vx >= MAX_WALK_XM && dirsign > 0) {
vx = MAX_WALK_XM;
ax = 0;
ax = std::min(ax, -OVERSPEED_DECELERATION);
} else if (vx <= -MAX_WALK_XM && dirsign < 0) {
vx = -MAX_WALK_XM;
ax = 0;
ax = std::max(ax, OVERSPEED_DECELERATION);
}
} else {
if ( vx * dirsign < MAX_WALK_XM ) {
Expand All @@ -776,12 +787,10 @@ Player::handle_horizontal_input()
ax = dirsign * RUN_ACCELERATION_X;
}
// limit speed
if (vx >= MAX_RUN_XM + BONUS_RUN_XM *((m_player_status.bonus == AIR_BONUS) ? 1 : 0) && dirsign > 0) {
vx = MAX_RUN_XM + BONUS_RUN_XM *((m_player_status.bonus == AIR_BONUS) ? 1 : 0);
ax = 0;
} else if (vx <= -MAX_RUN_XM - BONUS_RUN_XM *((m_player_status.bonus == AIR_BONUS) ? 1 : 0) && dirsign < 0) {
vx = -MAX_RUN_XM - BONUS_RUN_XM *((m_player_status.bonus == AIR_BONUS) ? 1 : 0);
ax = 0;
if (vx >= MAX_RUN_XM + BONUS_RUN_XM *((m_player_status.bonus == AIR_BONUS) ? 1 : 0)) {
ax = std::min(ax, -OVERSPEED_DECELERATION);
} else if (vx <= -MAX_RUN_XM - BONUS_RUN_XM *((m_player_status.bonus == AIR_BONUS) ? 1 : 0)) {
ax = std::max(ax, OVERSPEED_DECELERATION);
}
}

Expand Down Expand Up @@ -1029,7 +1038,7 @@ Player::handle_vertical_input()
if (m_controller->pressed(Control::JUMP) && m_can_walljump && !m_backflipping)
{
SoundManager::current()->play((is_big()) ? "sounds/bigjump.wav" : "sounds/jump.wav");
m_physic.set_velocity(m_on_left_wall ? 400.f : -400.f, -520.f);
m_physic.set_velocity(m_on_left_wall ? 450.f : -450.f, -520.f);
}

m_physic.set_acceleration_y(0);
Expand Down Expand Up @@ -1747,6 +1756,9 @@ Player::collision_solid(const CollisionHit& hit)
kill(false);
}
}

if ((hit.left && m_boost < 0.f) || (hit.right && m_boost > 0.f))
m_boost = 0.f;
}

HitResponse
Expand Down Expand Up @@ -2127,4 +2139,10 @@ Player::has_grabbed(const std::string& object_name) const
return false;
}

void
Player::sideways_push(float delta)
{
m_boost = delta;
}

/* EOF */
4 changes: 4 additions & 0 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ class Player final : public MovingObject,
void position_grabbed_object();
void try_grab();

/** Boosts Tux in a certain direction, sideways. Useful for bumpers/walljumping. */
void sideways_push(float delta);

private:
void handle_input();
void handle_input_ghost(); /**< input handling while in ghost mode */
Expand Down Expand Up @@ -238,6 +241,7 @@ class Player final : public MovingObject,
bool m_on_right_wall;
bool m_in_walljump_tile;
bool m_can_walljump;
float m_boost;
float m_speedlimit;
const Controller* m_scripting_controller_old; /**< Saves the old controller while the scripting_controller is used */
bool m_jump_early_apex;
Expand Down