diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 96be13b0d38..d8f721c53fb 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -56,36 +56,36 @@ const float SNOW_EXPLOSIONS_VY = -200; /**< Speed of snowballs */ Yeti::Yeti(const ReaderMapping& reader) : BadGuy(reader, "images/creatures/yeti/yeti.sprite"), - state(), - state_timer(), - safe_timer(), - stomp_count(), - hit_points(), - hud_head(), - left_stand_x(), - right_stand_x(), - left_jump_x(), - right_jump_x(), - fixed_pos(), - hud_icon() + m_state(), + m_state_timer(), + m_safe_timer(), + m_stomp_count(), + m_hit_points(), + m_hud_head(), + m_left_stand_x(), + m_right_stand_x(), + m_left_jump_x(), + m_right_jump_x(), + m_fixed_pos(), + m_hud_icon() { - reader.get("lives", hit_points, INITIAL_HITPOINTS); + reader.get("lives", m_hit_points, INITIAL_HITPOINTS); m_countMe = true; SoundManager::current()->preload("sounds/yeti_gna.wav"); SoundManager::current()->preload("sounds/yeti_roar.wav"); - reader.get("hud-icon", hud_icon, "images/creatures/yeti/hudlife.png"); - hud_head = Surface::from_file(hud_icon); + reader.get("hud-icon", m_hud_icon, "images/creatures/yeti/hudlife.png"); + m_hud_head = Surface::from_file(m_hud_icon); m_allowed_directions = {}; initialize(); - reader.get("fixed-pos", fixed_pos, false); - if (fixed_pos) { - left_stand_x = 80; - right_stand_x = 1140; - left_jump_x = 528; - right_jump_x = 692; + reader.get("fixed-pos", m_fixed_pos, false); + if (m_fixed_pos) { + m_left_stand_x = 80; + m_right_stand_x = 1140; + m_left_jump_x = 528; + m_right_jump_x = 692; } else { recalculate_pos(); } @@ -102,22 +102,22 @@ void Yeti::recalculate_pos() { if (m_dir == Direction::RIGHT) { - left_stand_x = m_col.m_bbox.get_left(); - right_stand_x = left_stand_x + RUN_DISTANCE; + m_left_stand_x = m_col.m_bbox.get_left(); + m_right_stand_x = m_left_stand_x + RUN_DISTANCE; } else { - right_stand_x = m_col.m_bbox.get_left(); - left_stand_x = right_stand_x - RUN_DISTANCE; + m_right_stand_x = m_col.m_bbox.get_left(); + m_left_stand_x = m_right_stand_x - RUN_DISTANCE; } - left_jump_x = left_stand_x + JUMP_SPACE; - right_jump_x = right_stand_x - JUMP_SPACE; + m_left_jump_x = m_left_stand_x + JUMP_SPACE; + m_right_jump_x = m_right_stand_x - JUMP_SPACE; } void Yeti::draw(DrawingContext& context) { // we blink when we are safe - if (safe_timer.started() && size_t(g_game_time * 40) % 2) + if (m_safe_timer.started() && size_t(g_game_time * 40) % 2) return; draw_hit_points(context); @@ -128,15 +128,15 @@ Yeti::draw(DrawingContext& context) void Yeti::draw_hit_points(DrawingContext& context) { - if (hud_head) + if (m_hud_head) { context.push_transform(); context.set_translation(Vector(0, 0)); context.transform().scale = 1.f; - for (int i = 0; i < hit_points; ++i) + for (int i = 0; i < m_hit_points; ++i) { - context.color().draw_surface(hud_head, Vector(BORDER_X + (static_cast(i * hud_head->get_width())), BORDER_Y + 1), LAYER_FOREGROUND1); + context.color().draw_surface(m_hud_head, Vector(BORDER_X + (static_cast(i * m_hud_head->get_width())), BORDER_Y + 1), LAYER_FOREGROUND1); } context.pop_transform(); @@ -146,20 +146,20 @@ Yeti::draw_hit_points(DrawingContext& context) void Yeti::active_update(float dt_sec) { - switch (state) { + switch (m_state) { case JUMP_DOWN: m_physic.set_velocity_x((m_dir==Direction::RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX); break; case RUN: m_physic.set_velocity_x((m_dir==Direction::RIGHT)?+RUN_VX:-RUN_VX); - if (((m_dir == Direction::RIGHT) && (get_pos().x >= right_jump_x)) || ((m_dir == Direction::LEFT) && (get_pos().x <= left_jump_x))) jump_up(); + if (((m_dir == Direction::RIGHT) && (get_pos().x >= m_right_jump_x)) || ((m_dir == Direction::LEFT) && (get_pos().x <= m_left_jump_x))) jump_up(); break; case JUMP_UP: m_physic.set_velocity_x((m_dir==Direction::RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX); - if (((m_dir == Direction::RIGHT) && (get_pos().x >= right_stand_x)) || ((m_dir == Direction::LEFT) && (get_pos().x <= left_stand_x))) be_angry(); + if (((m_dir == Direction::RIGHT) && (get_pos().x >= m_right_stand_x)) || ((m_dir == Direction::LEFT) && (get_pos().x <= m_left_stand_x))) be_angry(); break; case BE_ANGRY: - if (state_timer.check() && on_ground()) { + if (m_state_timer.check() && on_ground()) { m_physic.set_velocity_y(STOMP_VY); set_action("stomp", m_dir); SoundManager::current()->play("sounds/yeti_gna.wav", get_pos()); @@ -167,7 +167,7 @@ Yeti::active_update(float dt_sec) break; case SQUISHED: { - Direction newdir = (int(state_timer.get_timeleft() * SNOW_EXPLOSIONS_FREQUENCY) % 2) ? Direction::LEFT : Direction::RIGHT; + Direction newdir = (int(m_state_timer.get_timeleft() * SNOW_EXPLOSIONS_FREQUENCY) % 2) ? Direction::LEFT : Direction::RIGHT; if (m_dir != newdir && m_dir == Direction::RIGHT) { SoundManager::current()->play("sounds/stomp.wav", get_pos()); add_snow_explosions(); @@ -176,9 +176,9 @@ Yeti::active_update(float dt_sec) m_dir = newdir; set_action("jump", m_dir); } - if (state_timer.check()) { + if (m_state_timer.check()) { BadGuy::kill_fall(); - state = FALLING; + m_state = FALLING; m_physic.set_velocity_y(JUMP_UP_VY / 2); // Move up a bit before falling // Add some extra explosions for (int i = 0; i < 10; i++) { @@ -200,7 +200,7 @@ Yeti::jump_down() set_action("jump", m_dir); m_physic.set_velocity_x((m_dir==Direction::RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX)); m_physic.set_velocity_y(JUMP_DOWN_VY); - state = JUMP_DOWN; + m_state = JUMP_DOWN; } void @@ -209,7 +209,7 @@ Yeti::run() set_action("walking", m_dir); m_physic.set_velocity_x((m_dir==Direction::RIGHT)?(+RUN_VX):(-RUN_VX)); m_physic.set_velocity_y(0); - state = RUN; + m_state = RUN; } void @@ -218,7 +218,7 @@ Yeti::jump_up() set_action("jump", m_dir); m_physic.set_velocity_x((m_dir==Direction::RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX)); m_physic.set_velocity_y(JUMP_UP_VY); - state = JUMP_UP; + m_state = JUMP_UP; } void @@ -229,9 +229,9 @@ Yeti::be_angry() set_action("stand", m_dir); m_physic.set_velocity_x(0); - stomp_count = 0; - state = BE_ANGRY; - state_timer.start(STOMP_WAIT); + m_stomp_count = 0; + m_state = BE_ANGRY; + m_state_timer.start(STOMP_WAIT); } bool @@ -254,13 +254,13 @@ Yeti::kill_squished(GameObject& object) void Yeti::take_hit(Player& ) { - if (safe_timer.started()) + if (m_safe_timer.started()) return; SoundManager::current()->play("sounds/yeti_roar.wav", get_pos()); - hit_points--; + m_hit_points--; - if (hit_points <= 0) { + if (m_hit_points <= 0) { // We're dead m_physic.set_velocity_x(((m_dir==Direction::RIGHT)?+RUN_VX:-RUN_VX)/5); m_physic.set_velocity_y(0); @@ -268,13 +268,13 @@ void Yeti::take_hit(Player& ) // Set the badguy layer to be above the foremost, so that // this does not reveal secret tilemaps: m_layer = Sector::get().get_foremost_layer() + 1; - state = SQUISHED; - state_timer.start(YETI_SQUISH_TIME); + m_state = SQUISHED; + m_state_timer.start(YETI_SQUISH_TIME); set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC); //sprite->set_action("dead"); // This sprite does not look very good } else { - safe_timer.start(SAFE_TIME); + m_safe_timer.start(SAFE_TIME); } } @@ -296,16 +296,16 @@ Yeti::drop_stalactite() for (auto& stalactite : Sector::get().get_objects_by_type()) { if (stalactite.is_hanging()) { - if (hit_points >= 3) { + if (m_hit_points >= 3) { // drop stalactites within 3 of player, going out with each jump float distancex = fabsf(stalactite.get_bbox().get_middle().x - player->get_bbox().get_middle().x); - if (distancex < static_cast(stomp_count) * 32.0f) { + if (distancex < static_cast(m_stomp_count) * 32.0f) { stalactite.start_shaking(); } } else { /* if (hitpoints < 3) */ // drop every 3rd pair of stalactites - if ((((static_cast(stalactite.get_pos().x) + 16) / 64) % 3) == (stomp_count % 3)) { + if ((((static_cast(stalactite.get_pos().x) + 16) / 64) % 3) == (m_stomp_count % 3)) { stalactite.start_shaking(); } } @@ -320,7 +320,7 @@ Yeti::collision_solid(const CollisionHit& hit) if (hit.top || hit.bottom) { // hit floor or roof m_physic.set_velocity_y(0); - switch (state) { + switch (m_state) { case JUMP_DOWN: run(); break; @@ -330,17 +330,17 @@ Yeti::collision_solid(const CollisionHit& hit) break; case BE_ANGRY: // we just landed - if (!state_timer.started()) { + if (!m_state_timer.started()) { set_action("stand", m_dir); - stomp_count++; + m_stomp_count++; drop_stalactite(); // go to other side after 3 jumps - if (stomp_count == 3) { + if (m_stomp_count == 3) { jump_down(); } else { // jump again - state_timer.start(STOMP_WAIT); + m_state_timer.start(STOMP_WAIT); } } break; @@ -351,7 +351,7 @@ Yeti::collision_solid(const CollisionHit& hit) } } else if (hit.left || hit.right) { // hit wall - if(state != SQUISHED && state != FALLING) + if(m_state != SQUISHED && m_state != FALLING) jump_up(); } } @@ -367,9 +367,9 @@ Yeti::get_settings() { ObjectSettings result = BadGuy::get_settings(); - result.add_text("hud-icon", &hud_icon, "hud-icon", std::string("images/creatures/yeti/hudlife.png"), OPTION_HIDDEN); - result.add_bool(_("Fixed position"), &fixed_pos, "fixed-pos", false); - result.add_int(_("Lives"), &hit_points, "lives", 5); + result.add_text("hud-icon", &m_hud_icon, "hud-icon", std::string("images/creatures/yeti/hudlife.png"), OPTION_HIDDEN); + result.add_bool(_("Fixed position"), &m_fixed_pos, "fixed-pos", false); + result.add_int(_("Lives"), &m_hit_points, "lives", 5); return result; } diff --git a/src/badguy/yeti.hpp b/src/badguy/yeti.hpp index fe6435b1ad2..4fcb8e33d09 100644 --- a/src/badguy/yeti.hpp +++ b/src/badguy/yeti.hpp @@ -54,6 +54,7 @@ class Yeti final : public BadGuy void take_hit(Player& player); void add_snow_explosions(); + void recalculate_pos(); private: enum YetiState { @@ -66,22 +67,20 @@ class Yeti final : public BadGuy }; private: - YetiState state; - Timer state_timer; - Timer safe_timer; - int stomp_count; - int hit_points; - SurfacePtr hud_head; - - float left_stand_x; - float right_stand_x; - float left_jump_x; - float right_jump_x; - - void recalculate_pos(); - - bool fixed_pos; - std::string hud_icon; + YetiState m_state; + Timer m_state_timer; + Timer m_safe_timer; + int m_stomp_count; + int m_hit_points; + SurfacePtr m_hud_head; + + float m_left_stand_x; + float m_right_stand_x; + float m_left_jump_x; + float m_right_jump_x; + + bool m_fixed_pos; + std::string m_hud_icon; class SnowExplosionParticle: public BadGuy { diff --git a/src/editor/object_settings.cpp b/src/editor/object_settings.cpp index 0099f4847d6..c2622ce09b3 100644 --- a/src/editor/object_settings.cpp +++ b/src/editor/object_settings.cpp @@ -19,9 +19,9 @@ #include #include +#include "supertux/direction.hpp" #include "util/gettext.hpp" #include "video/color.hpp" -#include "supertux/direction.hpp" ObjectSettings::ObjectSettings(const std::string& name) : m_name(name), diff --git a/src/object/ispy.cpp b/src/object/ispy.cpp index d0e3430b044..1f5e71899ea 100644 --- a/src/object/ispy.cpp +++ b/src/object/ispy.cpp @@ -53,7 +53,7 @@ Ispy::Ispy(const ReaderMapping& reader) : } } - set_sprite_action("idle"); + set_action("idle", m_dir); } ObjectSettings @@ -74,7 +74,7 @@ Ispy::after_editor_set() { MovingSprite::after_editor_set(); m_dir = m_allowed_directions[m_dir_in_allowed]; - set_sprite_action("idle"); + set_action("idle", m_dir); } HitResponse @@ -103,7 +103,7 @@ Ispy::update(float dt_sec) if (Sector::get().can_see_player(eye)) { - set_sprite_action("alert", 1); + set_action("alert", m_dir, 1); m_state = ISPYSTATE_ALERT; } } @@ -111,7 +111,7 @@ Ispy::update(float dt_sec) { if (m_sprite->animation_done()) { - set_sprite_action("hiding", 1); + set_action("hiding", m_dir, 1); m_state = ISPYSTATE_HIDING; Sector::get().run_script(m_script, "Ispy"); @@ -121,7 +121,7 @@ Ispy::update(float dt_sec) { if (m_sprite->animation_done()) { - set_sprite_action("showing", 1); + set_action("showing", m_dir, 1); m_state = ISPYSTATE_SHOWING; } } @@ -129,25 +129,12 @@ Ispy::update(float dt_sec) { if (m_sprite->animation_done()) { - set_sprite_action("idle"); + set_action("idle", m_dir); m_state = ISPYSTATE_IDLE; } } } -void -Ispy::set_sprite_action(const std::string& action, int loops) -{ - switch (m_dir) - { - case Direction::DOWN: set_action(action + "-down", loops); break; - case Direction::UP: set_action(action + "-up", loops); break; - case Direction::LEFT: set_action(action + "-left", loops); break; - case Direction::RIGHT: set_action(action + "-right", loops); break; - default: break; - } -} - void Ispy::on_flip(float height) { diff --git a/src/object/ispy.hpp b/src/object/ispy.hpp index 2f3c7736996..33255819ec7 100644 --- a/src/object/ispy.hpp +++ b/src/object/ispy.hpp @@ -40,9 +40,6 @@ class Ispy final : public MovingSprite virtual void on_flip(float height) override; -private: - void set_sprite_action(const std::string& action, int loops = -1); - private: enum IspyState { ISPYSTATE_IDLE,