Separated body parts!
authorRicardo Cruz <rick2@aeiou.pt>
Tue, 17 Aug 2004 21:54:22 +0000 (21:54 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Tue, 17 Aug 2004 21:54:22 +0000 (21:54 +0000)
SVN-Revision: 1796

src/player.cpp
src/player.h
src/resources.cpp

index 574c478..d23259b 100644 (file)
@@ -51,14 +51,12 @@ Surface* tux_life;
 
 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;
 
@@ -84,6 +82,25 @@ void player_input_init(player_input_type* pplayer_input)
   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();
@@ -687,16 +704,16 @@ Player::grabdistros()
 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);
@@ -735,64 +752,65 @@ Player::draw(DrawingContext& context)
           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))
@@ -800,7 +818,7 @@ Player::draw(DrawingContext& context)
     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)
index 719611b..13396ea 100644 (file)
@@ -96,37 +96,33 @@ extern Surface* tux_life;
 
 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
 {
index efa7f31..5527993 100644 (file)
@@ -114,11 +114,11 @@ void loadshared()
 
   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];
@@ -131,12 +131,29 @@ void loadshared()
       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);
@@ -288,6 +305,11 @@ void unloadshared(void)
 
   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];