22
22
23
23
#include " audio/sound_manager.hpp"
24
24
#include " badguy/badguy.hpp"
25
+ #include " collision/collision_group.hpp"
25
26
#include " control/codecontroller.hpp"
26
27
#include " control/input_manager.hpp"
27
28
#include " editor/editor.hpp"
@@ -157,6 +158,7 @@ const int MAX_ICE_BULLETS = 2;
157
158
} // namespace
158
159
159
160
Player::Player (PlayerStatus& player_status, const std::string& name_, int player_id) :
161
+ MovingSprite({0 , 0 }, " images/creatures/tux/tux.sprite" , 9001 , COLGROUP_MOVING),
160
162
m_id(player_id),
161
163
m_target(nullptr ),
162
164
m_deactivated(false ),
@@ -226,7 +228,6 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player
226
228
// if/when we have complete penny gfx, we can
227
229
// load those instead of Tux's sprite in the
228
230
// constructor
229
- m_sprite(SpriteManager::current()->create(" images/creatures/tux/tux.sprite" )),
230
231
m_swimming_angle(0 ),
231
232
m_swimming_accel_modifier(100 .f),
232
233
m_water_jump(false ),
@@ -266,6 +267,7 @@ Player::Player(PlayerStatus& player_status, const std::string& name_, int player
266
267
267
268
m_col.set_size (TUX_WIDTH, is_big () ? BIG_TUX_HEIGHT : SMALL_TUX_HEIGHT);
268
269
270
+
269
271
m_sprite->set_angle (0 .0f );
270
272
// m_santahatsprite->set_angle(0.0f);
271
273
@@ -1958,13 +1960,13 @@ Player::set_bonus(BonusType type, bool animate)
1958
1960
if (animate) {
1959
1961
m_growing = true ;
1960
1962
if (m_climbing)
1961
- m_sprite-> set_action (" climbgrow" , m_dir, 1 );
1963
+ set_action (" climbgrow" , m_dir, 1 );
1962
1964
else if (m_swimming)
1963
- m_sprite-> set_action (" swimgrow" , m_dir, 1 );
1965
+ set_action (" swimgrow" , m_dir, 1 );
1964
1966
else if (m_sliding)
1965
- m_sprite-> set_action (" slidegrow" , m_dir, 1 );
1967
+ set_action (" slidegrow" , m_dir, 1 );
1966
1968
else
1967
- m_sprite-> set_action (" grow" , m_dir , 1 );
1969
+ set_action (" grow" , m_dir , 1 );
1968
1970
}
1969
1971
}
1970
1972
@@ -2080,7 +2082,7 @@ Player::draw(DrawingContext& context)
2080
2082
/* Set Tux sprite action */
2081
2083
if (m_dying) {
2082
2084
m_sprite->set_angle (0 .0f );
2083
- m_sprite-> set_action (" gameover" );
2085
+ set_action (" gameover" );
2084
2086
}
2085
2087
else if (m_growing)
2086
2088
{
@@ -2097,28 +2099,28 @@ Player::draw(DrawingContext& context)
2097
2099
else if (m_climbing) {
2098
2100
action = " climbgrow" ;
2099
2101
}
2100
- m_sprite-> set_action (action + sa_postfix, Sprite::LOOPS_CONTINUED);
2102
+ set_action (action + sa_postfix, Sprite::LOOPS_CONTINUED);
2101
2103
}
2102
2104
else if (m_stone) {
2103
- m_sprite-> set_action (" earth-stone" );
2105
+ set_action (" earth-stone" );
2104
2106
}
2105
2107
else if (m_climbing) {
2106
- m_sprite-> set_action (sa_prefix+" -climb" +sa_postfix);
2108
+ set_action (sa_prefix+" -climb" +sa_postfix);
2107
2109
2108
2110
// Avoid flickering briefly after growing on ladder
2109
2111
if ((m_physic.get_velocity_x ()==0 )&&(m_physic.get_velocity_y ()==0 ))
2110
2112
m_sprite->pause_animation ();
2111
2113
}
2112
2114
else if (m_backflipping) {
2113
- m_sprite-> set_action (sa_prefix+" -backflip" +sa_postfix);
2115
+ set_action (sa_prefix+" -backflip" +sa_postfix);
2114
2116
}
2115
2117
else if (m_sliding) {
2116
2118
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);
2118
2120
}
2119
2121
else {
2120
2122
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);
2122
2124
if (m_was_crawling_before_slide || was_growing_before)
2123
2125
{
2124
2126
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)
2127
2129
}
2128
2130
}
2129
2131
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);
2131
2133
}
2132
2134
else if (m_crawl)
2133
2135
{
2134
2136
if (on_ground ())
2135
2137
{
2136
- m_sprite-> set_action (sa_prefix + " -crawl" + sa_postfix);
2138
+ set_action (sa_prefix + " -crawl" + sa_postfix);
2137
2139
if (m_physic.get_velocity_x () != 0 .f ) {
2138
2140
m_sprite->resume_animation ();
2139
2141
}
@@ -2142,26 +2144,26 @@ Player::draw(DrawingContext& context)
2142
2144
}
2143
2145
}
2144
2146
else {
2145
- m_sprite-> set_action (sa_prefix + " -slidejump" + sa_postfix);
2147
+ set_action (sa_prefix + " -slidejump" + sa_postfix);
2146
2148
}
2147
2149
}
2148
2150
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);
2150
2152
}
2151
2153
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);
2153
2155
}
2154
2156
else if ((m_wants_buttjump || m_does_buttjump) && is_big () && !m_water_jump) {
2155
2157
if (m_buttjump_stomp) {
2156
- m_sprite-> set_action (sa_prefix + " -stomp" + sa_postfix, 1 );
2158
+ set_action (sa_prefix + " -stomp" + sa_postfix, 1 );
2157
2159
}
2158
2160
else {
2159
- m_sprite-> set_action (sa_prefix + " -buttjump" + sa_postfix, 1 );
2161
+ set_action (sa_prefix + " -buttjump" + sa_postfix, 1 );
2160
2162
}
2161
2163
}
2162
2164
else if ((m_controller->hold (Control::LEFT) || m_controller->hold (Control::RIGHT)) && m_can_walljump)
2163
2165
{
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 );
2165
2167
}
2166
2168
else if (!on_ground () || m_fall_mode != ON_GROUND)
2167
2169
{
@@ -2172,20 +2174,20 @@ Player::draw(DrawingContext& context)
2172
2174
if (m_water_jump && m_dir != m_old_dir)
2173
2175
log_debug << " Obracanko (:" << std::endl;
2174
2176
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);
2176
2178
else if (m_water_jump)
2177
- m_sprite-> set_action (sa_prefix + " -swimjump" + sa_postfix);
2179
+ set_action (sa_prefix + " -swimjump" + sa_postfix);
2178
2180
else if (m_swimboosting)
2179
- m_sprite-> set_action (sa_prefix + " -boost" + sa_postfix);
2181
+ set_action (sa_prefix + " -boost" + sa_postfix);
2180
2182
else
2181
- m_sprite-> set_action (sa_prefix + " -swim" + sa_postfix);
2183
+ set_action (sa_prefix + " -swim" + sa_postfix);
2182
2184
}
2183
2185
else
2184
2186
{
2185
2187
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);
2187
2189
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);
2189
2191
}
2190
2192
}
2191
2193
}
@@ -2200,7 +2202,7 @@ Player::draw(DrawingContext& context)
2200
2202
{
2201
2203
m_idle_stage = 0 ;
2202
2204
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);
2204
2206
2205
2207
if (!m_should_fancy_idle)
2206
2208
{
@@ -2219,19 +2221,19 @@ Player::draw(DrawingContext& context)
2219
2221
if (m_idle_stage >= static_cast <unsigned int >(IDLE_STAGES.size ()))
2220
2222
{
2221
2223
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);
2223
2225
m_sprite->set_animation_loops (-1 );
2224
2226
}
2225
2227
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 );
2227
2229
}
2228
2230
}
2229
2231
else
2230
2232
{
2231
2233
if (m_idle_stage != 0 || m_sprite->get_action () != sa_prefix + (" -" + IDLE_STAGES[0 ]) + sa_postfix)
2232
2234
{
2233
2235
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);
2235
2237
m_sprite->set_animation_loops (-1 );
2236
2238
}
2237
2239
m_fancy_idle_active = false ;
@@ -2240,9 +2242,9 @@ Player::draw(DrawingContext& context)
2240
2242
else
2241
2243
{
2242
2244
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);
2244
2246
else
2245
- m_sprite-> set_action (sa_prefix + " -walk" + sa_postfix);
2247
+ set_action (sa_prefix + " -walk" + sa_postfix);
2246
2248
2247
2249
m_fancy_idle_active = false ;
2248
2250
}
@@ -3094,7 +3096,7 @@ Player::remove_collected_key(Key* key)
3094
3096
void
3095
3097
Player::register_class (ssq::VM& vm)
3096
3098
{
3097
- ssq::Class cls = vm.addAbstractClass <Player>(" Player" , vm.findClass (" MovingObject " ));
3099
+ ssq::Class cls = vm.addAbstractClass <Player>(" Player" , vm.findClass (" MovingSprite " ));
3098
3100
3099
3101
cls.addFunc <bool , Player, const std::string&>(" add_bonus" , &Player::add_bonus);
3100
3102
cls.addFunc <bool , Player, const std::string&>(" set_bonus" , &Player::set_bonus);
0 commit comments