Skip to content

Commit 5a73183

Browse files
committed
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.
1 parent 28d55c9 commit 5a73183

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

src/object/player.cpp

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "audio/sound_manager.hpp"
2424
#include "badguy/badguy.hpp"
25+
#include "collision/collision_group.hpp"
2526
#include "control/codecontroller.hpp"
2627
#include "control/input_manager.hpp"
2728
#include "editor/editor.hpp"
@@ -157,6 +158,7 @@ const int MAX_ICE_BULLETS = 2;
157158
} // namespace
158159

159160
Player::Player(PlayerStatus& player_status, const std::string& name_, int player_id) :
161+
MovingSprite({0, 0}, "images/creatures/tux/tux.sprite", 9001, COLGROUP_MOVING),
160162
m_id(player_id),
161163
m_target(nullptr),
162164
m_deactivated(false),
@@ -226,7 +228,6 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player
226228
// if/when we have complete penny gfx, we can
227229
// load those instead of Tux's sprite in the
228230
// constructor
229-
m_sprite(SpriteManager::current()->create("images/creatures/tux/tux.sprite")),
230231
m_swimming_angle(0),
231232
m_swimming_accel_modifier(100.f),
232233
m_water_jump(false),
@@ -266,6 +267,7 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player
266267

267268
m_col.set_size(TUX_WIDTH, is_big() ? BIG_TUX_HEIGHT : SMALL_TUX_HEIGHT);
268269

270+
269271
m_sprite->set_angle(0.0f);
270272
//m_santahatsprite->set_angle(0.0f);
271273

@@ -1958,13 +1960,13 @@ Player::set_bonus(BonusType type, bool animate)
19581960
if (animate) {
19591961
m_growing = true;
19601962
if (m_climbing)
1961-
m_sprite->set_action("climbgrow", m_dir, 1);
1963+
set_action("climbgrow", m_dir, 1);
19621964
else if (m_swimming)
1963-
m_sprite->set_action("swimgrow", m_dir, 1);
1965+
set_action("swimgrow", m_dir, 1);
19641966
else if (m_sliding)
1965-
m_sprite->set_action("slidegrow", m_dir, 1);
1967+
set_action("slidegrow", m_dir, 1);
19661968
else
1967-
m_sprite->set_action("grow", m_dir , 1);
1969+
set_action("grow", m_dir , 1);
19681970
}
19691971
}
19701972

@@ -2080,7 +2082,7 @@ Player::draw(DrawingContext& context)
20802082
/* Set Tux sprite action */
20812083
if (m_dying) {
20822084
m_sprite->set_angle(0.0f);
2083-
m_sprite->set_action("gameover");
2085+
set_action("gameover");
20842086
}
20852087
else if (m_growing)
20862088
{
@@ -2097,28 +2099,28 @@ Player::draw(DrawingContext& context)
20972099
else if (m_climbing) {
20982100
action = "climbgrow";
20992101
}
2100-
m_sprite->set_action(action + sa_postfix, Sprite::LOOPS_CONTINUED);
2102+
set_action(action + sa_postfix, Sprite::LOOPS_CONTINUED);
21012103
}
21022104
else if (m_stone) {
2103-
m_sprite->set_action("earth-stone");
2105+
set_action("earth-stone");
21042106
}
21052107
else if (m_climbing) {
2106-
m_sprite->set_action(sa_prefix+"-climb"+sa_postfix);
2108+
set_action(sa_prefix+"-climb"+sa_postfix);
21072109

21082110
// Avoid flickering briefly after growing on ladder
21092111
if ((m_physic.get_velocity_x()==0)&&(m_physic.get_velocity_y()==0))
21102112
m_sprite->pause_animation();
21112113
}
21122114
else if (m_backflipping) {
2113-
m_sprite->set_action(sa_prefix+"-backflip"+sa_postfix);
2115+
set_action(sa_prefix+"-backflip"+sa_postfix);
21142116
}
21152117
else if (m_sliding) {
21162118
if (m_jumping || m_is_slidejump_falling) {
2117-
m_sprite->set_action(sa_prefix +"-slidejump"+ sa_postfix);
2119+
set_action(sa_prefix +"-slidejump"+ sa_postfix);
21182120
}
21192121
else {
21202122
const bool was_growing_before = (m_sprite->get_action().substr(0, 9) == "slidegrow");
2121-
m_sprite->set_action(sa_prefix + "-slide" + sa_postfix);
2123+
set_action(sa_prefix + "-slide" + sa_postfix);
21222124
if (m_was_crawling_before_slide || was_growing_before)
21232125
{
21242126
m_sprite->set_frame(m_sprite->get_frames()); // Skip the "duck" animation when coming from crawling or slidegrowing
@@ -2127,13 +2129,13 @@ Player::draw(DrawingContext& context)
21272129
}
21282130
}
21292131
else if (m_duck && is_big() && !m_swimming && !m_crawl && !m_stone) {
2130-
m_sprite->set_action(sa_prefix+"-duck"+sa_postfix);
2132+
set_action(sa_prefix+"-duck"+sa_postfix);
21312133
}
21322134
else if (m_crawl)
21332135
{
21342136
if (on_ground())
21352137
{
2136-
m_sprite->set_action(sa_prefix + "-crawl" + sa_postfix);
2138+
set_action(sa_prefix + "-crawl" + sa_postfix);
21372139
if (m_physic.get_velocity_x() != 0.f) {
21382140
m_sprite->resume_animation();
21392141
}
@@ -2142,26 +2144,26 @@ Player::draw(DrawingContext& context)
21422144
}
21432145
}
21442146
else {
2145-
m_sprite->set_action(sa_prefix + "-slidejump" + sa_postfix);
2147+
set_action(sa_prefix + "-slidejump" + sa_postfix);
21462148
}
21472149
}
21482150
else if (m_skidding_timer.started() && !m_skidding_timer.check() && !m_swimming) {
2149-
m_sprite->set_action(sa_prefix + "-skid" + sa_postfix);
2151+
set_action(sa_prefix + "-skid" + sa_postfix);
21502152
}
21512153
else if (m_kick_timer.started() && !m_kick_timer.check() && !m_swimming && !m_water_jump) {
2152-
m_sprite->set_action(sa_prefix+"-kick"+sa_postfix);
2154+
set_action(sa_prefix+"-kick"+sa_postfix);
21532155
}
21542156
else if ((m_wants_buttjump || m_does_buttjump) && is_big() && !m_water_jump) {
21552157
if (m_buttjump_stomp) {
2156-
m_sprite->set_action(sa_prefix + "-stomp" + sa_postfix, 1);
2158+
set_action(sa_prefix + "-stomp" + sa_postfix, 1);
21572159
}
21582160
else {
2159-
m_sprite->set_action(sa_prefix + "-buttjump" + sa_postfix, 1);
2161+
set_action(sa_prefix + "-buttjump" + sa_postfix, 1);
21602162
}
21612163
}
21622164
else if ((m_controller->hold(Control::LEFT) || m_controller->hold(Control::RIGHT)) && m_can_walljump)
21632165
{
2164-
m_sprite->set_action(sa_prefix+"-walljump"+(m_on_left_wall ? "-left" : "-right"), 1);
2166+
set_action(sa_prefix+"-walljump"+(m_on_left_wall ? "-left" : "-right"), 1);
21652167
}
21662168
else if (!on_ground() || m_fall_mode != ON_GROUND)
21672169
{
@@ -2172,20 +2174,20 @@ Player::draw(DrawingContext& context)
21722174
if (m_water_jump && m_dir != m_old_dir)
21732175
log_debug << "Obracanko (:" << std::endl;
21742176
if (glm::length(m_physic.get_velocity()) < 50.f)
2175-
m_sprite->set_action(sa_prefix + "-float" + sa_postfix);
2177+
set_action(sa_prefix + "-float" + sa_postfix);
21762178
else if (m_water_jump)
2177-
m_sprite->set_action(sa_prefix + "-swimjump" + sa_postfix);
2179+
set_action(sa_prefix + "-swimjump" + sa_postfix);
21782180
else if (m_swimboosting)
2179-
m_sprite->set_action(sa_prefix + "-boost" + sa_postfix);
2181+
set_action(sa_prefix + "-boost" + sa_postfix);
21802182
else
2181-
m_sprite->set_action(sa_prefix + "-swim" + sa_postfix);
2183+
set_action(sa_prefix + "-swim" + sa_postfix);
21822184
}
21832185
else
21842186
{
21852187
if (m_physic.get_velocity_y() > 0)
2186-
m_sprite->set_action(sa_prefix + "-fall" + sa_postfix);
2188+
set_action(sa_prefix + "-fall" + sa_postfix);
21872189
else if (m_physic.get_velocity_y() <= 0)
2188-
m_sprite->set_action(sa_prefix + "-jump" + sa_postfix);
2190+
set_action(sa_prefix + "-jump" + sa_postfix);
21892191
}
21902192
}
21912193
}
@@ -2200,7 +2202,7 @@ Player::draw(DrawingContext& context)
22002202
{
22012203
m_idle_stage = 0;
22022204
m_idle_timer.start(static_cast<float>(TIME_UNTIL_IDLE) / 1000.0f);
2203-
m_sprite->set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix, Sprite::LOOPS_CONTINUED);
2205+
set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix, Sprite::LOOPS_CONTINUED);
22042206

22052207
if (!m_should_fancy_idle)
22062208
{
@@ -2219,19 +2221,19 @@ Player::draw(DrawingContext& context)
22192221
if (m_idle_stage >= static_cast<unsigned int>(IDLE_STAGES.size()))
22202222
{
22212223
m_idle_stage = static_cast<int>(IDLE_STAGES.size()) - 1;
2222-
m_sprite->set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix);
2224+
set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix);
22232225
m_sprite->set_animation_loops(-1);
22242226
}
22252227
else
2226-
m_sprite->set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix, 1);
2228+
set_action(sa_prefix + ("-" + IDLE_STAGES[m_idle_stage]) + sa_postfix, 1);
22272229
}
22282230
}
22292231
else
22302232
{
22312233
if (m_idle_stage != 0 || m_sprite->get_action() != sa_prefix + ("-" + IDLE_STAGES[0]) + sa_postfix)
22322234
{
22332235
m_idle_stage = 0;
2234-
m_sprite->set_action(sa_prefix + ("-" + IDLE_STAGES[0]) + sa_postfix);
2236+
set_action(sa_prefix + ("-" + IDLE_STAGES[0]) + sa_postfix);
22352237
m_sprite->set_animation_loops(-1);
22362238
}
22372239
m_fancy_idle_active = false;
@@ -2240,9 +2242,9 @@ Player::draw(DrawingContext& context)
22402242
else
22412243
{
22422244
if (std::abs(m_physic.get_velocity_x()) >= MAX_RUN_XM - 3)
2243-
m_sprite->set_action(sa_prefix + "-run" + sa_postfix);
2245+
set_action(sa_prefix + "-run" + sa_postfix);
22442246
else
2245-
m_sprite->set_action(sa_prefix + "-walk" + sa_postfix);
2247+
set_action(sa_prefix + "-walk" + sa_postfix);
22462248

22472249
m_fancy_idle_active = false;
22482250
}
@@ -3094,7 +3096,7 @@ Player::remove_collected_key(Key* key)
30943096
void
30953097
Player::register_class(ssq::VM& vm)
30963098
{
3097-
ssq::Class cls = vm.addAbstractClass<Player>("Player", vm.findClass("MovingObject"));
3099+
ssq::Class cls = vm.addAbstractClass<Player>("Player", vm.findClass("MovingSprite"));
30983100

30993101
cls.addFunc<bool, Player, const std::string&>("add_bonus", &Player::add_bonus);
31003102
cls.addFunc<bool, Player, const std::string&>("set_bonus", &Player::set_bonus);

src/object/player.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#pragma once
1818

19+
#include "moving_sprite.hpp"
1920
#include "sprite/sprite_ptr.hpp"
2021
#include "supertux/direction.hpp"
2122
#include "supertux/moving_object.hpp"
@@ -41,12 +42,12 @@ extern const float TUX_INVINCIBLE_TIME_WARNING;
4142

4243
/**
4344
* @scripting
44-
* @summary This module contains methods controlling the player. (No, SuperTux doesn't use mind control. ""Player"" refers to the type of the player object.)
45+
* @summary This module contains methods controlling the player.
4546
* @instances The first player can be accessed using ""Tux"", or ""sector.Tux"" from the console.
4647
All following players (2nd, 3rd, etc...) can be accessed by ""Tux{index}"".
4748
For example, to access the 2nd player, use ""Tux1"" (or ""sector.Tux1"" from the console).
4849
*/
49-
class Player final : public MovingObject
50+
class Player final : public MovingSprite
5051
{
5152
public:
5253
static void register_class(ssq::VM& vm);
@@ -610,8 +611,6 @@ class Player final : public MovingObject
610611
std::unique_ptr<ObjectRemoveListener> m_grabbed_object_remove_listener;
611612
bool m_released_object;
612613

613-
SpritePtr m_sprite; /**< The main sprite representing Tux */
614-
615614
float m_swimming_angle;
616615
float m_swimming_accel_modifier;
617616
bool m_water_jump;

0 commit comments

Comments
 (0)