From 0fd62d3a9d86d20f84771f5518f35bf85d49624e Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Sun, 8 Dec 2024 14:02:32 -0500 Subject: [PATCH 1/8] Refactor StickyBadguy to support other sprites Bad logic anyway, will be improved later. --- src/badguy/badguy.hpp | 19 +++++++++++-------- src/object/sticky_object.cpp | 9 +++++---- src/object/sticky_object.hpp | 8 ++++++-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index ca3578e0e24..8861dd12f91 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_LIGHT_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_LIGHT_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_LIGHT_SPRITE_NAME); /** Called when the badguy is drawn. The default implementation simply draws the badguy sprite on screen */ diff --git a/src/object/sticky_object.cpp b/src/object/sticky_object.cpp index f3b9a553469..1885e1b457d 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 f177d74bb3b..bfa2f079576 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); From 67d1e222e1e487ef78fa556fdaf0b00dba71b2a0 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Sun, 8 Dec 2024 14:02:48 -0500 Subject: [PATCH 2/8] Make Corrupted granito, mole, and root sapling sticky --- src/badguy/corrupted_granito.cpp | 2 +- src/badguy/corrupted_granito.hpp | 3 ++- src/badguy/mole.cpp | 3 ++- src/badguy/mole.hpp | 3 ++- src/badguy/root_sapling.cpp | 4 ++-- src/badguy/root_sapling.hpp | 3 ++- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/badguy/corrupted_granito.cpp b/src/badguy/corrupted_granito.cpp index 8e3522c4c56..f10bdc8ff02 100644 --- a/src/badguy/corrupted_granito.cpp +++ b/src/badguy/corrupted_granito.cpp @@ -25,7 +25,7 @@ static const float HORIZONTAL_SPEED = 220; /**< X-speed when jumping. */ static const float VERTICAL_SPEED = -450; /**< Y-speed when jumping. */ CorruptedGranito::CorruptedGranito(const ReaderMapping& reader) : - BadGuy(reader, "images/creatures/granito/corrupted/corrupted_granito.sprite"), + StickyBadguy(reader, "images/creatures/granito/corrupted/corrupted_granito.sprite"), recover_timer(), state() { diff --git a/src/badguy/corrupted_granito.hpp b/src/badguy/corrupted_granito.hpp index d78a98a1e52..c397e47e8eb 100644 --- a/src/badguy/corrupted_granito.hpp +++ b/src/badguy/corrupted_granito.hpp @@ -18,9 +18,10 @@ #define HEADER_SUPERTUX_BADGUY_CORRUPTEDGRANITO_HPP #include "badguy/badguy.hpp" +#include "object/sticky_object.hpp" /** An "Evil" Granito. */ -class CorruptedGranito final : public BadGuy +class CorruptedGranito final : public StickyBadguy { public: enum Type { diff --git a/src/badguy/mole.cpp b/src/badguy/mole.cpp index 8d89e7287ce..f04a34a0c32 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(), diff --git a/src/badguy/mole.hpp b/src/badguy/mole.hpp index e9aa43f1b63..beeffab7a54 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 3deeea88e9a..3e5b335b591 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) { diff --git a/src/badguy/root_sapling.hpp b/src/badguy/root_sapling.hpp index d84c63b27f7..5a070eae165 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); From 9e0407185a62a1a1d3f46e0993b7e7a4ccfd8cb2 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Sun, 8 Dec 2024 14:07:49 -0500 Subject: [PATCH 3/8] Fix default constructor typo --- src/badguy/badguy.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 8861dd12f91..08a6fb6a584 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -50,13 +50,13 @@ class BadGuy : public MovingSprite, 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 = BADGUY_LIGHT_SPRITE_NAME, - const std::string& ice_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 = BADGUY_LIGHT_SPRITE_NAME, - const std::string& ice_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 = BADGUY_LIGHT_SPRITE_NAME, - const std::string& ice_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 */ From d0aa8d25ecaf76a124052b243e0e7060666d92b5 Mon Sep 17 00:00:00 2001 From: Carsten Wirtz Date: Sun, 8 Dec 2024 21:58:16 +0100 Subject: [PATCH 4/8] Update corrupted_granito_big.cpp [ci skip] --- src/badguy/corrupted_granito_big.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/badguy/corrupted_granito_big.cpp b/src/badguy/corrupted_granito_big.cpp index 5d98bd30f2e..266f7f96365 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(), From 03dd5c79a5a069d33b7cf4f9f61a6d409cf8be2e Mon Sep 17 00:00:00 2001 From: Carsten Wirtz Date: Sun, 8 Dec 2024 22:00:18 +0100 Subject: [PATCH 5/8] Update corrupted_granito_big.hpp --- src/badguy/corrupted_granito_big.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/badguy/corrupted_granito_big.hpp b/src/badguy/corrupted_granito_big.hpp index c1723a54fd4..0025c4bdaec 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); From 40ad61750784f7b0dc0894d607d3061eeeccef94 Mon Sep 17 00:00:00 2001 From: Carsten Wirtz Date: Sun, 8 Dec 2024 22:01:52 +0100 Subject: [PATCH 6/8] Revert "stickyness" in corrupted_granito.cpp [ci skip] --- src/badguy/corrupted_granito.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/badguy/corrupted_granito.cpp b/src/badguy/corrupted_granito.cpp index f10bdc8ff02..8e3522c4c56 100644 --- a/src/badguy/corrupted_granito.cpp +++ b/src/badguy/corrupted_granito.cpp @@ -25,7 +25,7 @@ static const float HORIZONTAL_SPEED = 220; /**< X-speed when jumping. */ static const float VERTICAL_SPEED = -450; /**< Y-speed when jumping. */ CorruptedGranito::CorruptedGranito(const ReaderMapping& reader) : - StickyBadguy(reader, "images/creatures/granito/corrupted/corrupted_granito.sprite"), + BadGuy(reader, "images/creatures/granito/corrupted/corrupted_granito.sprite"), recover_timer(), state() { From fe9d8143ea915dd96e7886b108033aae3469826a Mon Sep 17 00:00:00 2001 From: Carsten Wirtz Date: Sun, 8 Dec 2024 22:02:31 +0100 Subject: [PATCH 7/8] Revert "stickyness" in corrupted_granito.hpp --- src/badguy/corrupted_granito.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/badguy/corrupted_granito.hpp b/src/badguy/corrupted_granito.hpp index c397e47e8eb..d78a98a1e52 100644 --- a/src/badguy/corrupted_granito.hpp +++ b/src/badguy/corrupted_granito.hpp @@ -18,10 +18,9 @@ #define HEADER_SUPERTUX_BADGUY_CORRUPTEDGRANITO_HPP #include "badguy/badguy.hpp" -#include "object/sticky_object.hpp" /** An "Evil" Granito. */ -class CorruptedGranito final : public StickyBadguy +class CorruptedGranito final : public BadGuy { public: enum Type { From 265db3758f3c449fa120a6cade3f86f0e43012ff Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Mon, 9 Dec 2024 03:19:49 -0500 Subject: [PATCH 8/8] Make stickyness sticky I wasn't calling the actual sticky related functions like an idiot. I have discussed that this can be refactored one day anyway, so it's whatever... --- src/badguy/corrupted_granito_big.cpp | 5 +++-- src/badguy/mole.cpp | 3 ++- src/badguy/root_sapling.cpp | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/badguy/corrupted_granito_big.cpp b/src/badguy/corrupted_granito_big.cpp index 266f7f96365..d570950185f 100644 --- a/src/badguy/corrupted_granito_big.cpp +++ b/src/badguy/corrupted_granito_big.cpp @@ -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/mole.cpp b/src/badguy/mole.cpp index f04a34a0c32..b1af87f89c8 100644 --- a/src/badguy/mole.cpp +++ b/src/badguy/mole.cpp @@ -97,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/root_sapling.cpp b/src/badguy/root_sapling.cpp index 3e5b335b591..3d95902662e 100644 --- a/src/badguy/root_sapling.cpp +++ b/src/badguy/root_sapling.cpp @@ -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);