-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
Wind: Affect Tux on ground + Fancy Particles Option #1493
Changes from 9 commits
bc91e06
06c60dc
f1ec635
b62d04c
cfe4d7d
57d42da
8abc971
a4b8062
276fd65
bbf32ed
c5383de
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(supertux-sprite | ||
(action | ||
(name "default") | ||
(hitbox 0 0 63 3) | ||
(loops 1) | ||
(fps 15) | ||
(images "wind3.png" | ||
"wind2.png" | ||
"wind.png" | ||
"wind.png" | ||
"wind2.png" | ||
"wind3.png") | ||
) | ||
(action | ||
(name "flip") | ||
(hitbox 0 0 3 63) | ||
(loops 1) | ||
(fps 15) | ||
(images "windup3.png" | ||
"windup2.png" | ||
"windup.png" | ||
"windup.png" | ||
"windup2.png" | ||
"windup3.png") | ||
) | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
#include "math/random.hpp" | ||
#include "object/particles.hpp" | ||
#include "object/player.hpp" | ||
#include "object/sprite_particle.hpp" | ||
#include "sprite/sprite.hpp" | ||
#include "sprite/sprite_manager.hpp" | ||
#include "supertux/sector.hpp" | ||
#include "util/reader_mapping.hpp" | ||
#include "video/drawing_context.hpp" | ||
|
@@ -33,7 +36,8 @@ Wind::Wind(const ReaderMapping& reader) : | |
acceleration(), | ||
new_size(), | ||
dt_sec(0), | ||
affects_badguys() | ||
affects_badguys(), | ||
fancy_wind() | ||
{ | ||
float w,h; | ||
reader.get("x", m_col.m_bbox.get_left(), 0.0f); | ||
|
@@ -50,6 +54,8 @@ Wind::Wind(const ReaderMapping& reader) : | |
reader.get("acceleration", acceleration, 100.0f); | ||
|
||
reader.get("affects-badguys", affects_badguys, false); | ||
|
||
reader.get("fancy-wind", fancy_wind, false); | ||
|
||
set_group(COLGROUP_TOUCHABLE); | ||
} | ||
|
@@ -69,8 +75,9 @@ Wind::get_settings() | |
result.add_float(_("Acceleration"), &acceleration, "acceleration"); | ||
result.add_bool(_("Blowing"), &blowing, "blowing", true); | ||
result.add_bool(_("Affects Badguys"), &affects_badguys, "affects-badguys", false); | ||
result.add_bool(_("Fancy Particles"), &fancy_wind, "fancy-wind", false); | ||
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. Not sure about what others might think, but I consider the name "Fancy Particles" to not be verbose enough. |
||
|
||
result.reorder({"blowing", "speed-x", "speed-y", "acceleration", "affects-badguys", "region", "name", "x", "y"}); | ||
result.reorder({"blowing", "speed-x", "speed-y", "acceleration", "affects-badguys", "fancy-wind", "region", "name", "x", "y"}); | ||
|
||
return result; | ||
} | ||
|
@@ -83,13 +90,22 @@ Wind::update(float dt_sec_) | |
if (!blowing) return; | ||
if (m_col.m_bbox.get_width() <= 16 || m_col.m_bbox.get_height() <= 16) return; | ||
|
||
// TODO: nicer, configurable particles for wind? | ||
if (graphicsRandom.rand(0, 100) < 20) { | ||
Vector ppos = Vector(graphicsRandom.randf(m_col.m_bbox.get_left()+8, m_col.m_bbox.get_right()-8), graphicsRandom.randf(m_col.m_bbox.get_top()+8, m_col.m_bbox.get_bottom()-8)); | ||
Vector pspeed = Vector(graphicsRandom.randf(speed.x-20, speed.x+20), graphicsRandom.randf(speed.y-20, speed.y+20)); | ||
|
||
// TODO: Rotate sprite rather than just use 2 different actions | ||
// Approx. 1 particle per tile | ||
if (graphicsRandom.randf(0.f, 100.f) < (m_col.m_bbox.get_width() / 32.f) * (m_col.m_bbox.get_height() / 32.f)) | ||
{ | ||
// emit a particle | ||
Vector ppos = Vector(graphicsRandom.randf(m_col.m_bbox.get_left()+8, m_col.m_bbox.get_right()-8), graphicsRandom.randf(m_col.m_bbox.get_top()+8, m_col.m_bbox.get_bottom()-8)); | ||
Vector pspeed = Vector(speed.x, speed.y); | ||
Sector::get().add<Particles>(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f, | ||
LAYER_BACKGROUNDTILES+1); | ||
if (fancy_wind) | ||
{ | ||
Sector::get().add<SpriteParticle>("images/particles/wind.sprite", (abs(speed.x) > abs(speed.y)) ? "default" : "flip", ppos, ANCHOR_MIDDLE, pspeed, Vector(0, 0), LAYER_BACKGROUNDTILES+1); | ||
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. I'm not sure if maybe you should move the Yes, sorry for being mean and stricter than necessary, but that's just me being a good code reviewer. No hard feelings. |
||
} | ||
else | ||
{ | ||
Sector::get().add<Particles>(ppos, 44, 46, pspeed, Vector(0,0), 1, Color(.4f, .4f, .4f), 3, .1f, LAYER_BACKGROUNDTILES+1); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -108,17 +124,29 @@ Wind::collision(GameObject& other, const CollisionHit& ) | |
if (!blowing) return ABORT_MOVE; | ||
|
||
auto player = dynamic_cast<Player*> (&other); | ||
if (player) { | ||
if (!player->on_ground()) { | ||
if (player) | ||
{ | ||
if (!player->on_ground()) | ||
{ | ||
player->add_velocity(speed * acceleration * dt_sec, speed); | ||
} | ||
else | ||
{ | ||
if (player->get_controller().hold(Control::RIGHT) || player->get_controller().hold(Control::LEFT)) | ||
{ | ||
player->add_velocity(Vector(speed.x, 0) * acceleration * dt_sec, speed); | ||
} | ||
else | ||
{ | ||
//When on ground, get blown slightly differently, but the max speed is less than it would be otherwise seen as we take "friction" into account | ||
player->add_velocity((Vector(speed.x, 0) * 0.1f) * (acceleration+1), (Vector(speed.x, speed.y) * 0.5f)); | ||
} | ||
} | ||
} | ||
|
||
auto badguy = dynamic_cast<BadGuy*> (&other); | ||
if (badguy && this->affects_badguys) { | ||
if (badguy->can_be_affected_by_wind()) { | ||
badguy->add_wind_velocity(speed * acceleration * dt_sec, speed); | ||
} | ||
if (badguy && this->affects_badguys && badguy->can_be_affected_by_wind()) | ||
{ | ||
badguy->add_wind_velocity(speed * acceleration * dt_sec, speed); | ||
} | ||
|
||
return ABORT_MOVE; | ||
|
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 you please check the indentation of this file and fix it (because if we merge it now, this won't happen)
Oh, and add
[ci skip]
after your commit message so that we don't waste unnecessary integration cycles.