From 671da815a4096cc4c7edd5b820b066cae5c28074 Mon Sep 17 00:00:00 2001 From: Swagtoy Date: Fri, 29 Nov 2024 03:51:35 -0500 Subject: [PATCH] Switch Player from MovingObject to MovingSprite This exposes some Squirrel methods such as set_sprite. Pretty fun. Big tux is still jank but this may be somewhere in the file. --- src/object/player.cpp | 68 ++++++++++++++++++++++--------------------- src/object/player.hpp | 7 ++--- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/object/player.cpp b/src/object/player.cpp index 7c53c70e72..dc7e09e618 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -22,6 +22,7 @@ #include "audio/sound_manager.hpp" #include "badguy/badguy.hpp" +#include "collision/collision_group.hpp" #include "control/codecontroller.hpp" #include "control/input_manager.hpp" #include "editor/editor.hpp" @@ -157,6 +158,7 @@ const int MAX_ICE_BULLETS = 2; } // namespace Player::Player(PlayerStatus& player_status, const std::string& name_, int player_id) : + MovingSprite({0, 0}, "images/creatures/tux/tux.sprite", 9001, COLGROUP_MOVING), m_id(player_id), m_target(nullptr), m_deactivated(false), @@ -225,7 +227,6 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player // if/when we have complete penny gfx, we can // load those instead of Tux's sprite in the // constructor - m_sprite(SpriteManager::current()->create("images/creatures/tux/tux.sprite")), m_swimming_angle(0), m_swimming_accel_modifier(100.f), m_water_jump(false), @@ -263,6 +264,7 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player m_col.set_size(TUX_WIDTH, is_big() ? BIG_TUX_HEIGHT : SMALL_TUX_HEIGHT); + m_sprite->set_angle(0.0f); //m_santahatsprite->set_angle(0.0f); @@ -1955,13 +1957,13 @@ Player::set_bonus(BonusType type, bool animate) if (animate) { m_growing = true; if (m_climbing) - m_sprite->set_action("climbgrow", m_dir, 1); + set_action("climbgrow", m_dir, 1); else if (m_swimming) - m_sprite->set_action("swimgrow", m_dir, 1); + set_action("swimgrow", m_dir, 1); else if (m_sliding) - m_sprite->set_action("slidegrow", m_dir, 1); + set_action("slidegrow", m_dir, 1); else - m_sprite->set_action("grow", m_dir , 1); + set_action("grow", m_dir , 1); } } @@ -2065,7 +2067,7 @@ Player::draw(DrawingContext& context) /* Set Tux sprite action */ if (m_dying) { m_sprite->set_angle(0.0f); - m_sprite->set_action("gameover"); + set_action("gameover"); } else if (m_growing) { @@ -2082,28 +2084,28 @@ Player::draw(DrawingContext& context) else if (m_climbing) { action = "climbgrow"; } - m_sprite->set_action(action + sa_postfix, Sprite::LOOPS_CONTINUED); + set_action(action + sa_postfix, Sprite::LOOPS_CONTINUED); } else if (m_stone) { - m_sprite->set_action("earth-stone"); + set_action("earth-stone"); } else if (m_climbing) { - m_sprite->set_action(sa_prefix+"-climb"+sa_postfix); + set_action(sa_prefix+"-climb"+sa_postfix); // Avoid flickering briefly after growing on ladder if ((m_physic.get_velocity_x()==0)&&(m_physic.get_velocity_y()==0)) m_sprite->pause_animation(); } else if (m_backflipping) { - m_sprite->set_action(sa_prefix+"-backflip"+sa_postfix); + set_action(sa_prefix+"-backflip"+sa_postfix); } else if (m_sliding) { if (m_jumping || m_is_slidejump_falling) { - m_sprite->set_action(sa_prefix +"-slidejump"+ sa_postfix); + set_action(sa_prefix +"-slidejump"+ sa_postfix); } else { const bool was_growing_before = (m_sprite->get_action().substr(0, 9) == "slidegrow"); - m_sprite->set_action(sa_prefix + "-slide" + sa_postfix); + set_action(sa_prefix + "-slide" + sa_postfix); if (m_was_crawling_before_slide || was_growing_before) { m_sprite->set_frame(m_sprite->get_frames()); // Skip the "duck" animation when coming from crawling or slidegrowing @@ -2112,13 +2114,13 @@ Player::draw(DrawingContext& context) } } else if (m_duck && is_big() && !m_swimming && !m_crawl && !m_stone) { - m_sprite->set_action(sa_prefix+"-duck"+sa_postfix); + set_action(sa_prefix+"-duck"+sa_postfix); } else if (m_crawl) { if (on_ground()) { - m_sprite->set_action(sa_prefix + "-crawl" + sa_postfix); + set_action(sa_prefix + "-crawl" + sa_postfix); if (m_physic.get_velocity_x() != 0.f) { m_sprite->resume_animation(); } @@ -2127,26 +2129,26 @@ Player::draw(DrawingContext& context) } } else { - m_sprite->set_action(sa_prefix + "-slidejump" + sa_postfix); + set_action(sa_prefix + "-slidejump" + sa_postfix); } } else if (m_skidding_timer.started() && !m_skidding_timer.check() && !m_swimming) { - m_sprite->set_action(sa_prefix + "-skid" + sa_postfix); + set_action(sa_prefix + "-skid" + sa_postfix); } else if (m_kick_timer.started() && !m_kick_timer.check() && !m_swimming && !m_water_jump) { - m_sprite->set_action(sa_prefix+"-kick"+sa_postfix); + set_action(sa_prefix+"-kick"+sa_postfix); } else if ((m_wants_buttjump || m_does_buttjump) && is_big() && !m_water_jump) { if (m_buttjump_stomp) { - m_sprite->set_action(sa_prefix + "-stomp" + sa_postfix, 1); + set_action(sa_prefix + "-stomp" + sa_postfix, 1); } else { - m_sprite->set_action(sa_prefix + "-buttjump" + sa_postfix, 1); + set_action(sa_prefix + "-buttjump" + sa_postfix, 1); } } else if ((m_controller->hold(Control::LEFT) || m_controller->hold(Control::RIGHT)) && m_can_walljump) { - m_sprite->set_action(sa_prefix+"-walljump"+(m_on_left_wall ? "-left" : "-right"), 1); + set_action(sa_prefix+"-walljump"+(m_on_left_wall ? "-left" : "-right"), 1); } else if (!on_ground() || m_fall_mode != ON_GROUND) { @@ -2157,20 +2159,20 @@ Player::draw(DrawingContext& context) if (m_water_jump && m_dir != m_old_dir) log_debug << "Obracanko (:" << std::endl; if (glm::length(m_physic.get_velocity()) < 50.f) - m_sprite->set_action(sa_prefix + "-float" + sa_postfix); + set_action(sa_prefix + "-float" + sa_postfix); else if (m_water_jump) - m_sprite->set_action(sa_prefix + "-swimjump" + sa_postfix); + set_action(sa_prefix + "-swimjump" + sa_postfix); else if (m_swimboosting) - m_sprite->set_action(sa_prefix + "-boost" + sa_postfix); + set_action(sa_prefix + "-boost" + sa_postfix); else - m_sprite->set_action(sa_prefix + "-swim" + sa_postfix); + set_action(sa_prefix + "-swim" + sa_postfix); } else { if (m_physic.get_velocity_y() > 0) - m_sprite->set_action(sa_prefix + "-fall" + sa_postfix); + set_action(sa_prefix + "-fall" + sa_postfix); else if (m_physic.get_velocity_y() <= 0) - m_sprite->set_action(sa_prefix + "-jump" + sa_postfix); + set_action(sa_prefix + "-jump" + sa_postfix); } } } @@ -2183,34 +2185,34 @@ Player::draw(DrawingContext& context) m_idle_stage = 0; m_idle_timer.start(static_cast(TIME_UNTIL_IDLE) / 1000.0f); - m_sprite->set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix, Sprite::LOOPS_CONTINUED); + set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix, Sprite::LOOPS_CONTINUED); } else if (m_idle_timer.check() || m_sprite->animation_done()) { m_idle_stage++; if (m_idle_stage >= static_cast(IDLE_STAGES.size())) { m_idle_stage = static_cast(IDLE_STAGES.size()) - 1; - m_sprite->set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix); + set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix); m_sprite->set_animation_loops(-1); } else { - m_sprite->set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix, 1); + set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix, 1); } } else { - m_sprite->set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix, Sprite::LOOPS_CONTINUED); + set_action(sa_prefix+("-" + IDLE_STAGES[m_idle_stage])+sa_postfix, Sprite::LOOPS_CONTINUED); } } else { if (std::abs(m_physic.get_velocity_x()) >= MAX_RUN_XM-3) { - m_sprite->set_action(sa_prefix+"-run"+sa_postfix); + set_action(sa_prefix+"-run"+sa_postfix); } else { - m_sprite->set_action(sa_prefix+"-walk"+sa_postfix); + set_action(sa_prefix+"-walk"+sa_postfix); } } } @@ -3063,7 +3065,7 @@ Player::remove_collected_key(Key* key) void Player::register_class(ssq::VM& vm) { - ssq::Class cls = vm.addAbstractClass("Player", vm.findClass("MovingObject")); + ssq::Class cls = vm.addAbstractClass("Player", vm.findClass("MovingSprite")); cls.addFunc("add_bonus", &Player::add_bonus); cls.addFunc("set_bonus", &Player::set_bonus); diff --git a/src/object/player.hpp b/src/object/player.hpp index 26cb8221d3..464537ce88 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -17,6 +17,7 @@ #ifndef HEADER_SUPERTUX_OBJECT_PLAYER_HPP #define HEADER_SUPERTUX_OBJECT_PLAYER_HPP +#include "moving_sprite.hpp" #include "sprite/sprite_ptr.hpp" #include "supertux/direction.hpp" #include "supertux/moving_object.hpp" @@ -42,12 +43,12 @@ extern const float TUX_INVINCIBLE_TIME_WARNING; /** * @scripting - * @summary This module contains methods controlling the player. (No, SuperTux doesn't use mind control. ""Player"" refers to the type of the player object.) + * @summary This module contains methods controlling the player. * @instances The first player can be accessed using ""Tux"", or ""sector.Tux"" from the console. All following players (2nd, 3rd, etc...) can be accessed by ""Tux{index}"". For example, to access the 2nd player, use ""Tux1"" (or ""sector.Tux1"" from the console). */ -class Player final : public MovingObject +class Player final : public MovingSprite { public: static void register_class(ssq::VM& vm); @@ -580,8 +581,6 @@ class Player final : public MovingObject std::unique_ptr m_grabbed_object_remove_listener; bool m_released_object; - SpritePtr m_sprite; /**< The main sprite representing Tux */ - float m_swimming_angle; float m_swimming_accel_modifier; bool m_water_jump;