Skip to content

Commit

Permalink
Use set_velocity whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Aug 13, 2023
1 parent 1651483 commit 879ec46
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 62 deletions.
16 changes: 6 additions & 10 deletions src/badguy/angrystone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ AngryStone::AngryStone(const ReaderMapping& reader) :
m_state(IDLE)
{
m_countMe = false;
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
m_physic.enable_gravity(true);
set_action("idle");
}
Expand All @@ -50,8 +49,7 @@ AngryStone::collision_solid(const CollisionHit& hit)
{
m_state = IDLE;
sprite->set_action("idle");
physic.set_velocity_x(0);
physic.set_velocity_y(0);
physic.set_velocity(0, 0);
physic.enable_gravity(true);
m_old_wall_direction.x = m_attack_direction.x;
m_old_wall_direction.y = m_attack_direction.y;
Expand Down Expand Up @@ -153,8 +151,8 @@ AngryStone::active_update(float dt_sec)
m_timer.start(ATTACK_TIME);
m_state = ATTACKING;
m_physic.enable_gravity(false);
m_physic.set_velocity_x(CHARGE_SPEED * m_attack_direction.x);
m_physic.set_velocity_y(CHARGE_SPEED * m_attack_direction.y);
m_physic.set_velocity(CHARGE_SPEED * m_attack_direction.x,
CHARGE_SPEED * m_attack_direction.y);
m_old_wall_direction.x = 0;
m_old_wall_direction.y = 0;
}
Expand All @@ -168,8 +166,7 @@ AngryStone::active_update(float dt_sec)
m_state = RECOVERING;
set_action("idle");
m_physic.enable_gravity(true);
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
}
} break;

Expand All @@ -180,8 +177,7 @@ AngryStone::active_update(float dt_sec)
m_state = IDLE;
set_action("idle");
m_physic.enable_gravity(true);
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
}
} break;
}
Expand Down
9 changes: 3 additions & 6 deletions src/badguy/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,7 @@ BadGuy::collision_solid(const CollisionHit& hit)
}
else
{
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
}
update_on_ground_flag(hit);
}
Expand Down Expand Up @@ -574,8 +573,7 @@ BadGuy::kill_squished(GameObject& object)

SoundManager::current()->play("sounds/squish.wav", get_pos());
m_physic.enable_gravity(true);
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
set_state(STATE_SQUISHED);
set_group(COLGROUP_MOVING_ONLY_STATIC);
auto player = dynamic_cast<Player*>(&object);
Expand Down Expand Up @@ -969,8 +967,7 @@ BadGuy::ignite()
unfreeze();

m_physic.enable_gravity(true);
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
set_group(COLGROUP_MOVING_ONLY_STATIC);
m_sprite->stop_animation();
m_ignited = true;
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/goldbomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ GoldBomb::collision_solid(const CollisionHit& hit)
{
if (tstate == STATE_TICKING) {
if (hit.bottom) {
m_physic.set_velocity_y(0);
m_physic.set_velocity_x(0);
m_physic.set_velocity(0, 0);
}else if (hit.left || hit.right)
m_physic.set_velocity_x(-m_physic.get_velocity_x());
else if (hit.top)
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/kamikazesnowball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ KamikazeSnowball::kill_collision()
{
set_action("collision", m_dir);
SoundManager::current()->play(SPLAT_SOUND, get_pos());
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
m_physic.enable_gravity(true);
set_state(STATE_FALLING);

Expand Down
3 changes: 1 addition & 2 deletions src/badguy/kugelblitz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ Kugelblitz::Kugelblitz(const ReaderMapping& reader) :
void
Kugelblitz::initialize()
{
m_physic.set_velocity_y(300);
m_physic.set_velocity_x(-20); // Fall a little to the left.
m_physic.set_velocity(-20, 300); // Fall a little to the left.
direction = 1;
dying = false;
}
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/mriceblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ MrIceBlock::collision_squished(GameObject& object)
}

SoundManager::current()->play("sounds/stomp.wav", get_pos());
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
set_state(ICESTATE_FLAT);
nokick_timer.start(NOKICK_TIME);
break;
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/skullyhop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void
SkullyHop::set_state(SkullyHopState newState)
{
if (newState == STANDING) {
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
set_action("standing", m_dir);

recover_timer.start(0.5);
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/skydive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ SkyDive::grab(MovingObject& object, const Vector& pos, Direction dir_)

if (!m_frozen)
{
m_physic.set_velocity_x(movement.x * LOGICAL_FPS);
m_physic.set_velocity_y(0.0);
m_physic.set_velocity(movement.x * LOGICAL_FPS, 0.0);
m_physic.set_acceleration_y(0.0);
}
m_physic.enable_gravity(false);
Expand Down
9 changes: 3 additions & 6 deletions src/badguy/snail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ Snail::be_flat()
state = STATE_FLAT;
set_action("flat", m_dir, /* loops = */ -1);

m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);

flat_timer.start(4);
}
Expand All @@ -129,8 +128,7 @@ Snail::be_kicked(bool upwards)
state = STATE_KICKED;
set_action("flat", m_dir, /* loops = */ -1);

m_physic.set_velocity_x(m_dir == Direction::LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED);
m_physic.set_velocity_y(0);
m_physic.set_velocity(m_dir == Direction::LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED, 0);

// Start a timer to delay addition of upward movement until we are (hopefully) out from under the player.
if (upwards)
Expand Down Expand Up @@ -203,8 +201,7 @@ Snail::active_update(float dt_sec)

case STATE_KICKED_DELAY:
if (kicked_delay_timer.check()) {
m_physic.set_velocity_x(m_dir == Direction::LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED);
m_physic.set_velocity_y(SNAIL_KICK_SPEED_Y);
m_physic.set_velocity(m_dir == Direction::LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED, SNAIL_KICK_SPEED_Y);
state = STATE_KICKED;
}
break;
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/stalactite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ Stalactite::squish()
{
state = STALACTITE_SQUISHED;
m_physic.enable_gravity(true);
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
set_state(STATE_SQUISHED);
set_action("squished");
SoundManager::current()->play("sounds/icecrash.ogg", get_pos());
Expand Down
6 changes: 2 additions & 4 deletions src/badguy/toad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ void
Toad::set_state(ToadState newState)
{
if (newState == IDLE) {
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
if (!m_frozen)
set_action("idle", m_dir);

recover_timer.start(TOAD_RECOVER_TIME);
} else
if (newState == JUMPING) {
set_action("jumping", m_dir);
m_physic.set_velocity_x(m_dir == Direction::LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED);
m_physic.set_velocity_y(VERTICAL_SPEED);
m_physic.set_velocity(m_dir == Direction::LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED, VERTICAL_SPEED);
SoundManager::current()->play( HOP_SOUND, get_pos());
} else
if (newState == FALLING) {
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/totem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ Totem::synchronize_with(Totem* base)
pos.y -= m_sprite->get_current_hitbox_height();
set_pos(pos);

m_physic.set_velocity_x(base->m_physic.get_velocity_x());
m_physic.set_velocity_y(base->m_physic.get_velocity_y());
m_physic.set_velocity(base->m_physic.get_velocity());
}

/* EOF */
15 changes: 5 additions & 10 deletions src/badguy/yeti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,23 @@ void
Yeti::jump_down()
{
set_action("jump", m_dir);
m_physic.set_velocity_x((m_dir==Direction::RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
m_physic.set_velocity_y(JUMP_DOWN_VY);
m_physic.set_velocity(m_dir == Direction::RIGHT ? JUMP_DOWN_VX : -JUMP_DOWN_VX, JUMP_DOWN_VY);
state = JUMP_DOWN;
}

void
Yeti::run()
{
set_action("walking", m_dir);
m_physic.set_velocity_x((m_dir==Direction::RIGHT)?(+RUN_VX):(-RUN_VX));
m_physic.set_velocity_y(0);
m_physic.set_velocity(m_dir == Direction::RIGHT ? RUN_VX : -RUN_VX, 0);
state = RUN;
}

void
Yeti::jump_up()
{
set_action("jump", m_dir);
m_physic.set_velocity_x((m_dir==Direction::RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
m_physic.set_velocity_y(JUMP_UP_VY);
m_physic.set_velocity(m_dir == Direction::RIGHT ? JUMP_UP_VX : -JUMP_UP_VX, JUMP_UP_VY);
state = JUMP_UP;
}

Expand Down Expand Up @@ -262,8 +259,7 @@ void Yeti::take_hit(Player& )

if (hit_points <= 0) {
// We're dead.
m_physic.set_velocity_x(((m_dir==Direction::RIGHT)?+RUN_VX:-RUN_VX)/5);
m_physic.set_velocity_y(0);
m_physic.set_velocity((m_dir == Direction::RIGHT ? RUN_VX : -RUN_VX) / 5, 0);

// Set the badguy layer to be above the foremost, so that
// this does not reveal secret tilemaps:
Expand Down Expand Up @@ -392,8 +388,7 @@ Yeti::add_snow_explosions()
Yeti::SnowExplosionParticle::SnowExplosionParticle(const Vector& pos, const Vector& velocity)
: BadGuy(pos, (velocity.x > 0) ? Direction::RIGHT : Direction::LEFT, "images/objects/bullets/icebullet.sprite")
{
m_physic.set_velocity_x(velocity.x);
m_physic.set_velocity_y(velocity.y);
m_physic.set_velocity(velocity);
m_physic.enable_gravity(true);
set_state(STATE_FALLING);
m_layer = Sector::get().get_foremost_layer() + 1;
Expand Down
6 changes: 2 additions & 4 deletions src/badguy/zeekling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ Zeekling::onBumpHorizontal()
m_dir = (m_dir == Direction::LEFT ? Direction::RIGHT : Direction::LEFT);
state = FLYING;
set_action(m_dir);
m_physic.set_velocity_x(m_dir == Direction::LEFT ? -speed : speed);
m_physic.set_velocity_y(0);
m_physic.set_velocity(m_dir == Direction::LEFT ? -speed : speed, 0);
} else
if (state == CLIMBING) {
m_dir = (m_dir == Direction::LEFT ? Direction::RIGHT : Direction::LEFT);
Expand All @@ -82,8 +81,7 @@ Zeekling::onBumpVertical()
{
if (BadGuy::get_state() == STATE_BURNING)
{
m_physic.set_velocity_y(0);
m_physic.set_velocity_x(0);
m_physic.set_velocity(0, 0);
return;
}
if (state == FLYING) {
Expand Down
3 changes: 1 addition & 2 deletions src/object/coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ HeavyCoin::collision_solid(const CollisionHit& hit)
if (m_physic.get_velocity_y() > 200) {// lets some coins bounce
m_physic.set_velocity_y(-99);
} else {
m_physic.set_velocity_y(0);
m_physic.set_velocity_x(0);
m_physic.set_velocity(0, 0);
}
}
if (hit.right || hit.left) {
Expand Down
3 changes: 1 addition & 2 deletions src/object/falling_coin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ FallingCoin::FallingCoin(const Vector& start_position, float vel_x) :
pos(start_position),
sprite(SpriteManager::current()->create("images/objects/coin/coin.sprite"))
{
physic.set_velocity_y(-800.0f);
physic.set_velocity_x(vel_x);
physic.set_velocity(vel_x, -800.0f);
}

void
Expand Down
3 changes: 1 addition & 2 deletions src/object/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2435,8 +2435,7 @@ Player::deactivate()
if (m_deactivated)
return;
m_deactivated = true;
m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);
m_physic.set_velocity(0, 0);
m_physic.set_acceleration_x(0);
m_physic.set_acceleration_y(0);
if (m_climbing) stop_climbing(*m_climbing);
Expand Down

0 comments on commit 879ec46

Please sign in to comment.