diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index ca3578e0e2..08a6fb6a58 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -27,6 +27,9 @@ enum class Direction; class Player; class Bullet; +static const char* BADGUY_LIGHT_SPRITE_NAME = "images/objects/lightmap_light/lightmap_light-medium.sprite"; +static const char* BADGUY_ICE_SPRITE_NAME = "images/creatures/overlays/iceoverlay/iceoverlay.sprite"; + /** * Base class for moving sprites that can hurt the Player. @@ -43,17 +46,17 @@ class BadGuy : public MovingSprite, public: BadGuy(const Vector& pos, const std::string& sprite_name, int layer = LAYER_OBJECTS, - const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite", - const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite"); + const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME, + const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME); BadGuy(const Vector& pos, Direction direction, const std::string& sprite_name, int layer = LAYER_OBJECTS, - const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite", - const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite"); + const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME, + const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME); BadGuy(const ReaderMapping& reader, const std::string& sprite_name, int layer = LAYER_OBJECTS, - const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite", - const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite"); + const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME, + const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME); BadGuy(const ReaderMapping& reader, const std::string& sprite_name, Direction default_direction, int layer = LAYER_OBJECTS, - const std::string& light_sprite_name = "images/objects/lightmap_light/lightmap_light-medium.sprite", - const std::string& ice_sprite_name = "images/creatures/overlays/iceoverlay/iceoverlay.sprite"); + const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME, + const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME); /** Called when the badguy is drawn. The default implementation simply draws the badguy sprite on screen */ diff --git a/src/badguy/corrupted_granito_big.cpp b/src/badguy/corrupted_granito_big.cpp index 5d98bd30f2..d570950185 100644 --- a/src/badguy/corrupted_granito_big.cpp +++ b/src/badguy/corrupted_granito_big.cpp @@ -31,7 +31,7 @@ static const float CRACK_TIME = 1.f; // seconds static const float SHAKE_TIME = 0.1f; // seconds CorruptedGranitoBig::CorruptedGranitoBig(const ReaderMapping& reader) : - BadGuy(reader, "images/creatures/granito/corrupted/big/rock_mine.sprite", LAYER_OBJECTS-3), + StickyBadguy(reader, "images/creatures/granito/corrupted/big/rock_mine.sprite", LAYER_OBJECTS-3), m_state(STATE_READY), m_crack_timer(), m_shake_timer(), @@ -49,7 +49,7 @@ CorruptedGranitoBig::CorruptedGranitoBig(const ReaderMapping& reader) : void CorruptedGranitoBig::initialize() { - BadGuy::initialize(); + StickyBadguy::initialize(); m_state = STATE_READY; set_action("idle", m_dir); @@ -59,7 +59,8 @@ CorruptedGranitoBig::initialize() void CorruptedGranitoBig::active_update(float dt_sec) { - BadGuy::active_update(dt_sec); + if (m_sticky) sticky_update(dt_sec); + StickyBadguy::active_update(dt_sec); if (m_state == STATE_BROKEN) return; diff --git a/src/badguy/corrupted_granito_big.hpp b/src/badguy/corrupted_granito_big.hpp index c1723a54fd..0025c4bdae 100644 --- a/src/badguy/corrupted_granito_big.hpp +++ b/src/badguy/corrupted_granito_big.hpp @@ -18,9 +18,10 @@ #define HEADER_SUPERTUX_BADGUY_CORRUPTED_GRANITO_BIG_HPP #include "badguy/badguy.hpp" +#include "object/sticky_object.hpp" /** Granito, which explodes into shards when player comes close to it. */ -class CorruptedGranitoBig final : public BadGuy +class CorruptedGranitoBig final : public StickyBadguy { public: explicit CorruptedGranitoBig(const ReaderMapping& reader); diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 8d89e7287c..b1af87f89c 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -23,6 +23,7 @@ #include "math/random.hpp" #include "math/util.hpp" #include "object/player.hpp" +#include "object/sticky_object.hpp" #include "sprite/sprite.hpp" #include "supertux/flip_level_transformer.hpp" #include "supertux/sector.hpp" @@ -33,7 +34,7 @@ static const float THROW_INTERVAL = 1; /**< Time between two thrown rocks. */ static const float THROW_VELOCITY = 400; /**< Initial velocity of thrown rocks. */ Mole::Mole(const ReaderMapping& reader) : - BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), + StickyBadguy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING), timer(), throw_timer(), @@ -96,7 +97,8 @@ Mole::throw_rock() void Mole::active_update(float dt_sec) { - BadGuy::active_update(dt_sec); + if (m_sticky) sticky_update(dt_sec); + StickyBadguy::active_update(dt_sec); switch (state) { case PRE_THROWING: diff --git a/src/badguy/mole.hpp b/src/badguy/mole.hpp index e9aa43f1b6..beeffab7a5 100644 --- a/src/badguy/mole.hpp +++ b/src/badguy/mole.hpp @@ -18,8 +18,9 @@ #define HEADER_SUPERTUX_BADGUY_MOLE_HPP #include "badguy/badguy.hpp" +#include "object/sticky_object.hpp" -class Mole final : public BadGuy +class Mole final : public StickyBadguy { public: Mole(const ReaderMapping& ); diff --git a/src/badguy/root_sapling.cpp b/src/badguy/root_sapling.cpp index 3deeea88e9..3d95902662 100644 --- a/src/badguy/root_sapling.cpp +++ b/src/badguy/root_sapling.cpp @@ -31,8 +31,8 @@ static const float ROOT_SAPLING_RANGE = 32.f * 20; static const float ROOT_SAPLING_SPAWN_TIME = 1.35f; RootSapling::RootSapling(const ReaderMapping& reader) : - BadGuy(reader, "images/creatures/mole/corrupted/root_sapling.sprite", Direction::UP, - LAYER_TILES - 15, "images/creatures/mole/corrupted/core_glow/core_glow.sprite"), + StickyBadguy(reader, "images/creatures/mole/corrupted/root_sapling.sprite", Direction::UP, + LAYER_TILES - 15, COLGROUP_MOVING, "images/creatures/mole/corrupted/core_glow/core_glow.sprite"), m_root_timer(), m_dead(false) { @@ -105,6 +105,7 @@ RootSapling::collision_player(Player& player, const CollisionHit& hit) void RootSapling::active_update(float dt_sec) { + if (m_sticky) sticky_update(dt_sec); if (m_dead) return; BadGuy::active_update(dt_sec); diff --git a/src/badguy/root_sapling.hpp b/src/badguy/root_sapling.hpp index d84c63b27f..5a070eae16 100644 --- a/src/badguy/root_sapling.hpp +++ b/src/badguy/root_sapling.hpp @@ -18,10 +18,11 @@ #define HEADER_SUPERTUX_BADGUY_ROOT_SAPLING_HPP #include "badguy/badguy.hpp" +#include "object/sticky_object.hpp" #include "collision/collision_system.hpp" -class RootSapling final : public BadGuy +class RootSapling final : public StickyBadguy { public: RootSapling(const ReaderMapping& reader); diff --git a/src/object/sticky_object.cpp b/src/object/sticky_object.cpp index f3b9a55346..1885e1b457 100644 --- a/src/object/sticky_object.cpp +++ b/src/object/sticky_object.cpp @@ -82,8 +82,9 @@ StickyObject::move_for_owner(MovingObject& object) m_col.set_pos(object.get_pos() + m_displacement_from_owner); } -StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, Direction default_direction, int layer, CollisionGroup collision_group) : - BadGuy(mapping, sprite_name, default_direction, layer), +StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, Direction default_direction, int layer, CollisionGroup collision_group, + const std::string& light_sprite_name, const std::string& ice_sprite_name) : + BadGuy(mapping, sprite_name, default_direction, layer, light_sprite_name, ice_sprite_name), m_sticky(), m_sticking(), m_displacement_from_owner() @@ -91,8 +92,8 @@ StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& spri set_group(collision_group); } -StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, int layer, CollisionGroup collision_group) : - BadGuy(mapping, sprite_name, layer), +StickyBadguy::StickyBadguy(const ReaderMapping& mapping, const std::string& sprite_name, int layer, CollisionGroup collision_group, const std::string& light_sprite_name, const std::string& ice_sprite_name) : + BadGuy(mapping, sprite_name, layer, light_sprite_name, ice_sprite_name), m_sticky(), m_sticking(), m_displacement_from_owner() diff --git a/src/object/sticky_object.hpp b/src/object/sticky_object.hpp index f177d74bb3..bfa2f07957 100644 --- a/src/object/sticky_object.hpp +++ b/src/object/sticky_object.hpp @@ -78,9 +78,13 @@ class StickyBadguy : public BadGuy { public: StickyBadguy(const ReaderMapping& reader, const std::string& sprite_name, Direction default_direction, - int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING); + int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING, + const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME, + const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME); StickyBadguy(const ReaderMapping& reader, const std::string& sprite_name, - int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING); + int layer = LAYER_OBJECTS, CollisionGroup collision_group = COLGROUP_MOVING, + const std::string& light_sprite_name = BADGUY_LIGHT_SPRITE_NAME, + const std::string& ice_sprite_name = BADGUY_ICE_SPRITE_NAME); virtual GameObjectClasses get_class_types() const override { return BadGuy::get_class_types().add(typeid(StickyBadguy)); } virtual void sticky_update(float dt_sec);