Skip to content

Commit

Permalink
option for roof sleeping crystallos
Browse files Browse the repository at this point in the history
fix bug with Direction::AUTO in the editor for scrystallo and rcrystallo
  • Loading branch information
Narre committed Aug 9, 2023
1 parent e76add2 commit 25956a8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/badguy/rcrystallo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ RCrystallo::after_editor_set()
{
WalkingBadguy::after_editor_set();

set_action("roof", m_start_dir);
set_action("roof", m_start_dir == Direction::AUTO ? Direction::LEFT : m_start_dir);
update_hitbox();
}

Expand Down
20 changes: 16 additions & 4 deletions src/badguy/scrystallo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
SCrystallo::SCrystallo(const ReaderMapping& reader) :
WalkingBadguy(reader, "images/creatures/crystallo/crystallo.sprite", "sleeping-left", "sleeping-right"),
m_state(SCRYSTALLO_SLEEPING),
m_roof(),
m_radius(),
m_range(),
m_radius_anchor()
{
walk_speed = 80;
max_drop_height = 16;
reader.get("roof", m_roof, false);
reader.get("radius", m_radius, 100.0f);
reader.get("range", m_range, 250.0f);
SoundManager::current()->preload("sounds/crystallo-pop.ogg");
Expand All @@ -41,8 +43,16 @@ SCrystallo::SCrystallo(const ReaderMapping& reader) :
void
SCrystallo::initialize()
{
if (m_roof)
{
m_physic.set_gravity_modifier(-Sector::get().get_gravity());
FlipLevelTransformer::transform_flip(m_flip);
}
else
{
m_physic.set_gravity_modifier(Sector::get().get_gravity());
}
m_state = SCRYSTALLO_SLEEPING;
m_physic.enable_gravity(false);
set_action("sleeping", m_dir);
}

Expand All @@ -53,6 +63,7 @@ SCrystallo::get_settings()

result.add_float(_("Walk Radius"), &m_radius, "radius", 100.0f);
result.add_float(_("Awakening Radius"), &m_range, "range", 250.0f);
result.add_bool(_("Roof-attached"), &m_roof, "roof", false);

result.reorder({ "radius", "range", "direction", "x", "y" });

Expand Down Expand Up @@ -120,7 +131,6 @@ SCrystallo::active_update(float dt_sec)
return;
}

m_physic.enable_gravity(true);
m_physic.set_velocity_y(-250.f);
WalkingBadguy::initialize();
set_action(m_dir == Direction::LEFT ? "jumping-left" : "jumping-right", -1);
Expand Down Expand Up @@ -158,7 +168,6 @@ SCrystallo::collision_squished(GameObject& object)
{
set_action(m_dir == Direction::LEFT ? "shattered-left" : "shattered-right", /* loops = */ -1, ANCHOR_BOTTOM);
kill_squished(object);
m_physic.enable_gravity(true);
m_physic.set_velocity_x(0.0);
m_physic.set_acceleration_x(0.0);
return true;
Expand All @@ -175,7 +184,9 @@ SCrystallo::after_editor_set()
{
WalkingBadguy::after_editor_set();

set_action("sleeping", m_start_dir);
if ((m_roof && m_flip == NO_FLIP) || (!m_roof && m_flip == VERTICAL_FLIP))
FlipLevelTransformer::transform_flip(m_flip);
set_action("sleeping", m_start_dir == Direction::AUTO ? Direction::LEFT : m_start_dir);
update_hitbox();
}

Expand All @@ -186,6 +197,7 @@ SCrystallo::on_flip(float height)

if (m_state == SCRYSTALLO_SLEEPING || m_state == SCRYSTALLO_WAKING)
{
m_physic.set_gravity_modifier(-m_physic.get_gravity_modifier());
FlipLevelTransformer::transform_flip(m_flip);
}
else
Expand Down
3 changes: 3 additions & 0 deletions src/badguy/scrystallo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ class SCrystallo final : public WalkingBadguy
SCrystalloState m_state;

private:
bool m_roof;
float m_radius;
float m_range;
Vector m_radius_anchor;


private:
SCrystallo(const SCrystallo&) = delete;
SCrystallo& operator=(const SCrystallo&) = delete;
Expand Down
2 changes: 2 additions & 0 deletions src/supertux/physic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class Physic final
/** Set gravity modifier factor to apply to object when enabled */
void set_gravity_modifier(float modifier) { gravity_modifier = modifier; }

float get_gravity_modifier() { return gravity_modifier; }

Vector get_movement(float dt_sec);

private:
Expand Down

0 comments on commit 25956a8

Please sign in to comment.