Skip to content

Commit

Permalink
More dynamics for the big snowball
Browse files Browse the repository at this point in the history
  • Loading branch information
weluvgoatz committed Jul 8, 2024
1 parent 9db7870 commit 8aad196
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
25 changes: 24 additions & 1 deletion src/object/bigsnowball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
#include "badguy/yeti.hpp"
#include "math/random.hpp"
#include "math/util.hpp"
#include "object/bumper.hpp"
#include "object/player.hpp"
#include "object/sprite_particle.hpp"
#include "object/trampoline.hpp"
#include "sprite/sprite.hpp"
#include "sprite/sprite_manager.hpp"
#include "supertux/sector.hpp"
#include "supertux/tile.hpp"
#include "util/reader_mapping.hpp"

namespace {
Expand Down Expand Up @@ -112,7 +115,9 @@ BigSnowball::update(float dt_sec)
spawn_particles();
}

Vector movement = m_physic.get_movement(dt_sec);
bool in_water = !Sector::get().is_free_of_tiles(get_bbox(), true, Tile::WATER);

Vector movement = m_physic.get_movement(dt_sec) * Vector(in_water ? 0.4f : 1.f, in_water ? 0.6f : 1.f);
m_sprite->set_angle(m_sprite->get_angle() + movement.x * 3.141592653898f / 2.f);
m_col.set_movement(movement);
m_col.propagate_movement(movement);
Expand Down Expand Up @@ -146,6 +151,24 @@ BigSnowball::collision(GameObject& other, const CollisionHit& hit)
collision_solid(hit);
return ABORT_MOVE;
}

auto tramp = dynamic_cast<Trampoline*>(&other); // cppcheck-suppress constVariablePointer
if (tramp)
{
m_physic.set_velocity_y(-500.f);
tramp->bounce();
return ABORT_MOVE;
}

auto bumper = dynamic_cast<Bumper*>(&other); // cppcheck-suppress constVariablePointer
if (bumper)
{
m_physic.set_velocity_x(-m_physic.get_velocity_x());
m_dir = m_dir == Direction::LEFT ? Direction::RIGHT : Direction::LEFT;
bumper->bounce();
return ABORT_MOVE;
}

return FORCE_MOVE;
}

Expand Down
10 changes: 8 additions & 2 deletions src/object/bumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ Bumper::collision(GameObject& other, const CollisionHit& hit)
{
player->get_physic().set_velocity(0.f, player->is_swimming() ? 0.f : BOUNCE_Y);
player->sideways_push(m_dir == Direction::LEFT ? -BOUNCE_X : BOUNCE_X);
SoundManager::current()->play(TRAMPOLINE_SOUND, get_pos());
set_action("swinging", m_dir, 1);
bounce();
}

auto badguy = dynamic_cast<BadGuy*> (&other);
Expand Down Expand Up @@ -143,4 +142,11 @@ Bumper::on_flip(float height)
FlipLevelTransformer::transform_flip(m_flip);
}

void
Bumper::bounce()
{
SoundManager::current()->play(TRAMPOLINE_SOUND, get_pos());
set_action("swinging", m_dir, 1);
}

/* EOF */
2 changes: 2 additions & 0 deletions src/object/bumper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Bumper final : public StickyObject

Physic& get_physic();

void bounce();

private:
Physic m_physic;

Expand Down
5 changes: 4 additions & 1 deletion src/object/pushbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "object/pushbutton.hpp"

#include "audio/sound_manager.hpp"
#include "object/bigsnowball.hpp"
#include "object/player.hpp"
#include "object/rock.hpp"
#include "sprite/sprite.hpp"
Expand Down Expand Up @@ -88,7 +89,9 @@ PushButton::collision(GameObject& other, const CollisionHit& hit)
{
auto player = dynamic_cast<Player*>(&other);
auto rock = dynamic_cast<Rock*>(&other);
if (!player && !rock)
auto bs = dynamic_cast<BigSnowball*>(&other);

if (!player && !rock && !bs)
return FORCE_MOVE;
if (player)
{
Expand Down

0 comments on commit 8aad196

Please sign in to comment.