Skip to content

Commit

Permalink
Add a flip-action option for sprite actions (#2558)
Browse files Browse the repository at this point in the history
This PR adds a "flip-action" option for sprite actions. It's a vertical version of the existing "mirror-action", which is used to remove the need for sprite images to be stored twice, once for each direction. This does the same for up and down.
As a result, UP images were removed for ispy, and replaced with flip-actions of down.
  • Loading branch information
Narre authored Aug 2, 2023
1 parent dedfdb3 commit b1844bd
Show file tree
Hide file tree
Showing 20 changed files with 145 additions and 123 deletions.
46 changes: 26 additions & 20 deletions data/images/creatures/crystallo/rcrystallo.sprite
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(supertux-sprite
(action
(name "left")
(name "left-upright")
(fps 14)
(hitbox 8 1 32 25)
(images "crystallo-left-0.png"
Expand All @@ -10,34 +10,39 @@
"crystallo-left-4.png"
"crystallo-left-5.png"
"crystallo-left-6.png"
"crystallo-left-7.png"))

"crystallo-left-7.png")
)
(action
(name "left")
(hitbox 8 1 32 25)
(flip-action "left-upright")
)
(action
(name "right")
(fps 14)
(hitbox 8 1 32 25)
(mirror-action "left"))

(mirror-action "left")
)
(action
(name "slowdown-left")
(fps 5)
(hitbox 8 1 32 25)
(clone-action "left"))

(clone-action "left")
)
(action
(name "slowdown-right")
(fps 5)
(hitbox 8 1 32 25)
(clone-action "right"))

(clone-action "right")
)
(action
(name "shattered-left")
(images "shattered-left.png"))

(images "shattered-left.png")
)
(action
(name "shattered-right")
(mirror-action "shattered-left"))

(mirror-action "shattered-left")
)
(action
(name "detected-left")
(fps 15)
Expand All @@ -54,22 +59,23 @@
"crystallo-fall-6.png"
"crystallo-fall-8.png"
"crystallo-fall-9.png"
"crystallo-fall-8.png"))

"crystallo-fall-8.png")
)
(action
(name "detected-right")
(fps 15)
(hitbox 35 2 20 35)
(loops 1)
(mirror-action "detected-left"))

(mirror-action "detected-left")
)
(action
(name "fall-left")
(hitbox 45 2 20 35)
(images "crystallo-fall-10.png"))

(images "crystallo-fall-10.png")
)
(action
(name "fall-right")
(hitbox 35 2 20 35)
(mirror-action "fall-left"))
(mirror-action "fall-left")
)
)
6 changes: 2 additions & 4 deletions data/images/creatures/dart/dart.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
(hitbox 6 10 7 12)
(images "flying-down.png")
)
;; This will never show up since the editor uses the flipped down texture
;; But it prevents warnings for missing actions
(action
(name "editor-up")
(name "flying-up")
(hitbox 6 10 7 12)
(images "flying-down.png")
(flip-action "flying-down")
)
)
17 changes: 10 additions & 7 deletions data/images/creatures/darttrap/darttrap.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@
"down-idle.png"
)
)
;; This will never show up since the editor uses the flipped down texture
;; But it prevents warnings for missing actions
(action
(hitbox 13 21 54 11)
(name "editor-up")
(images "down-1.png")
)
(action
(hitbox 21 13 11 54)
(name "idle-right")
(loops 1)
(mirror-action "idle-left")
)
(action
(hitbox 13 18 54 11)
(name "idle-up")
(flip-action "idle-down")
)
(action
(hitbox 21 13 11 54)
(name "loading-left")
Expand Down Expand Up @@ -70,4 +68,9 @@
(fps 10)
(mirror-action "loading-left")
)
(action
(hitbox 13 18 54 11)
(name "loading-up")
(flip-action "loading-down")
)
)
Binary file removed data/images/objects/ispy/i-hiding-up.png
Binary file not shown.
Binary file removed data/images/objects/ispy/i-idle-up.png
Binary file not shown.
Binary file removed data/images/objects/ispy/i-shaking-up.png
Binary file not shown.
Binary file removed data/images/objects/ispy/i-shaking2-up.png
Binary file not shown.
Binary file removed data/images/objects/ispy/i-shaking3-up.png
Binary file not shown.
Binary file removed data/images/objects/ispy/i-showing1-up.png
Binary file not shown.
Binary file removed data/images/objects/ispy/i-showing2-up.png
Binary file not shown.
Binary file removed data/images/objects/ispy/i-showing3-up.png
Binary file not shown.
49 changes: 4 additions & 45 deletions data/images/objects/ispy/ispy.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -144,63 +144,22 @@
(action
(name "idle-up")
(hitbox 0 0 34 28)
(fps 14)
(images
"i-idle-up.png"
)
(flip-action "idle-down")
)
(action
(name "alert-up")
(hitbox 0 0 34 28)
(fps 14)
(images
"i-idle-up.png"
"i-idle-up.png"
"i-idle-up.png"
"i-idle-up.png"
"i-shaking-up.png"
"i-shaking2-up.png"
"i-shaking-up.png"
"i-shaking2-up.png"
"i-shaking-up.png"
"i-shaking2-up.png"
"i-shaking-up.png"
"i-shaking2-up.png"
"i-shaking3-up.png"
"i-showing2-up.png"
"i-showing1-up.png"
"i-hiding-up.png"
)
(flip-action "alert-down")
)
(action
(name "hiding-up")
(hitbox 0 0 34 28)
(fps 14)
(images
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
"i-hiding-up.png"
)
(flip-action "hiding-down")
)
(action
(name "showing-up")
(hitbox 0 0 34 28)
(fps 14)
(images
"i-hiding-up.png"
"i-showing1-up.png"
"i-showing2-up.png"
"i-showing3-up.png"
"i-idle-up.png"
"i-idle-up.png"
)
(flip-action "showing-down")
)
)

5 changes: 0 additions & 5 deletions src/badguy/badguy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ class BadGuy : public MovingSprite,
return "images/objects/water_drop/water_drop.sprite";
}

void set_sprite_action(const std::string& action, int loops = 1)
{
set_action(action, loops);
}

/** Returns true if the badguy can currently be affected by wind */
virtual bool can_be_affected_by_wind() const;

Expand Down
17 changes: 8 additions & 9 deletions src/badguy/dart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ Dart::Dart(const ReaderMapping& reader) :
SoundManager::current()->preload("sounds/stomp.wav");
}

Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_, const std::string& sprite, Flip flip) :
Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_, const std::string& sprite) :
BadGuy(pos, d, sprite),
parent(parent_),
sound_source()
{
m_physic.enable_gravity(false);
m_countMe = false;
m_flip = flip;
SoundManager::current()->preload(DART_SOUND);
SoundManager::current()->preload("sounds/darthit.wav");
SoundManager::current()->preload("sounds/stomp.wav");
Expand All @@ -67,8 +66,7 @@ Dart::initialize()
{
m_physic.set_velocity_x(m_dir == Direction::LEFT ? -::DART_SPEED : m_dir == Direction::RIGHT ? ::DART_SPEED : 0);
m_physic.set_velocity_y(m_dir == Direction::UP ? -::DART_SPEED : m_dir == Direction::DOWN ? ::DART_SPEED : 0);
set_action("flying", m_dir == Direction::UP ? Direction::DOWN : m_dir);
if (m_dir == Direction::UP) m_flip = VERTICAL_FLIP;
set_action("flying", m_dir);
}

void
Expand Down Expand Up @@ -147,18 +145,15 @@ Dart::play_looping_sounds()
}

void
Dart::after_editor_set()
Dart::set_flip(Flip flip)
{
BadGuy::after_editor_set();
if ((m_dir == Direction::UP && m_flip == NO_FLIP) || (m_dir == Direction::DOWN && m_flip == VERTICAL_FLIP))
FlipLevelTransformer::transform_flip(m_flip);
m_flip = flip;
}

void
Dart::on_flip(float height)
{
BadGuy::on_flip(height);
FlipLevelTransformer::transform_flip(m_flip);
if (m_dir == Direction::UP)
{
m_dir = Direction::DOWN;
Expand All @@ -169,6 +164,10 @@ Dart::on_flip(float height)
m_dir = Direction::UP;
m_physic.set_velocity_y(-::DART_SPEED);
}
else
{
FlipLevelTransformer::transform_flip(m_flip);
}
}

/* EOF */
5 changes: 3 additions & 2 deletions src/badguy/dart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Dart final : public BadGuy
{
public:
Dart(const ReaderMapping& reader);
Dart(const Vector& pos, Direction d, const BadGuy* parent, const std::string& sprite = "images/creatures/dart/dart.sprite", Flip flip = NO_FLIP);
Dart(const Vector& pos, Direction d, const BadGuy* parent, const std::string& sprite = "images/creatures/dart/dart.sprite");

virtual void initialize() override;
virtual void activate() override;
Expand All @@ -51,9 +51,10 @@ class Dart final : public BadGuy
virtual void stop_looping_sounds() override;
virtual void play_looping_sounds() override;

virtual void after_editor_set() override;
virtual void on_flip(float height) override;

void set_flip(Flip flip);

protected:
const BadGuy* parent; /**< collisions with this BadGuy will be ignored */
std::unique_ptr<SoundSource> sound_source; /**< SoundSource for ambient sound */
Expand Down
28 changes: 14 additions & 14 deletions src/badguy/darttrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ DartTrap::DartTrap(const ReaderMapping& reader) :
void
DartTrap::initialize()
{
set_action("idle", m_dir == Direction::UP ? Direction::DOWN : m_dir);
if (m_dir == Direction::UP) m_flip = VERTICAL_FLIP;
set_action("idle", m_dir);
}

void
Expand Down Expand Up @@ -100,14 +99,16 @@ void
DartTrap::load()
{
m_state = LOADING;
set_action("loading", m_dir == Direction::UP ? Direction::DOWN : m_dir, 1);
set_action("loading", m_dir, 1);
}

void
DartTrap::fire()
{
SoundManager::current()->play("sounds/dartfire.wav", get_pos());
Dart &dart = Sector::get().add<Dart>(Vector(0.f, 0.f), m_dir, this, m_dart_sprite, m_flip);
Dart &dart = Sector::get().add<Dart>(Vector(0.f, 0.f), m_dir, this, m_dart_sprite);
if(m_dir == Direction::LEFT || m_dir == Direction::RIGHT)
dart.set_flip(m_flip);

Vector pos;
switch (m_dir)
Expand All @@ -133,7 +134,7 @@ DartTrap::fire()
dart.set_pos(pos);

m_state = IDLE;
set_action("idle", m_dir == Direction::UP ? Direction::DOWN : m_dir);
set_action("idle", m_dir);
}

ObjectSettings
Expand All @@ -152,23 +153,22 @@ DartTrap::get_settings()
return result;
}

void
DartTrap::after_editor_set()
{
BadGuy::after_editor_set();
if ((m_dir == Direction::UP && m_flip == NO_FLIP) || (m_dir == Direction::DOWN && m_flip == VERTICAL_FLIP))
FlipLevelTransformer::transform_flip(m_flip);
}

void
DartTrap::on_flip(float height)
{
BadGuy::on_flip(height);
FlipLevelTransformer::transform_flip(m_flip);
if (m_dir == Direction::UP)
{
m_dir = Direction::DOWN;
set_action(m_state == IDLE ? "idle" : "loading", m_dir, 1);
}
else if (m_dir == Direction::DOWN)
{
m_dir = Direction::UP;
set_action(m_state == IDLE ? "idle" : "loading", m_dir, 1);
}
else
FlipLevelTransformer::transform_flip(m_flip);
}

/* EOF */
1 change: 0 additions & 1 deletion src/badguy/darttrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class DartTrap final : public BadGuy

virtual ObjectSettings get_settings() override;

virtual void after_editor_set() override;
virtual void on_flip(float height) override;

protected:
Expand Down
1 change: 0 additions & 1 deletion src/badguy/rcrystallo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ void
RCrystallo::draw(DrawingContext& context)
{
context.push_transform();
context.set_flip(context.get_flip() ^ (state == RCRYSTALLO_ROOF ? VERTICAL_FLIP : NO_FLIP));
m_sprite->draw(context.color(), get_pos(), m_layer);
context.pop_transform();
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripting/badguy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void
BadGuy::set_action(const std::string& action, int loops)
{
SCRIPT_GUARD_VOID;
object.set_sprite_action(action, loops);
object.set_action(action, loops);
}

void
Expand Down
Loading

0 comments on commit b1844bd

Please sign in to comment.