-
-
Notifications
You must be signed in to change notification settings - Fork 521
Wind and swimming updates #2793
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
Changes from all commits
df12c3e
b640ad0
61a9936
209e2bb
3a20c79
f27c2dd
84c0105
ae1cfe9
0a1a6e6
b56b8c1
8c431b7
aefe237
d586bf7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,10 @@ void | |
Dart::active_update(float dt_sec) | ||
{ | ||
BadGuy::active_update(dt_sec); | ||
|
||
m_physic.set_velocity_y(m_physic.get_velocity_y() * 0.9f); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should depend on dt_sec. |
||
m_col.set_movement(m_physic.get_movement(dt_sec)); | ||
|
||
sound_source->set_position(get_pos()); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#include "badguy/kamikazesnowball.hpp" | ||
|
||
#include "audio/sound_manager.hpp" | ||
#include "supertux/direction.hpp" | ||
|
||
namespace{ | ||
static const float KAMIKAZE_SPEED = 200; | ||
|
@@ -39,6 +40,14 @@ KamikazeSnowball::initialize() | |
set_action(m_dir); | ||
} | ||
|
||
void | ||
KamikazeSnowball::active_update(float dt_sec) { | ||
m_physic.set_velocity_y(m_physic.get_velocity_y() * 0.9f); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should depend on dt_sec. |
||
m_col.set_movement(m_physic.get_movement(dt_sec)); | ||
|
||
BadGuy::active_update(dt_sec); | ||
} | ||
|
||
bool | ||
KamikazeSnowball::collision_squished(MovingObject& object) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,33 @@ inline Vector at_angle(Vector const& v, float angle) | |
return vec2_from_polar(glm::length(v), angle); | ||
} | ||
|
||
// Move vector towards a new vector by a scalar delta. | ||
inline Vector move_towards(Vector const& from, Vector const& to, float d) { | ||
// Based on Godot's implementation | ||
Vector vd = to - from; | ||
float len = vd.length(); | ||
return len <= d ? to : from + vd / len * d; | ||
} | ||
|
||
// Change a velocity vector towards another, but do not change a component towards zero unless their signs are opposite. | ||
inline Vector push_to_velocity(Vector const& from, Vector const& to, float d) { | ||
if (d == 0.f) return from; | ||
|
||
Vector diff = glm::normalize(to - from) * d; | ||
Vector result = from; | ||
|
||
if (to.x > 0 && from.x < to.x) | ||
result.x = std::min(from.x + diff.x, to.x); | ||
if (to.x < 0 && from.x > to.x) | ||
result.x = std::max(from.x + diff.x, to.x); | ||
if (to.y > 0 && from.y < to.y) | ||
result.y = std::min(from.y + diff.y, to.y); | ||
if (to.y < 0 && from.y > to.y) | ||
result.y = std::max(from.y + diff.y, to.y); | ||
|
||
return result; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks pretty much like:
|
||
} | ||
|
||
} // namespace math | ||
|
||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,10 @@ | |
|
||
#include "object/player.hpp" | ||
|
||
#include <algorithm> | ||
|
||
#include <glm/geometric.hpp> | ||
|
||
#include <simplesquirrel/class.hpp> | ||
#include <simplesquirrel/vm.hpp> | ||
|
||
|
@@ -27,6 +31,7 @@ | |
#include "editor/editor.hpp" | ||
#include "math/util.hpp" | ||
#include "math/random.hpp" | ||
#include "math/vector.hpp" | ||
#include "object/brick.hpp" | ||
#include "object/bullet.hpp" | ||
#include "object/camera.hpp" | ||
|
@@ -40,6 +45,7 @@ | |
#include "sprite/sprite.hpp" | ||
#include "sprite/sprite_manager.hpp" | ||
#include "supertux/constants.hpp" | ||
#include "supertux/direction.hpp" | ||
#include "supertux/game_session.hpp" | ||
#include "supertux/gameconfig.hpp" | ||
#include "supertux/resources.hpp" | ||
|
@@ -379,6 +385,11 @@ Player::trigger_sequence(Sequence seq, const SequenceData* data) | |
void | ||
Player::update(float dt_sec) | ||
{ | ||
if (m_col.m_colliding_wind.empty()) { | ||
m_physic.set_wind_acceleration(0); | ||
m_physic.set_wind_velocity(0, 0); | ||
} | ||
|
||
if (is_dead() || Sector::get().get_object_count<Player>() == 1) | ||
{ | ||
m_tag_timer.stop(); | ||
|
@@ -1173,6 +1184,11 @@ Player::apply_friction() | |
friction *= (ICE_FRICTION_MULTIPLIER*(m_sliding ? 4.f : m_stone ? 5.f : 1.f)); | ||
else | ||
friction *= (NORMAL_FRICTION_MULTIPLIER*(m_sliding ? 0.8f : m_stone ? 0.4f : 1.f)); | ||
|
||
// Air friction does not make sense when the air is moving with you! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Air drag depends on the object speed with respect to the air. If the velocity of the air is equal to the velocity of Tux, then indeed, there is no drag. However, when they have both different velocities, there is drag. That is actually the reason why wind blows object away. However, it looks like the term friction stands for the friction between Tux and the ground. In such a case, the friction is one force and the air drag is another force. |
||
if (!is_on_ground && !m_col.m_colliding_wind.empty() && std::abs(m_physic.get_wind_velocity_x()) > 0.f) | ||
friction = 0.f; | ||
|
||
if (velx < 0) { | ||
m_physic.set_acceleration_x(friction); | ||
} else if (velx > 0) { | ||
|
@@ -1263,7 +1279,11 @@ Player::handle_horizontal_input() | |
// let's skid! | ||
if (fabsf(vx)>SKID_XM && !m_skidding_timer.started()) { | ||
m_skidding_timer.start(SKID_TIME); | ||
SoundManager::current()->play("sounds/skid.wav", get_pos()); | ||
|
||
// skidding sound disabled in wind because it becomes too repetitive | ||
if (m_col.m_colliding_wind.empty()) | ||
SoundManager::current()->play("sounds/skid.wav", get_pos()); | ||
|
||
// dust some particles | ||
Sector::get().add<Particles>( | ||
Vector(m_dir == Direction::LEFT ? m_col.m_bbox.get_right() : m_col.m_bbox.get_left(), m_col.m_bbox.get_bottom()), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be calculated using your push_to_velocity function?