Skip to content

Commit

Permalink
Improvements to Dart and DartTrap (#2554)
Browse files Browse the repository at this point in the history
Removes all hard-coded coordinates and offsets in darttrap.cpp, now the darts will always spawn in the centre of the hitbox's height (width for up and down darts). This makes it much more intuitive to create custom sprites for DartTrap. The default sprite is adjusted for this in a way that won't affect existing levels.
It also makes it possible to change the sprite of the dispensed Dart from DartTrap's menu in the editor.
Darts and DartTraps now also support UP and DOWN directions, in addition to LEFT and RIGHT.
This PR also cleans up darttrap.cpp/hpp according to the guidelines, namely adding the m_ prefix to member variables.
  • Loading branch information
Narre authored Jul 31, 2023
1 parent 8652dad commit 2447cd6
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 84 deletions.
18 changes: 15 additions & 3 deletions data/images/creatures/dart/dart.sprite
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
(action
(name "flying-left")
(hitbox 10 6 12 7)
(images "flying.png")
)
(images "flying-left.png")
)
(action
(name "flying-right")
(hitbox 10 6 12 7)
(mirror-action "flying-left")
)
)
(action
(name "flying-down")
(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")
(hitbox 6 10 7 12)
(images "flying-down.png")
)
)
Binary file added data/images/creatures/dart/flying-down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
76 changes: 55 additions & 21 deletions data/images/creatures/darttrap/darttrap.sprite
Original file line number Diff line number Diff line change
@@ -1,39 +1,73 @@
(supertux-sprite
(action
(hitbox 21 13 11 37)
(hitbox 21 13 11 54)
(name "idle-left")
(loops 1)
(images "d3-.png"
"d3-.png"
"d3-.png"
"d3-.png"
"d4.png"
"d-idle.png")
(loops 1)
(images "left-3.png"
"left-3.png"
"left-3.png"
"left-3.png"
"left-4.png"
"left-idle.png"
)
)
(action
(hitbox 13 21 54 11)
(name "idle-down")
(loops 1)
(images "down-3.png"
"down-3.png"
"down-3.png"
"down-3.png"
"down-4.png"
"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 37)
(hitbox 21 13 11 54)
(name "idle-right")
(loops 1)
(loops 1)
(mirror-action "idle-left")
)
(action
(hitbox 21 13 11 37)
(hitbox 21 13 11 54)
(name "loading-left")
(fps 10)
(fps 10)
(images
"left-idle.png"
"left-1.png"
"left-2.png"
"left-3.png"
"left-3.png"
"left-3.png"
"left-3.png"
)
)
(action
(hitbox 13 21 54 11)
(name "loading-down")
(fps 10)
(images
"d-idle.png"
"d1.png"
"d2.png"
"d3-.png"
"d3-.png"
"d3-.png"
"d3-.png"
"down-idle.png"
"down-1.png"
"down-2.png"
"down-3.png"
"down-3.png"
"down-3.png"
"down-3.png"
)
)
(action
(hitbox 21 13 11 37)
(hitbox 21 13 11 54)
(name "loading-right")
(fps 10)
(fps 10)
(mirror-action "loading-left")
)
)
Binary file added data/images/creatures/darttrap/down-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/creatures/darttrap/down-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/creatures/darttrap/down-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/creatures/darttrap/down-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/images/creatures/darttrap/down-idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 2 additions & 2 deletions data/images/engine/editor/objects.stoi
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
(icon "images/creatures/angrystone/charging-0.png"))
(object
(class "darttrap")
(icon "images/creatures/darttrap/d1.png"))
(icon "images/creatures/darttrap/left-1.png"))
(object
(class "dispenser")
(icon "images/creatures/dispenser/cannon_left.png"))
Expand Down Expand Up @@ -192,7 +192,7 @@
(icon "images/creatures/skydive/skydive1.png"))
(object
(class "dart")
(icon "images/creatures/dart/flying.png"))
(icon "images/creatures/dart/flying-left.png"))
)

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

Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_ = nullptr) :
BadGuy(pos, d, "images/creatures/dart/dart.sprite"),
Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_, const std::string& sprite, Flip flip) :
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 @@ -64,8 +65,10 @@ Dart::updatePointers(const GameObject* from_object, GameObject* to_object)
void
Dart::initialize()
{
m_physic.set_velocity_x(m_dir == Direction::LEFT ? -::DART_SPEED : ::DART_SPEED);
set_action("flying", m_dir);
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;
}

void
Expand Down Expand Up @@ -143,11 +146,29 @@ Dart::play_looping_sounds()
}
}

void
Dart::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
Dart::on_flip(float height)
{
BadGuy::on_flip(height);
FlipLevelTransformer::transform_flip(m_flip);
if (m_dir == Direction::UP)
{
m_dir = Direction::DOWN;
m_physic.set_velocity_y(::DART_SPEED);
}
else if (m_dir == Direction::DOWN)
{
m_dir = Direction::UP;
m_physic.set_velocity_y(-::DART_SPEED);
}
}

/* EOF */
3 changes: 2 additions & 1 deletion 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);
Dart(const Vector& pos, Direction d, const BadGuy* parent, const std::string& sprite = "images/creatures/dart/dart.sprite", Flip flip = NO_FLIP);

virtual void initialize() override;
virtual void activate() override;
Expand All @@ -51,6 +51,7 @@ 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;

protected:
Expand Down
Loading

0 comments on commit 2447cd6

Please sign in to comment.