Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions src/object/bounce_jump_state.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SuperTux
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

#include "object/bounce_jump_state.hpp"

void
clear_player_bounce_state(PlayerBounceState& state)
{
state.jumping = false;
state.slidejump_falling = false;
state.jump_early_apex = false;
state.gravity_modifier = 1.0f;
}
18 changes: 18 additions & 0 deletions src/object/bounce_jump_state.hpp
Comment thread
Mour4z marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SuperTux
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

#pragma once

struct PlayerBounceState
{
bool jumping;
bool slidejump_falling;
bool jump_early_apex;
float gravity_modifier;
};

void clear_player_bounce_state(PlayerBounceState& state);
19 changes: 19 additions & 0 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "object/brick.hpp"
#include "object/bullet.hpp"
#include "object/camera.hpp"
#include "object/bounce_jump_state.hpp"
#include "object/display_effect.hpp"
#include "object/falling_coin.hpp"
#include "object/key.hpp"
Expand Down Expand Up @@ -1459,6 +1460,24 @@ Player::do_jump(float yspeed) {
}
}

void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a simple little comment (not too large) above this function explaining the original problem too, this way its justification makes sense in the future for future readers.

Player::clear_jump_state_for_bounce()
{
PlayerBounceState state{
m_jumping,
m_is_slidejump_falling,
m_jump_early_apex,
m_physic.get_gravity_modifier()
};

clear_player_bounce_state(state);

m_jumping = state.jumping;
m_is_slidejump_falling = state.slidejump_falling;
m_jump_early_apex = state.jump_early_apex;
m_physic.set_gravity_modifier(state.gravity_modifier);
Comment thread
Mour4z marked this conversation as resolved.
Outdated
}

void
Player::early_jump_apex()
{
Expand Down
2 changes: 2 additions & 0 deletions src/object/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ class Player final : public MovingSprite
*/
void do_jump(float yspeed);

void clear_jump_state_for_bounce();

/** Adds velocity to the player (be careful when using this) */
void add_velocity(const Vector& velocity);

Expand Down
2 changes: 2 additions & 0 deletions src/object/rusty_trampoline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ RustyTrampoline::collision(MovingObject& other, const CollisionHit& hit)
float vy = player->get_physic().get_velocity_y();
//player is falling down on trampoline
if (hit.top && vy >= 0) {
player->clear_jump_state_for_bounce();

if (player->get_controller().hold(Control::JUMP)) {
vy = VY_TRIGGER;
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/object/trampoline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Trampoline::collision(MovingObject& other, const CollisionHit& hit)
//player is falling down on trampoline
if (hit.top && vy >= 0)
{
player->clear_jump_state_for_bounce();

if (!(player->get_status().bonus[player->get_id()] == BONUS_AIR))
{
if (player->get_controller().hold(Control::JUMP))
Expand Down
39 changes: 0 additions & 39 deletions tests/unit/CMakeLists.txt
Comment thread
Mour4z marked this conversation as resolved.

This file was deleted.