Skip to content

Commit

Permalink
fix: wallkicks not making smoke particles
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahkittyy committed Apr 16, 2023
1 parent 0d5bc67 commit b0d4300
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
9 changes: 7 additions & 2 deletions game/player_ghost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include "util.hpp"
#include "world.hpp"

player_ghost::player_ghost() {
player_ghost::player_ghost()
: m_pmgr(nullptr) {
m_last_update = util::get_time();
m_p.setOrigin(m_p.size().x / 2.f, m_p.size().y / 2.f);
m_p.update();
Expand All @@ -21,6 +22,10 @@ void player_ghost::flush_data(const multiplayer::player_data& d) {
m_nametag.set_name(m_data.name);
}

void player_ghost::set_particle_manager(particle_manager* pmgr) {
m_pmgr = pmgr;
}

void player_ghost::update() {
if (m_p.get_fill_color() != m_data.fill) {
m_p.set_fill_color(m_data.fill);
Expand All @@ -41,7 +46,7 @@ void player_ghost::update() {

// mini physics simulation
world::control_vars& v = m_state.controls;
world::run_controls(dt, v);
world::run_controls(dt, v, m_pmgr);

v.xp += v.xv * dt.asSeconds();
if (v.grounded) {
Expand Down
4 changes: 4 additions & 0 deletions game/player_ghost.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class player_ghost : public sf::Drawable, public sf::Transformable {
void flush_state(const multiplayer::player_state& s);
void flush_data(const multiplayer::player_data& d);

void set_particle_manager(particle_manager* pmgr = nullptr);

private:
void draw(sf::RenderTarget& t, sf::RenderStates s) const;

Expand All @@ -21,4 +23,6 @@ class player_ghost : public sf::Drawable, public sf::Transformable {
nametag m_nametag;
multiplayer::player_state m_state;
multiplayer::player_data m_data;

particle_manager* m_pmgr;
};
7 changes: 6 additions & 1 deletion game/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void world::step(sf::Time dt) {
m_cvars.on_ice = m_on_ice();
m_cvars.alt_controls = m_alt_controls();
m_cvars.tile_above = m_tile_above_player();
run_controls(dt, m_cvars);
run_controls(dt, m_cvars, &m_pmgr);

// !! physics !! //

Expand Down Expand Up @@ -802,6 +802,11 @@ void world::control_vars::player_wallkick(dir d, particle_manager* pmgr) {
sp.setScale(xv_sign, sp.getScale().y);
}
resource::get().play_sound("wallkick");
if (pmgr) {
auto& sp = pmgr->spawn<particles::smoke>();
sp.setPosition(xp - 0.35f * xv_sign, yp);
sp.setScale(xv_sign, sp.getScale().y);
}
sx = -xv_sign;
since_wallkick = sf::Time::Zero;
}
Expand Down

0 comments on commit b0d4300

Please sign in to comment.