Sprite* smalltux_gameover;
Sprite* smalltux_star;
-Sprite* largetux_star;
+Sprite* bigtux_star;
-Sprite* small_tux;
-Sprite* big_tux;
-Sprite* ice_tux;
-Sprite* fire_tux;
-
-Sprite* tux_arm;
+TuxBodyParts* small_tux;
+TuxBodyParts* big_tux;
+TuxBodyParts* fire_tux;
+TuxBodyParts* ice_tux;
PlayerKeymap keymap;
pplayer_input->activate = UP;
}
+void
+TuxBodyParts::set_action(std::string action)
+{
+head->set_action(action);
+body->set_action(action);
+arms->set_action(action);
+feet->set_action(action);
+}
+
+void
+TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer,
+ Uint32 drawing_effect)
+{
+head->draw(context, pos, layer, drawing_effect);
+body->draw(context, pos, layer, drawing_effect);
+arms->draw(context, pos, layer, drawing_effect);
+feet->draw(context, pos, layer, drawing_effect);
+}
+
Player::Player()
{
init();
void
Player::draw(DrawingContext& context)
{
- Sprite* sprite;
+ TuxBodyParts* tux_body;
if (size == SMALL)
- sprite = small_tux;
+ tux_body = small_tux;
else if (got_power == FIRE_POWER)
- sprite = fire_tux;
+ tux_body = fire_tux;
else if (got_power == ICE_POWER)
- sprite = ice_tux;
+ tux_body = ice_tux;
else
- sprite = big_tux;
+ tux_body = big_tux;
int layer = LAYER_OBJECTS - 1;
Vector pos = Vector(base.x, base.y);
else if (duck && size != SMALL)
{
if (dir == RIGHT)
- sprite->set_action("duck-right");
+ tux_body->set_action("duck-right");
else
- sprite->set_action("duck-left");
+ tux_body->set_action("duck-left");
}
+
else if (skidding_timer.started())
{
if (dir == RIGHT)
- sprite->set_action("skid-right");
+ tux_body->set_action("skid-right");
else
- sprite->set_action("skid-left");
+ tux_body->set_action("skid-left");
}
else if (kick_timer.started())
{
if (dir == RIGHT)
- sprite->set_action("kick-right");
+ tux_body->set_action("kick-right");
else
- sprite->set_action("kick-left");
+ tux_body->set_action("kick-left");
}
else if (physic.get_velocity_y() != 0)
{
if (dir == RIGHT)
- sprite->set_action("jump-right");
+ tux_body->set_action("jump-right");
else
- sprite->set_action("jump-left");
+ tux_body->set_action("jump-left");
}
else
{
if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
{
if (dir == RIGHT)
- sprite->set_action("stand-right");
+ tux_body->set_action("stand-right");
else
- sprite->set_action("stand-left");
+ tux_body->set_action("stand-left");
}
else // moving
{
if (dir == RIGHT)
- sprite->set_action("walk-right");
+ tux_body->set_action("walk-right");
else
- sprite->set_action("walk-left");
+ tux_body->set_action("walk-left");
}
}
}
}
- if(dying != DYING_SQUISHED && !growing_timer.check())
- sprite->draw(context, pos, layer);
-
- // Draw arm overlay graphics when Tux is holding something
- if ((holding_something && physic.get_velocity_y() == 0) || shooting_timer.check() && !duck)
- {
+ // Tux is holding something
+ if ((holding_something && physic.get_velocity_y() == 0) ||
+ shooting_timer.check() && !duck)
+ {
if (dir == RIGHT)
- tux_arm->set_action("grab-right");
+ tux_body->arms->set_action("grab-right");
else
- tux_arm->set_action("grab-left");
- tux_arm->draw(context, pos, LAYER_OBJECTS + 1);
- }
-
+ tux_body->arms->set_action("grab-left");
+ }
+
+ if(dying != DYING_SQUISHED && !growing_timer.check())
+ tux_body->draw(context, pos, layer);
+
// Draw blinking star overlay
if (invincible_timer.started() &&
(invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3))
if (size == SMALL || duck)
smalltux_star->draw(context, pos, LAYER_OBJECTS + 2);
else
- largetux_star->draw(context, pos, LAYER_OBJECTS + 2);
+ bigtux_star->draw(context, pos, LAYER_OBJECTS + 2);
}
if (debug_mode)
extern Sprite* smalltux_gameover;
extern Sprite* smalltux_star;
-extern Sprite* largetux_star;
+extern Sprite* bigtux_star;
#define GROWING_TIME 1000
#define GROWING_FRAMES 7
extern Surface* growingtux_left[GROWING_FRAMES];
extern Surface* growingtux_right[GROWING_FRAMES];
-/*struct PlayerSprite
+class TuxBodyParts
{
- Sprite* stand_left;
- Sprite* stand_right;
- Sprite* walk_right;
- Sprite* walk_left;
- Sprite* jump_right;
- Sprite* jump_left;
- Sprite* kick_left;
- Sprite* kick_right;
- Sprite* skid_right;
- Sprite* skid_left;
- Sprite* grab_left;
- Sprite* grab_right;
- Sprite* duck_right;
- Sprite* duck_left;
-};*/
-
-extern Sprite* small_tux;
-extern Sprite* big_tux;
-extern Sprite* fire_tux;
-extern Sprite* ice_tux;
-
-extern Sprite* tux_arm;
+public:
+ TuxBodyParts() { };
+ ~TuxBodyParts() { };
+
+ void set_action(std::string action);
+ void draw(DrawingContext& context, const Vector& pos, int layer,
+ Uint32 drawing_effect = NONE_EFFECT);
+
+ Sprite* head;
+ Sprite* body;
+ Sprite* arms;
+ Sprite* feet;
+};
+
+extern TuxBodyParts* small_tux;
+extern TuxBodyParts* big_tux;
+extern TuxBodyParts* fire_tux;
+extern TuxBodyParts* ice_tux;
class Player : public MovingObject
{
int i;
- sprite_manager = new SpriteManager(datadir + "/supertux.strf");
+ sprite_manager = new SpriteManager(datadir + "/images/supertux.strf");
/* Tuxes: */
smalltux_star = sprite_manager->load("smalltux-star");
- largetux_star = sprite_manager->load("bigtux-star");
+ bigtux_star = sprite_manager->load("bigtux-star");
smalltux_gameover = sprite_manager->load("smalltux-gameover");
char img_name[1024];
growingtux_right[i] = new Surface(img_name, true);
}
- small_tux = sprite_manager->load("small-tux");
- big_tux = sprite_manager->load("big-tux");
- ice_tux = sprite_manager->load("ice-tux");
- fire_tux = sprite_manager->load("fire-tux");
-
- tux_arm = sprite_manager->load("tux-arm");
+ small_tux = new TuxBodyParts();
+ small_tux->head = sprite_manager->load("big-tux-head");
+ small_tux->body = sprite_manager->load("big-tux-body");
+ small_tux->arms = sprite_manager->load("big-tux-arms");
+ small_tux->feet = sprite_manager->load("big-tux-feet");
+
+ big_tux = new TuxBodyParts();
+ big_tux->head = sprite_manager->load("big-tux-head");
+ big_tux->body = sprite_manager->load("big-tux-body");
+ big_tux->arms = sprite_manager->load("big-tux-arms");
+ big_tux->feet = sprite_manager->load("big-tux-feet");
+
+ fire_tux = new TuxBodyParts();
+ fire_tux->head = sprite_manager->load("big-fire-tux-head");
+ fire_tux->body = sprite_manager->load("big-tux-body");
+ fire_tux->arms = sprite_manager->load("big-tux-arms");
+ fire_tux->feet = sprite_manager->load("big-tux-feet");
+
+ ice_tux = new TuxBodyParts();
+ ice_tux->head = sprite_manager->load("big-tux-head");
+ ice_tux->body = sprite_manager->load("big-tux-body");
+ ice_tux->arms = sprite_manager->load("big-tux-arms");
+ ice_tux->feet = sprite_manager->load("big-tux-feet");
/* Water: */
img_water = new Surface(datadir + "/images/shared/water.png", false);
delete tux_life;
+ delete small_tux;
+ delete big_tux;
+ delete fire_tux;
+ delete ice_tux;
+
for (int i = 0; i < GROWING_FRAMES; i++)
{
delete growingtux_left[i];