From 771e4e2a8a32058167051bf53d689df95d18b598 Mon Sep 17 00:00:00 2001 From: Vankata453 <78196474+Vankata453@users.noreply.github.com> Date: Mon, 24 Jul 2023 15:24:47 +0300 Subject: [PATCH] Fix sprite hardcoding issues, convert more objects to `MovingSprite` Some objects contain duplicate code for setting their sprite, which in some cases overrides the custom sprite preference. Such duplicate code has been removed. Some objects inherit `MovingObject`, whilst managing a sprite. Many of such objects have been converted to MovingObject. Triggers haven't been converted yet. That is to come with a future PR. Additionally, `m_sprite->set_action` calls on `MovingSprite` objects have been replaced with `set_action` calls. This makes sure that when the action is updated, the object's hitbox is too. --- src/badguy/flame.cpp | 3 --- src/badguy/goldbomb.cpp | 10 ---------- src/badguy/haywire.cpp | 11 ----------- src/badguy/kamikazesnowball.cpp | 10 +++------- src/badguy/kamikazesnowball.hpp | 3 ++- src/badguy/mrbomb.cpp | 11 ----------- src/badguy/mriceblock.cpp | 4 ++-- src/badguy/mriceblock.hpp | 3 ++- src/badguy/short_fuse.cpp | 11 ----------- src/badguy/smartblock.cpp | 11 +---------- src/object/block.cpp | 35 +++++---------------------------- src/object/block.hpp | 18 +++-------------- src/object/bonus_block.cpp | 20 +++++++------------ src/object/brick.cpp | 13 +++++------- src/object/brick.hpp | 7 ++++--- src/object/bumper.cpp | 6 +++--- src/object/candle.cpp | 10 +++++----- src/object/conveyor_belt.cpp | 31 +++++++++++++++++------------ src/object/conveyor_belt.hpp | 12 +++++------ src/object/firefly.cpp | 19 +++--------------- src/object/invisible_block.cpp | 15 ++++++-------- src/object/ispy.cpp | 12 +++++------ src/object/lantern.cpp | 8 ++++---- src/object/lit_object.cpp | 35 +++++++-------------------------- src/object/lit_object.hpp | 20 ++++++------------- src/object/magicblock.cpp | 4 ++-- src/object/moving_sprite.cpp | 2 +- src/object/moving_sprite.hpp | 2 +- src/object/rublight.cpp | 8 ++++---- src/object/rusty_trampoline.cpp | 15 +++++++------- src/object/shard.cpp | 2 +- src/object/skull_tile.cpp | 4 ++-- src/object/torch.cpp | 24 ++++++++-------------- src/object/torch.hpp | 10 ++++------ src/object/trampoline.cpp | 13 ++++++------ src/object/unstable_tile.cpp | 5 +++-- src/object/water_drop.cpp | 2 +- src/object/weak_block.cpp | 8 ++++---- 38 files changed, 143 insertions(+), 294 deletions(-) diff --git a/src/badguy/flame.cpp b/src/badguy/flame.cpp index edbb7541621..69b3527ecda 100644 --- a/src/badguy/flame.cpp +++ b/src/badguy/flame.cpp @@ -45,9 +45,6 @@ Flame::Flame(const ReaderMapping& reader, const std::string& sprite) : m_countMe = false; SoundManager::current()->preload(FLAME_SOUND); - reader.get("sprite", m_sprite_name, m_sprite_name.c_str()); - m_sprite = SpriteManager::current()->create(m_sprite_name); - set_colgroup_active(COLGROUP_TOUCHABLE); m_lightsprite->set_color(Color(0.21f, 0.13f, 0.08f)); diff --git a/src/badguy/goldbomb.cpp b/src/badguy/goldbomb.cpp index ccb78fc5313..72866d516c2 100644 --- a/src/badguy/goldbomb.cpp +++ b/src/badguy/goldbomb.cpp @@ -41,16 +41,6 @@ GoldBomb::GoldBomb(const ReaderMapping& reader) : //Prevent stutter when Tux jumps on Gold Bomb SoundManager::current()->preload("sounds/explosion.wav"); - //Check if we need another sprite - if ( !reader.get( "sprite", m_sprite_name ) ){ - return; - } - if (m_sprite_name.empty()) { - m_sprite_name = "images/creatures/gold_bomb/gold_bomb.sprite"; - return; - } - //Replace sprite - m_sprite = SpriteManager::current()->create( m_sprite_name ); m_exploding_sprite->set_action("default", 1); } diff --git a/src/badguy/haywire.cpp b/src/badguy/haywire.cpp index 2ebd7b798e7..cdcfaa954b5 100644 --- a/src/badguy/haywire.cpp +++ b/src/badguy/haywire.cpp @@ -56,17 +56,6 @@ Haywire::Haywire(const ReaderMapping& reader) : //Prevent stutter when Tux jumps on Mr Bomb SoundManager::current()->preload("sounds/explosion.wav"); - - //Check if we need another sprite - if ( !reader.get( "sprite", m_sprite_name ) ){ - return; - } - if (m_sprite_name.empty()) { - m_sprite_name = "images/creatures/haywire/haywire.sprite"; - return; - } - //Replace sprite - m_sprite = SpriteManager::current()->create( m_sprite_name ); } Direction diff --git a/src/badguy/kamikazesnowball.cpp b/src/badguy/kamikazesnowball.cpp index 307b0a2a3c1..ab3bb98f36d 100644 --- a/src/badguy/kamikazesnowball.cpp +++ b/src/badguy/kamikazesnowball.cpp @@ -17,8 +17,6 @@ #include "badguy/kamikazesnowball.hpp" #include "audio/sound_manager.hpp" -#include "sprite/sprite.hpp" -#include "sprite/sprite_manager.hpp" namespace{ static const float KAMIKAZE_SPEED = 200; @@ -26,8 +24,8 @@ namespace{ const std::string SPLAT_SOUND = "sounds/splat.wav"; } -KamikazeSnowball::KamikazeSnowball(const ReaderMapping& reader) : - BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite") +KamikazeSnowball::KamikazeSnowball(const ReaderMapping& reader, const std::string& sprite_name) : + BadGuy(reader, sprite_name) { SoundManager::current()->preload(SPLAT_SOUND); set_action (m_dir == Direction::LEFT ? "left" : "right", /* loops = */ -1); @@ -100,10 +98,8 @@ KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit) } LeafShot::LeafShot(const ReaderMapping& reader) : - KamikazeSnowball(reader) + KamikazeSnowball(reader, "images/creatures/leafshot/leafshot.sprite") { - m_sprite_name = "images/creatures/leafshot/leafshot.sprite"; - m_sprite = SpriteManager::current()->create(m_sprite_name); } void diff --git a/src/badguy/kamikazesnowball.hpp b/src/badguy/kamikazesnowball.hpp index 864674c0359..33a3907f301 100644 --- a/src/badguy/kamikazesnowball.hpp +++ b/src/badguy/kamikazesnowball.hpp @@ -24,7 +24,8 @@ class KamikazeSnowball : public BadGuy { public: - KamikazeSnowball(const ReaderMapping& reader); + KamikazeSnowball(const ReaderMapping& reader, + const std::string& sprite_name = "images/creatures/snowball/kamikaze-snowball.sprite"); virtual void initialize() override; virtual void collision_solid(const CollisionHit& hit) override; diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 255b5229b7b..03e309456ae 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -36,17 +36,6 @@ MrBomb::MrBomb(const ReaderMapping& reader) : //Prevent stutter when Tux jumps on Mr Bomb SoundManager::current()->preload("sounds/explosion.wav"); - - //Check if we need another sprite - if ( !reader.get( "sprite", m_sprite_name ) ){ - return; - } - if (m_sprite_name.empty()) { - m_sprite_name = "images/creatures/mr_bomb/mr_bomb.sprite"; - return; - } - //Replace sprite - m_sprite = SpriteManager::current()->create( m_sprite_name ); } HitResponse diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index aff55f08c53..d8792fb6c5e 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -30,8 +30,8 @@ namespace { const float NOKICK_TIME = 0.1f; } -MrIceBlock::MrIceBlock(const ReaderMapping& reader) : - WalkingBadguy(reader, "images/creatures/iceblock/iceblock.sprite", "left", "right"), +MrIceBlock::MrIceBlock(const ReaderMapping& reader, const std::string& sprite_name) : + WalkingBadguy(reader, sprite_name, "left", "right"), ice_state(ICESTATE_NORMAL), nokick_timer(), flat_timer(), diff --git a/src/badguy/mriceblock.hpp b/src/badguy/mriceblock.hpp index 53d6047e0aa..200e316bc31 100644 --- a/src/badguy/mriceblock.hpp +++ b/src/badguy/mriceblock.hpp @@ -22,7 +22,8 @@ class MrIceBlock : public WalkingBadguy { public: - MrIceBlock(const ReaderMapping& reader); + MrIceBlock(const ReaderMapping& reader, + const std::string& sprite_name = "images/creatures/iceblock/iceblock.sprite"); virtual void initialize() override; virtual HitResponse collision(GameObject& object, const CollisionHit& hit) override; diff --git a/src/badguy/short_fuse.cpp b/src/badguy/short_fuse.cpp index 3c17cb56808..165f1f920b3 100644 --- a/src/badguy/short_fuse.cpp +++ b/src/badguy/short_fuse.cpp @@ -31,17 +31,6 @@ ShortFuse::ShortFuse(const ReaderMapping& reader) : walk_speed = 100; max_drop_height = 16; - //Check if we need another sprite - if ( !reader.get( "sprite", m_sprite_name ) ){ - return; - } - if (m_sprite_name.empty()) { - m_sprite_name = "images/creatures/short_fuse/short_fuse.sprite"; - return; - } - //Replace sprite - m_sprite = SpriteManager::current()->create( m_sprite_name ); - SoundManager::current()->preload("sounds/firecracker.ogg"); } diff --git a/src/badguy/smartblock.cpp b/src/badguy/smartblock.cpp index f24265df905..5c6681e542c 100644 --- a/src/badguy/smartblock.cpp +++ b/src/badguy/smartblock.cpp @@ -16,19 +16,10 @@ #include "badguy/smartblock.hpp" -#include "sprite/sprite_manager.hpp" -#include "util/reader_mapping.hpp" - SmartBlock::SmartBlock(const ReaderMapping& reader) : - MrIceBlock(reader) + MrIceBlock(reader, "images/creatures/iceblock/smart_block.sprite") { max_drop_height = 16; - m_default_sprite_name = "images/creatures/iceblock/smart_block.sprite"; - - if (!reader.get("sprite", m_sprite_name)) { - m_sprite_name = m_default_sprite_name; - } - m_sprite = SpriteManager::current()->create(m_sprite_name); } /* EOF */ diff --git a/src/object/block.cpp b/src/object/block.cpp index 7f726dfe100..735cf42aa65 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -26,8 +26,6 @@ #include "object/growup.hpp" #include "object/player.hpp" #include "object/sprite_particle.hpp" -#include "sprite/sprite.hpp" -#include "sprite/sprite_manager.hpp" #include "supertux/constants.hpp" #include "supertux/flip_level_transformer.hpp" #include "supertux/sector.hpp" @@ -38,16 +36,13 @@ static const float BOUNCY_BRICK_MAX_OFFSET = 8; static const float BOUNCY_BRICK_SPEED = 90; static const float BUMP_ROTATION_ANGLE = 10; -Block::Block(SpritePtr newsprite) : - m_sprite(std::move(newsprite)), - m_sprite_name(), - m_default_sprite_name(), +Block::Block(const Vector& pos, const std::string& sprite_file) : + MovingSprite(pos, sprite_file), m_bouncing(false), m_breaking(false), m_bounce_dir(0), m_bounce_offset(0), - m_original_y(-1), - m_flip(NO_FLIP) + m_original_y(-1) { m_col.m_bbox.set_size(32, 32.1f); set_group(COLGROUP_STATIC); @@ -56,28 +51,13 @@ Block::Block(SpritePtr newsprite) : } Block::Block(const ReaderMapping& mapping, const std::string& sprite_file) : - m_sprite(), - m_sprite_name(), - m_default_sprite_name(), + MovingSprite(mapping, sprite_file), m_bouncing(false), m_breaking(false), m_bounce_dir(0), m_bounce_offset(0), - m_original_y(-1), - m_flip(NO_FLIP) + m_original_y(-1) { - mapping.get("x", m_col.m_bbox.get_left()); - mapping.get("y", m_col.m_bbox.get_top()); - - std::string sf; - mapping.get("sprite", sf); - if (sf.empty() || !PHYSFS_exists(sf.c_str())) { - sf = sprite_file; - } - m_sprite = SpriteManager::current()->create(sf); - m_sprite_name = sf; - m_default_sprite_name = sprite_file; - m_col.m_bbox.set_size(32, 32.1f); set_group(COLGROUP_STATIC); SoundManager::current()->preload("sounds/upgrade.wav"); @@ -237,11 +217,6 @@ Block::get_settings() return result; } -void Block::after_editor_set() -{ - m_sprite = SpriteManager::current()->create(m_sprite_name); -} - void Block::on_flip(float height) { diff --git a/src/object/block.hpp b/src/object/block.hpp index 17fd1f74a68..1b9eb6ca806 100644 --- a/src/object/block.hpp +++ b/src/object/block.hpp @@ -17,30 +17,24 @@ #ifndef HEADER_SUPERTUX_OBJECT_BLOCK_HPP #define HEADER_SUPERTUX_OBJECT_BLOCK_HPP -#include "sprite/sprite.hpp" -#include "sprite/sprite_ptr.hpp" -#include "supertux/moving_object.hpp" -#include "video/flip.hpp" +#include "object/moving_sprite.hpp" class Player; class ReaderMapping; -class Block : public MovingObject +class Block : public MovingSprite { friend class FlipLevelTransformer; public: - Block(SpritePtr sprite); + Block(const Vector& pos, const std::string& sprite_file); Block(const ReaderMapping& mapping, const std::string& sprite_file); virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; virtual void update(float dt_sec) override; virtual void draw(DrawingContext& context) override; - virtual std::string get_default_sprite_name() const { return m_default_sprite_name; } - virtual ObjectSettings get_settings() override; - virtual void after_editor_set() override; virtual void on_flip(float height) override; @@ -55,18 +49,12 @@ class Block : public MovingObject void break_me(); protected: - SpritePtr m_sprite; - std::string m_sprite_name; - std::string m_default_sprite_name; bool m_bouncing; bool m_breaking; float m_bounce_dir; float m_bounce_offset; float m_original_y; -private: - Flip m_flip; - private: Block(const Block&) = delete; Block& operator=(const Block&) = delete; diff --git a/src/object/bonus_block.cpp b/src/object/bonus_block.cpp index b89fc7aadd3..3ca508c22b3 100644 --- a/src/object/bonus_block.cpp +++ b/src/object/bonus_block.cpp @@ -36,7 +36,6 @@ #include "object/specialriser.hpp" #include "object/star.hpp" #include "object/trampoline.hpp" -#include "sprite/sprite_manager.hpp" #include "supertux/constants.hpp" #include "supertux/game_object_factory.hpp" #include "supertux/level.hpp" @@ -63,7 +62,7 @@ const float upgrade_sound_gain = 0.3f; } // namespace BonusBlock::BonusBlock(const Vector& pos, int tile_data) : - Block(SpriteManager::current()->create("images/objects/bonus_block/bonusblock.sprite")), + Block(pos, "images/objects/bonus_block/bonusblock.sprite"), m_contents(), m_object(), m_hit_counter(1), @@ -72,10 +71,7 @@ BonusBlock::BonusBlock(const Vector& pos, int tile_data) : m_custom_sx(), m_coin_sprite("images/objects/coin/coin.sprite") { - m_default_sprite_name = "images/objects/bonus_block/bonusblock.sprite"; - - m_col.m_bbox.set_pos(pos); - m_sprite->set_action("normal"); + set_action("normal"); m_contents = get_content_by_data(tile_data); preload_contents(tile_data); } @@ -90,8 +86,6 @@ BonusBlock::BonusBlock(const ReaderMapping& mapping) : m_custom_sx(), m_coin_sprite("images/objects/coin/coin.sprite") { - m_default_sprite_name = "images/objects/bonus_block/bonusblock.sprite"; - auto iter = mapping.get_iter(); while (iter.next()) { const std::string& token = iter.get_key(); @@ -172,7 +166,7 @@ BonusBlock::BonusBlock(const ReaderMapping& mapping) : SoundManager::current()->preload("sounds/switch.ogg"); m_lightsprite = Surface::from_file("/images/objects/lightmap_light/bonusblock_light.png"); if (m_contents == Content::LIGHT_ON) { - m_sprite->set_action("on"); + set_action("on"); } } } @@ -354,9 +348,9 @@ BonusBlock::try_open(Player* player) case Content::LIGHT_ON: { if (m_sprite->get_action() == "on") - m_sprite->set_action("off"); + set_action("off"); else - m_sprite->set_action("on"); + set_action("on"); SoundManager::current()->play("sounds/switch.ogg", get_pos()); break; } @@ -406,7 +400,7 @@ BonusBlock::try_open(Player* player) start_bounce(player); if (m_hit_counter <= 0 || m_contents == Content::LIGHT || m_contents == Content::LIGHT_ON) { //use 0 to allow infinite hits } else if (m_hit_counter == 1) { - m_sprite->set_action("empty"); + set_action("empty"); } else { m_hit_counter--; } @@ -550,7 +544,7 @@ BonusBlock::try_drop(Player *player) if (countdown) { // only decrease hit counter if try_open was not called if (m_hit_counter == 1) { - m_sprite->set_action("empty"); + set_action("empty"); } else { m_hit_counter--; } diff --git a/src/object/brick.cpp b/src/object/brick.cpp index 72cb89573f1..fc9b3829968 100644 --- a/src/object/brick.cpp +++ b/src/object/brick.cpp @@ -24,18 +24,15 @@ #include "object/explosion.hpp" #include "object/player.hpp" #include "object/portable.hpp" -#include "sprite/sprite.hpp" -#include "sprite/sprite_manager.hpp" #include "supertux/constants.hpp" #include "supertux/sector.hpp" #include "util/reader_mapping.hpp" -Brick::Brick(const Vector& pos, int data, const std::string& spriteName) : - Block(SpriteManager::current()->create(spriteName)), +Brick::Brick(const Vector& pos, int data, const std::string& sprite_name) : + Block(pos, sprite_name), m_breakable(false), m_coin_counter(0) { - m_col.m_bbox.set_pos(pos); if (data == 1) { m_coin_counter = 5; } else { @@ -43,8 +40,8 @@ Brick::Brick(const Vector& pos, int data, const std::string& spriteName) : } } -Brick::Brick(const ReaderMapping& mapping, const std::string& spriteName) : - Block(mapping, spriteName), +Brick::Brick(const ReaderMapping& mapping, const std::string& sprite_name) : + Block(mapping, sprite_name), m_breakable(), m_coin_counter(0) { @@ -115,7 +112,7 @@ Brick::try_break(Player* player, bool slider) Player& player_one = *Sector::get().get_players()[0]; player_one.get_status().add_coins(1); if (m_coin_counter == 0) - m_sprite->set_action("empty"); + set_action("empty"); start_bounce(player); } else if (m_breakable) { if (player) { diff --git a/src/object/brick.hpp b/src/object/brick.hpp index bc427aef399..2a1b5353c89 100644 --- a/src/object/brick.hpp +++ b/src/object/brick.hpp @@ -17,14 +17,15 @@ #ifndef HEADER_SUPERTUX_OBJECT_BRICK_HPP #define HEADER_SUPERTUX_OBJECT_BRICK_HPP -#include "badguy/crusher.hpp" #include "object/block.hpp" +#include "badguy/crusher.hpp" + class Brick : public Block { public: - Brick(const Vector& pos, int data, const std::string& spriteName); - Brick(const ReaderMapping& mapping, const std::string& spriteName = "images/objects/bonus_block/brick.sprite"); + Brick(const Vector& pos, int data, const std::string& sprite_name); + Brick(const ReaderMapping& mapping, const std::string& sprite_name = "images/objects/bonus_block/brick.sprite"); virtual HitResponse collision(GameObject& other, const CollisionHit& hit) override; virtual ObjectSettings get_settings() override; diff --git a/src/object/bumper.cpp b/src/object/bumper.cpp index cd71ef39de7..b267cf646f6 100644 --- a/src/object/bumper.cpp +++ b/src/object/bumper.cpp @@ -35,7 +35,7 @@ Bumper::Bumper(const ReaderMapping& reader) : left() { reader.get("left", left); - m_sprite->set_action(left ? "left-normal" : "right-normal"); + set_action(left ? "left-normal" : "right-normal"); physic.enable_gravity(false); } @@ -56,7 +56,7 @@ Bumper::update(float dt_sec) { if (m_sprite->animation_done()) { - m_sprite->set_action(left ? "left-normal" : "right-normal"); + set_action(left ? "left-normal" : "right-normal"); } m_col.set_movement(physic.get_movement (dt_sec)); } @@ -71,7 +71,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(BOUNCE_DIR); SoundManager::current()->play(TRAMPOLINE_SOUND, get_pos()); - m_sprite->set_action((left ? "left-swinging" : "right-swinging"), 1); + set_action((left ? "left-swinging" : "right-swinging"), 1); } auto bumper = dynamic_cast (&other); diff --git a/src/object/candle.cpp b/src/object/candle.cpp index 1483df84854..f415920016c 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -52,9 +52,9 @@ Candle::Candle(const ReaderMapping& mapping) : } if (burning) { - m_sprite->set_action("on"); + set_action("on"); } else { - m_sprite->set_action("off"); + set_action("off"); } } @@ -67,7 +67,7 @@ Candle::after_editor_set() candle_light_1->set_color(lightcolor); candle_light_2->set_color(lightcolor); - m_sprite->set_action(burning ? "on" : "off"); + set_action(burning ? "on" : "off"); } ObjectSettings @@ -136,9 +136,9 @@ Candle::set_burning(bool burning_) if (burning == burning_) return; burning = burning_; if (burning_) { - m_sprite->set_action("on"); + set_action("on"); } else { - m_sprite->set_action("off"); + set_action("off"); } //puff smoke for flickering light sources only if (flicker) puff_smoke(); diff --git a/src/object/conveyor_belt.cpp b/src/object/conveyor_belt.cpp index 5583626bf0a..8bbf7a81b9e 100644 --- a/src/object/conveyor_belt.cpp +++ b/src/object/conveyor_belt.cpp @@ -24,15 +24,14 @@ #include "util/reader_mapping.hpp" ConveyorBelt::ConveyorBelt(const ReaderMapping &reader) : - MovingObject(reader), // TODO: sprite + MovingSprite(reader, "images/objects/conveyor_belt/conveyor.sprite"), ExposedObject(this), m_running(true), m_dir(Direction::LEFT), m_length(1), m_speed(1.0f), m_frame(0.0f), - m_frame_index(0), - m_sprite(SpriteManager::current()->create("images/objects/conveyor_belt/conveyor.sprite")) + m_frame_index(0) { set_group(COLGROUP_STATIC); reader.get("running", m_running); @@ -47,18 +46,16 @@ ConveyorBelt::ConveyorBelt(const ReaderMapping &reader) : if (m_length <= 0) m_length = 1; - m_col.m_bbox.set_size(32.0f * static_cast(m_length), 32.0f); - if (!m_running) - m_sprite->set_action("stopped"); + set_action("stopped"); else - m_sprite->set_action(m_dir); + set_action(m_dir); } ObjectSettings ConveyorBelt::get_settings() { - ObjectSettings result = MovingObject::get_settings(); + ObjectSettings result = MovingSprite::get_settings(); result.add_direction(_("Direction"), &m_dir, Direction::LEFT, "direction"); result.add_float(_("Speed"), &m_speed, "speed", 1.0f); @@ -117,26 +114,34 @@ ConveyorBelt::draw(DrawingContext &context) } } +void +ConveyorBelt::update_hitbox() +{ + m_col.m_bbox.set_size(m_sprite->get_current_hitbox_width() * static_cast(m_length), + m_sprite->get_current_hitbox_height()); +} + void ConveyorBelt::after_editor_set() { + MovingSprite::after_editor_set(); + if (m_length <= 0) m_length = 1; - m_col.m_bbox.set_size(32.0f * static_cast(m_length), 32.0f); } void ConveyorBelt::start() { m_running = true; - m_sprite->set_action(m_dir); + set_action(m_dir); } void ConveyorBelt::stop() { m_running = false; - m_sprite->set_action("stopped"); + set_action("stopped"); } void @@ -144,7 +149,7 @@ ConveyorBelt::move_left() { m_dir = Direction::LEFT; if (m_running) - m_sprite->set_action("left"); + set_action("left"); } void @@ -152,7 +157,7 @@ ConveyorBelt::move_right() { m_dir = Direction::RIGHT; if (m_running) - m_sprite->set_action("right"); + set_action("right"); } void diff --git a/src/object/conveyor_belt.hpp b/src/object/conveyor_belt.hpp index a8c0c742b76..c3228811b1e 100644 --- a/src/object/conveyor_belt.hpp +++ b/src/object/conveyor_belt.hpp @@ -17,17 +17,14 @@ #ifndef HEADER_SUPERTUX_OBJECT_CONVEYOR_BELT_HPP #define HEADER_SUPERTUX_OBJECT_CONVEYOR_BELT_HPP +#include "object/moving_sprite.hpp" #include "squirrel/exposed_object.hpp" -#include "supertux/moving_object.hpp" #include "scripting/conveyor_belt.hpp" #include "supertux/timer.hpp" -#include "video/layer.hpp" - -class Sprite; /** This class represents a platform that moves entities riding it. */ -class ConveyorBelt final : public MovingObject, +class ConveyorBelt final : public MovingSprite, public ExposedObject { public: @@ -66,6 +63,9 @@ class ConveyorBelt final : public MovingObject, /** Changes the shifting speed of the conveyor. */ void set_speed(float target_speed); +private: + void update_hitbox() override; + private: bool m_running; Direction m_dir; @@ -77,8 +77,6 @@ class ConveyorBelt final : public MovingObject, const float MAX_SPEED = 32.0f; - std::unique_ptr m_sprite; - private: ConveyorBelt(const ConveyorBelt&) = delete; ConveyorBelt& operator=(const ConveyorBelt&) = delete; diff --git a/src/object/firefly.cpp b/src/object/firefly.cpp index 21c2ccbe85f..b579e8bc9bb 100644 --- a/src/object/firefly.cpp +++ b/src/object/firefly.cpp @@ -39,19 +39,6 @@ Firefly::Firefly(const ReaderMapping& mapping) : activated(false), initial_position(get_pos()) { - if (!mapping.get( "sprite", m_sprite_name)){ - update_state(); - return; - } - if (m_sprite_name.empty()) { - m_sprite_name = "images/objects/resetpoints/default-resetpoint.sprite"; - update_state(); - return; - } - //Replace sprite - m_sprite = SpriteManager::current()->create( m_sprite_name ); - m_col.m_bbox.set_size(m_sprite->get_current_hitbox_width(), m_sprite->get_current_hitbox_height()); - if (m_sprite_name.find("torch", 0) != std::string::npos) { m_sprite_light = SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite"); m_sprite_light->set_blend(Blend::ADD); @@ -101,11 +88,11 @@ Firefly::update_state() active_checkpoint_spawnpoint->sector == Sector::get().get_name() && active_checkpoint_spawnpoint->position == initial_position) // Is activated. { - m_sprite->set_action("ringing"); + set_action("ringing"); } else // Is deactivated. { - m_sprite->set_action("normal"); + set_action("normal"); } } @@ -142,7 +129,7 @@ Firefly::collision(GameObject& other, const CollisionHit& ) SoundManager::current()->play("sounds/savebell2.wav", get_pos()); } - m_sprite->set_action("ringing"); + set_action("ringing"); GameSession::current()->set_checkpoint_pos(Sector::get().get_name(), initial_position); } diff --git a/src/object/invisible_block.cpp b/src/object/invisible_block.cpp index 5d7774f5382..403c010b9e6 100644 --- a/src/object/invisible_block.cpp +++ b/src/object/invisible_block.cpp @@ -19,22 +19,19 @@ #include "audio/sound_manager.hpp" #include "editor/editor.hpp" #include "object/player.hpp" -#include "sprite/sprite.hpp" -#include "sprite/sprite_manager.hpp" #include "supertux/constants.hpp" InvisibleBlock::InvisibleBlock(const Vector& pos) : - Block(SpriteManager::current()->create("images/objects/bonus_block/invisibleblock.sprite")), - visible(false) + Block(pos, "images/objects/bonus_block/invisibleblock.sprite"), + visible(false) { - m_col.m_bbox.set_pos(pos); SoundManager::current()->preload("sounds/brick.wav"); - m_sprite->set_action("default-editor"); + set_action("default-editor"); } InvisibleBlock::InvisibleBlock(const ReaderMapping& mapping) : - Block(mapping, "images/objects/bonus_block/invisibleblock.sprite"), - visible(false) + Block(mapping, "images/objects/bonus_block/invisibleblock.sprite"), + visible(false) { SoundManager::current()->preload("sounds/brick.wav"); } @@ -77,7 +74,7 @@ InvisibleBlock::hit(Player& player) if (visible) return; - m_sprite->set_action("empty"); + set_action("empty"); start_bounce(&player); set_group(COLGROUP_STATIC); visible = true; diff --git a/src/object/ispy.cpp b/src/object/ispy.cpp index d6f795976c0..cd0fef1b0a1 100644 --- a/src/object/ispy.cpp +++ b/src/object/ispy.cpp @@ -128,10 +128,10 @@ Ispy::set_sprite_action(const std::string& action, int loops) { switch (m_dir) { - case Direction::DOWN: m_sprite->set_action(action + "-down", loops); break; - case Direction::UP: m_sprite->set_action(action + "-up", loops); break; - case Direction::LEFT: m_sprite->set_action(action + "-left", loops); break; - case Direction::RIGHT: m_sprite->set_action(action + "-right", loops); break; + case Direction::DOWN: set_action(action + "-down", loops); break; + case Direction::UP: set_action(action + "-up", loops); break; + case Direction::LEFT: set_action(action + "-left", loops); break; + case Direction::RIGHT: set_action(action + "-right", loops); break; default: break; } } @@ -143,12 +143,12 @@ Ispy::on_flip(float height) if (m_dir == Direction::UP) { m_dir = Direction::DOWN; - m_sprite->set_action("idle-down"); + set_action("idle-down"); } else if (m_dir == Direction::DOWN) { m_dir = Direction::UP; - m_sprite->set_action("idle-up"); + set_action("idle-up"); } } diff --git a/src/object/lantern.cpp b/src/object/lantern.cpp index f5f4907e6f6..9b979d0602e 100644 --- a/src/object/lantern.cpp +++ b/src/object/lantern.cpp @@ -79,10 +79,10 @@ Lantern::updateColor(){ lightsprite->set_color(lightcolor); //Turn lantern off if light is black if (lightcolor.red == 0 && lightcolor.green == 0 && lightcolor.blue == 0){ - m_sprite->set_action("off"); + set_action("off"); m_sprite->set_color(Color(1.0f, 1.0f, 1.0f)); } else { - m_sprite->set_action("normal"); + set_action("normal"); m_sprite->set_color(lightcolor); } } @@ -126,7 +126,7 @@ Lantern::grab(MovingObject& object, const Vector& pos, Direction dir) // if lantern is not lit, draw it as opened if (is_open()) { - m_sprite->set_action("off-open"); + set_action("off-open"); } } @@ -136,7 +136,7 @@ Lantern::ungrab(MovingObject& object, Direction dir) { // if lantern is not lit, it was drawn as opened while grabbed. Now draw it as closed again if (is_open()) { - m_sprite->set_action("off"); + set_action("off"); } Rock::ungrab(object, dir); diff --git a/src/object/lit_object.cpp b/src/object/lit_object.cpp index 607fd29cd86..eacd456c5a3 100644 --- a/src/object/lit_object.cpp +++ b/src/object/lit_object.cpp @@ -22,41 +22,29 @@ #include "util/reader_mapping.hpp" LitObject::LitObject(const ReaderMapping& reader) : - MovingObject(reader), + MovingSprite(reader, "images/objects/lightflower/lightflower1.sprite"), ExposedObject(this), m_light_offset(-6.f, -17.f), - m_sprite_name("images/objects/lightflower/lightflower1.sprite"), m_light_sprite_name("images/objects/lightflower/light/glow_light.sprite"), m_sprite_action("default"), m_light_sprite_action("default"), - m_sprite(), - m_light_sprite(), - m_layer(0), - m_flip(NO_FLIP) + m_light_sprite() { - reader.get("x", m_col.m_bbox.get_left()); - reader.get("y", m_col.m_bbox.get_top()); - reader.get("light-offset-x", m_light_offset.x); reader.get("light-offset-y", m_light_offset.y); - reader.get("sprite", m_sprite_name); reader.get("light-sprite", m_light_sprite_name); reader.get("layer", m_layer, 0); reader.get("action", m_sprite_action); reader.get("light-action", m_light_sprite_action); - m_sprite = SpriteManager::current()->create(m_sprite_name); m_light_sprite = SpriteManager::current()->create(m_light_sprite_name); m_light_sprite->set_blend(Blend::ADD); - m_sprite->set_action(m_sprite_action); + set_action(m_sprite_action); m_light_sprite->set_action(m_light_sprite_action); - m_col.m_bbox.set_size(static_cast(m_sprite->get_width()), - static_cast(m_sprite->get_height())); - set_group(COLGROUP_DISABLED); } @@ -75,9 +63,8 @@ LitObject::update(float) ObjectSettings LitObject::get_settings() { - ObjectSettings result = MovingObject::get_settings(); + ObjectSettings result = MovingSprite::get_settings(); - result.add_sprite(_("Sprite"), &m_sprite_name, "sprite", std::string("images/objects/lightflower/lightflower1.sprite")); result.add_sprite(_("Light sprite"), &m_light_sprite_name, "light-sprite", std::string("images/objects/lightflower/light/glow_light.sprite")); result.add_int(_("Layer"), &m_layer, "layer", 0); @@ -93,15 +80,13 @@ LitObject::get_settings() void LitObject::after_editor_set() { - m_sprite = SpriteManager::current()->create(m_sprite_name); + MovingSprite::after_editor_set(); + m_light_sprite = SpriteManager::current()->create(m_light_sprite_name); m_light_sprite->set_blend(Blend::ADD); - m_sprite->set_action(m_sprite_action); + set_action(m_sprite_action); m_light_sprite->set_action(m_light_sprite_action); - - m_col.m_bbox.set_size(static_cast(m_sprite->get_width()), - static_cast(m_sprite->get_height())); } void @@ -117,12 +102,6 @@ LitObject::get_action() const return m_sprite->get_action(); } -void -LitObject::set_action(const std::string& action) -{ - m_sprite->set_action(action); -} - const std::string& LitObject::get_light_action() const { diff --git a/src/object/lit_object.hpp b/src/object/lit_object.hpp index b22146e76d2..b44baf1b18c 100644 --- a/src/object/lit_object.hpp +++ b/src/object/lit_object.hpp @@ -17,17 +17,15 @@ #ifndef HEADER_SUPERTUX_OBJECT_LIT_OBJECT_HPP #define HEADER_SUPERTUX_OBJECT_LIT_OBJECT_HPP -#include "scripting/lit_object.hpp" -#include "sprite/sprite_ptr.hpp" +#include "object/moving_sprite.hpp" #include "squirrel/exposed_object.hpp" -#include "supertux/moving_object.hpp" -#include "video/flip.hpp" + +#include "scripting/lit_object.hpp" class ReaderMapping; -class LitObject final : - public MovingObject, - public ExposedObject +class LitObject final : public MovingSprite, + public ExposedObject { public: LitObject(const ReaderMapping& reader); @@ -35,8 +33,7 @@ class LitObject final : virtual void draw(DrawingContext& context) override; virtual void update(float) override; - virtual HitResponse collision(GameObject&, const CollisionHit&) override - { return ABORT_MOVE; } + virtual HitResponse collision(GameObject&, const CollisionHit&) override { return ABORT_MOVE; } static std::string class_name() { return "lit-object"; } virtual std::string get_class_name() const override { return class_name(); } @@ -51,20 +48,15 @@ class LitObject final : virtual void on_flip(float height) override; const std::string& get_action() const; - void set_action(const std::string& action); const std::string& get_light_action() const; void set_light_action(const std::string& action); private: Vector m_light_offset; - std::string m_sprite_name; std::string m_light_sprite_name; std::string m_sprite_action; std::string m_light_sprite_action; - SpritePtr m_sprite; SpritePtr m_light_sprite; - int m_layer; - Flip m_flip; private: LitObject(const LitObject&) = delete; diff --git a/src/object/magicblock.cpp b/src/object/magicblock.cpp index f88072905f1..66b92910051 100644 --- a/src/object/magicblock.cpp +++ b/src/object/magicblock.cpp @@ -176,11 +176,11 @@ MagicBlock::update(float dt_sec) if (m_is_solid) { m_solid_time+=dt_sec; m_color.alpha = ALPHA_SOLID; - m_sprite->set_action("solid"); + set_action("solid"); set_group(COLGROUP_STATIC); } else { m_color.alpha = ALPHA_NONSOLID; - m_sprite->set_action("normal"); + set_action("normal"); set_group(COLGROUP_DISABLED); } } diff --git a/src/object/moving_sprite.cpp b/src/object/moving_sprite.cpp index ac8ac83aef9..2f0f7b9c53e 100644 --- a/src/object/moving_sprite.cpp +++ b/src/object/moving_sprite.cpp @@ -64,7 +64,7 @@ MovingSprite::MovingSprite(const ReaderMapping& reader, const std::string& sprit //Make the sprite go default when the sprite file is invalid if (m_sprite_name.empty() || !PHYSFS_exists(m_sprite_name.c_str())) { - m_sprite = SpriteManager::current()->create(m_default_sprite_name); + change_sprite(m_default_sprite_name); m_sprite_found = false; } else if (!change_sprite(m_sprite_name)) // If sprite change fails, change back to default. diff --git a/src/object/moving_sprite.hpp b/src/object/moving_sprite.hpp index fa3579d6d4e..97a56ee6aba 100644 --- a/src/object/moving_sprite.hpp +++ b/src/object/moving_sprite.hpp @@ -97,7 +97,7 @@ class MovingSprite : public MovingObject protected: /** Update hitbox, based on sprite. */ - void update_hitbox(); + virtual void update_hitbox(); protected: std::string m_sprite_name; diff --git a/src/object/rublight.cpp b/src/object/rublight.cpp index 90b134d22c6..afe021e8326 100644 --- a/src/object/rublight.cpp +++ b/src/object/rublight.cpp @@ -37,7 +37,7 @@ RubLight::RubLight(const ReaderMapping& mapping) : fading_speed(5.0f), strength_multiplier(1.0f) { - m_sprite->set_action("inactive"); + set_action("inactive"); std::vector vColor; if (mapping.get("color", vColor)) @@ -95,7 +95,7 @@ void RubLight::rub(float strength) { if (strength <= 0) return; - m_sprite->set_action("active"); + set_action("active"); strength *= strength_multiplier; stored_energy = std::max(stored_energy, strength); if (state == STATE_DARK) @@ -107,12 +107,12 @@ RubLight::update(float dt_sec) { if (m_sprite->get_action() == "active" && m_sprite->animation_done()) { - m_sprite->set_action("inactive"); + set_action("inactive"); } switch (state) { case STATE_DARK: - m_sprite->set_action("inactive"); + set_action("inactive"); break; case STATE_FADING: diff --git a/src/object/rusty_trampoline.cpp b/src/object/rusty_trampoline.cpp index a82bfd3a967..9b3ce246bb5 100644 --- a/src/object/rusty_trampoline.cpp +++ b/src/object/rusty_trampoline.cpp @@ -49,7 +49,7 @@ RustyTrampoline::update(float dt_sec) if (counter < 1) { remove_me(); } else { - m_sprite->set_action("normal"); + set_action("normal"); } } @@ -90,9 +90,9 @@ RustyTrampoline::collision(GameObject& other, const CollisionHit& hit) SoundManager::current()->play(BOUNCE_SOUND, get_pos()); counter--; if (counter > 0) { - m_sprite->set_action("swinging", 1); + set_action("swinging", 1); } else { - m_sprite->set_action("breaking", 1); + set_action("breaking", 1); } return FORCE_MOVE; @@ -109,9 +109,9 @@ RustyTrampoline::collision(GameObject& other, const CollisionHit& hit) SoundManager::current()->play(BOUNCE_SOUND, get_pos()); counter--; if (counter > 0) { - m_sprite->set_action("swinging", 1); + set_action("swinging", 1); } else { - m_sprite->set_action("breaking", 1); + set_action("breaking", 1); } return FORCE_MOVE; } @@ -132,9 +132,10 @@ RustyTrampoline::grab(MovingObject& object, const Vector& pos, Direction dir) { } void -RustyTrampoline::ungrab(MovingObject& object, Direction dir) { +RustyTrampoline::ungrab(MovingObject& object, Direction dir) +{ Rock::ungrab(object, dir); - m_sprite->set_action("breaking", 1); + set_action("breaking", 1); counter = 0; //remove in update() } diff --git a/src/object/shard.cpp b/src/object/shard.cpp index 68a6631fa66..228c31dda61 100644 --- a/src/object/shard.cpp +++ b/src/object/shard.cpp @@ -39,7 +39,7 @@ Shard::Shard(const Vector& pos, const Vector& velocity) : { m_physic.enable_gravity(true); m_physic.set_velocity(velocity); - m_sprite->set_action("default"); + set_action("default"); SoundManager::current()->preload("sounds/crystallo-shardhit.ogg"); } diff --git a/src/object/skull_tile.cpp b/src/object/skull_tile.cpp index 8d18faf9823..acf85cd0a3c 100644 --- a/src/object/skull_tile.cpp +++ b/src/object/skull_tile.cpp @@ -91,7 +91,7 @@ SkullTile::update(float dt_sec) } m_col.set_movement(physic.get_movement(dt_sec)); } else if (hit) { - m_sprite->set_action("mad", -1); + set_action("mad", -1); if (timer.check()) { falling = true; physic.enable_gravity(true); @@ -101,7 +101,7 @@ SkullTile::update(float dt_sec) timer.start(FALLTIME); } } else { - m_sprite->set_action("normal", -1); + set_action("normal", -1); timer.stop(); } hit = false; diff --git a/src/object/torch.cpp b/src/object/torch.cpp index 0235316c9f6..26ea66d0322 100644 --- a/src/object/torch.cpp +++ b/src/object/torch.cpp @@ -24,31 +24,22 @@ #include "util/reader_mapping.hpp" Torch::Torch(const ReaderMapping& reader) : - MovingObject(reader), + MovingSprite(reader, "images/objects/torch/torch1.sprite"), ExposedObject(this), m_light_color(1.f, 1.f, 1.f), - m_torch(), m_flame(SpriteManager::current()->create("images/objects/torch/flame.sprite")), m_flame_glow(SpriteManager::current()->create("images/objects/torch/flame_glow.sprite")), m_flame_light(SpriteManager::current()->create("images/objects/torch/flame_light.sprite")), m_burning(true), - sprite_name("images/objects/torch/torch1.sprite"), m_layer(0), m_flip(NO_FLIP) { - reader.get("x", m_col.m_bbox.get_left()); - reader.get("y", m_col.m_bbox.get_top()); - - reader.get("sprite", sprite_name); reader.get("burning", m_burning, true); reader.get("layer", m_layer, 0); std::vector vColor; if (!reader.get("color", vColor)) vColor = { 1.f, 1.f, 1.f }; - m_torch = SpriteManager::current()->create(sprite_name); - m_col.m_bbox.set_size(static_cast(m_torch->get_width()), - static_cast(m_torch->get_height())); m_flame_glow->set_blend(Blend::ADD); m_flame_light->set_blend(Blend::ADD); if (vColor.size() >= 3) @@ -78,7 +69,7 @@ Torch::draw(DrawingContext& context) m_flame_glow->set_action(m_light_color.greyscale() >= 1.f ? "default" : "greyscale"); } - m_torch->draw(context.color(), get_pos(), m_layer - 1, m_flip); + m_sprite->draw(context.color(), get_pos(), m_layer - 1, m_flip); } void @@ -100,21 +91,22 @@ Torch::collision(GameObject& other, const CollisionHit& ) ObjectSettings Torch::get_settings() { - ObjectSettings result = MovingObject::get_settings(); + ObjectSettings result = MovingSprite::get_settings(); result.add_bool(_("Burning"), &m_burning, "burning", true); - result.add_sprite(_("Sprite"), &sprite_name, "sprite", std::string("images/objects/torch/torch1.sprite")); result.add_int(_("Layer"), &m_layer, "layer", 0); result.add_color(_("Color"), &m_light_color, "color", Color::WHITE); - result.reorder({"sprite", "layer", "color", "x", "y"}); + result.reorder({"burning", "sprite", "layer", "color", "x", "y"}); return result; } -void Torch::after_editor_set() +void +Torch::after_editor_set() { - m_torch = SpriteManager::current()->create(sprite_name); + MovingSprite::after_editor_set(); + m_flame->set_color(m_light_color); m_flame_glow->set_color(m_light_color); m_flame_light->set_color(m_light_color); diff --git a/src/object/torch.hpp b/src/object/torch.hpp index 6dd340b4c19..13f0d828ee6 100644 --- a/src/object/torch.hpp +++ b/src/object/torch.hpp @@ -18,17 +18,15 @@ #ifndef HEADER_SUPERTUX_OBJECT_TORCH_HPP #define HEADER_SUPERTUX_OBJECT_TORCH_HPP +#include "object/moving_sprite.hpp" #include "squirrel/exposed_object.hpp" + #include "scripting/torch.hpp" -#include "sprite/sprite_ptr.hpp" -#include "supertux/moving_object.hpp" -#include "video/flip.hpp" class ReaderMapping; -class Torch final : - public MovingObject, - public ExposedObject +class Torch final : public MovingSprite, + public ExposedObject { public: Torch(const ReaderMapping& reader); diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index 3d4e039e314..f0b318ed0dc 100644 --- a/src/object/trampoline.cpp +++ b/src/object/trampoline.cpp @@ -46,7 +46,7 @@ Trampoline::Trampoline(const ReaderMapping& mapping) : m_sprite_name = "images/objects/trampoline/trampoline_fix.sprite"; m_default_sprite_name = m_sprite_name; m_sprite = SpriteManager::current()->create(m_sprite_name); - m_sprite->set_action("normal"); + set_action("normal"); } } } @@ -59,7 +59,7 @@ Trampoline::Trampoline(const Vector& pos, bool port) : if (!port) { m_sprite_name = "images/objects/trampoline/trampoline_fix.sprite"; m_sprite = SpriteManager::current()->create(m_sprite_name); - m_sprite->set_action("normal"); + set_action("normal"); } } @@ -67,7 +67,7 @@ void Trampoline::update(float dt_sec) { if (m_sprite->animation_done()) { - m_sprite->set_action("normal"); + set_action("normal"); } Rock::update(dt_sec); @@ -111,7 +111,7 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit) } player->get_physic().set_velocity_y(vy); SoundManager::current()->play(TRAMPOLINE_SOUND, get_pos()); - m_sprite->set_action("swinging", 1); + set_action("swinging", 1); return FORCE_MOVE; } } @@ -124,7 +124,7 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit) vy = VY_INITIAL; walking_badguy->set_velocity_y(vy); SoundManager::current()->play(TRAMPOLINE_SOUND, get_pos()); - m_sprite->set_action("swinging", 1); + set_action("swinging", 1); return FORCE_MOVE; } } @@ -134,7 +134,8 @@ Trampoline::collision(GameObject& other, const CollisionHit& hit) } void -Trampoline::grab(MovingObject& object, const Vector& pos, Direction dir) { +Trampoline::grab(MovingObject& object, const Vector& pos, Direction dir) +{ m_sprite->set_animation_loops(0); Rock::grab(object, pos, dir); } diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index 08fcaae4963..d9460511a1f 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -41,7 +41,8 @@ UnstableTile::UnstableTile(const ReaderMapping& mapping) : m_alpha(1.f), m_original_pos(m_col.get_pos()) { - m_sprite->set_action("normal"); + set_action("normal"); + physic.set_gravity_modifier(.98f); physic.enable_gravity(false); } @@ -151,7 +152,7 @@ UnstableTile::revive() m_col.set_movement(Vector(0.0f, 0.0f)); m_revive_timer.stop(); m_respawn.reset(new FadeHelper(&m_alpha, FADE_IN_TIME, 1.f)); - m_sprite->set_action("normal"); + set_action("normal"); } void diff --git a/src/object/water_drop.cpp b/src/object/water_drop.cpp index 36f5f7a33d4..e006048c116 100644 --- a/src/object/water_drop.cpp +++ b/src/object/water_drop.cpp @@ -49,7 +49,7 @@ WaterDrop::collision_solid(const CollisionHit& hit) wd_state = WDS_SPLASH; physic.enable_gravity(false); SoundManager::current()->play("sounds/splash.ogg", get_pos()); - m_sprite->set_action("splash", 1); + set_action("splash", 1); // spawn water particles for (int i = 50; i; i--) { diff --git a/src/object/weak_block.cpp b/src/object/weak_block.cpp index 3dd541c02c7..5a1bc01cf2d 100644 --- a/src/object/weak_block.cpp +++ b/src/object/weak_block.cpp @@ -36,14 +36,14 @@ WeakBlock::WeakBlock(const ReaderMapping& mapping) : linked(true), lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")) { - m_sprite->set_action("normal"); + set_action("normal"); //Check if this weakblock destroys adjacent weakblocks if (mapping.get("linked", linked)){ if (! linked){ m_default_sprite_name = "images/objects/weak_block/meltbox.sprite"; m_sprite_name = m_default_sprite_name; m_sprite = SpriteManager::current()->create(m_sprite_name); - m_sprite->set_action("normal"); + set_action("normal"); } } @@ -137,7 +137,7 @@ WeakBlock::update(float ) if (m_sprite->animation_done()) { state = STATE_DISINTEGRATING; - m_sprite->set_action("disintegrating", 1); + set_action("disintegrating", 1); spreadHit(); set_group(COLGROUP_DISABLED); lightsprite = SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-tiny.sprite"); @@ -173,7 +173,7 @@ WeakBlock::startBurning() { if (state != STATE_NORMAL) return; state = STATE_BURNING; - m_sprite->set_action("burning", 1); + set_action("burning", 1); // FIXME: Not hardcode these sounds? if (m_sprite_name == "images/objects/weak_block/meltbox.sprite") { SoundManager::current()->play("sounds/sizzle.ogg", get_pos());