First implementation of the ice power.
authorRicardo Cruz <rick2@aeiou.pt>
Wed, 12 May 2004 17:56:34 +0000 (17:56 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Wed, 12 May 2004 17:56:34 +0000 (17:56 +0000)
SVN-Revision: 1136

src/badguy.cpp
src/badguy.h
src/defines.h
src/gameloop.cpp
src/player.cpp
src/player.h
src/resources.cpp
src/special.cpp
src/special.h
src/world.cpp
src/worldmap.cpp

index ab515b5..5241e2a 100644 (file)
@@ -151,6 +151,7 @@ BadGuy::BadGuy(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
   old_base = base;
   dir      = LEFT;
   seen     = false;
+  frozen_timer.init(true);
   animation_offset = 0;
   sprite_left = sprite_right = 0;
   physic.reset();
@@ -683,6 +684,9 @@ BadGuy::action(double frame_ratio)
   if(!seen)
     return;
 
+  if(frozen_timer.check())
+    return;
+
   switch (kind)
     {
     case BAD_MRICEBLOCK:
@@ -939,6 +943,7 @@ void
 BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
 {
   BadGuy* pbad_c    = NULL;
+  Bullet* pbullet_c = NULL;
 
   if(type == COLLISION_BUMP) {
     bump();
@@ -955,7 +960,12 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
   switch (c_object)
     {
     case CO_BULLET:
-      kill_me(10);
+      pbullet_c = (Bullet*) p_c_object;
+
+      if(pbullet_c->kind == FIRE_BULLET)
+        kill_me(10);
+      else if(pbullet_c->kind == ICE_BULLET)
+        frozen_timer.start(FROZEN_TIME);
       break;
 
     case CO_BADGUY:
index caaa8e9..87b03fe 100644 (file)
@@ -96,6 +96,7 @@ private:
   bool removable;
   bool seen;
   int squishcount; /// number of times this enemy was squiched
+  Timer frozen_timer;  // gets frozen when a ice shot hits it
   Timer timer;
   Physic physic;
 
index 616fcee..3079638 100644 (file)
@@ -69,7 +69,9 @@ enum DyingType {
 
 #define START_LIVES 4
 
-#define MAX_BULLETS 2
+#define MAX_FIRE_BULLETS 2
+#define MAX_ICE_BULLETS  1
+#define FROZEN_TIME 3000
 
 #define YM_FOR_JUMP 6.0
 #define WALK_ACCELERATION_X 0.03
index e2c44b9..9c52c9f 100644 (file)
@@ -343,7 +343,11 @@ GameSession::process_events()
                         break;
                       case SDLK_DELETE:
                         if(debug_mode)
-                          tux.got_coffee = 1;
+                          tux.got_power = tux.FIRE_POWER;
+                        break;
+                      case SDLK_HOME:
+                        if(debug_mode)
+                          tux.got_power = tux.ICE_POWER;
                         break;
                       case SDLK_INSERT:
                         if(debug_mode)
index ac5018f..8734457 100644 (file)
@@ -37,6 +37,7 @@ Sprite* largetux_star;
 
 PlayerSprite smalltux;
 PlayerSprite largetux;
+PlayerSprite icetux;
 PlayerSprite firetux;
 
 PlayerKeymap keymap;
@@ -72,7 +73,7 @@ Player::init()
   base.height = 32;
 
   size = SMALL;
-  got_coffee = false;
+  got_power = NONE_POWER;
 
   base.x = plevel->start_pos_x;
   base.y = plevel->start_pos_y;
@@ -453,7 +454,7 @@ Player::handle_input()
 
   /* Shoot! */
 
-  if (input.fire == DOWN && input.old_fire == UP && got_coffee)
+  if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER)
     {
       World::current()->add_bullet(base.x, base.y, physic.get_velocity_x(), dir);
       input.old_fire = DOWN;
@@ -559,8 +560,10 @@ Player::draw()
           
           if (size == SMALL)
             sprite = &smalltux;
-          else if (got_coffee)
+          else if (got_power == FIRE_POWER)
             sprite = &firetux;
+          else if (got_power == ICE_POWER)
+            sprite = &icetux;
           else
             sprite = &largetux;
           
@@ -709,9 +712,9 @@ Player::kill(HurtMode mode)
 
   if (mode == SHRINK && size == BIG)
     {
-      if (got_coffee)
+      if (got_power != NONE_POWER)
         {
-          got_coffee = false;
+          got_power = NONE_POWER;
         }
       else
         {
@@ -751,7 +754,7 @@ bool Player::is_dead()
 void
 Player::remove_powerups()
 {
-  got_coffee = false;
+  got_power = NONE_POWER;
   size = SMALL;
   base.height = 32;
 }
index 0f87dba..da36ef8 100644 (file)
@@ -103,14 +103,16 @@ struct PlayerSprite
 extern PlayerSprite smalltux;
 extern PlayerSprite largetux;
 extern PlayerSprite firetux;
+extern PlayerSprite icetux;
 
 class Player : public GameObject
 {
 public:
   enum HurtMode { KILL, SHRINK };
+  enum Power { NONE_POWER, FIRE_POWER, ICE_POWER };
 
   player_input_type  input;
-  bool got_coffee;
+  int got_power;
   int size;
   bool duck;
   bool holding_something;
index 60f6799..cdef725 100644 (file)
@@ -97,6 +97,22 @@ void loadshared()
   firetux.duck_left   = sprite_manager->load("firetux-duck-left");
   firetux.duck_right  = sprite_manager->load("firetux-duck-right");
 
+  icetux.stand_left  = sprite_manager->load("icetux-stand-left");
+  icetux.stand_right = sprite_manager->load("icetux-stand-right");
+  icetux.walk_left   = sprite_manager->load("icetux-walk-left");
+  icetux.walk_right  = sprite_manager->load("icetux-walk-right");
+  icetux.jump_left   = sprite_manager->load("icetux-jump-left");
+  icetux.jump_right  = sprite_manager->load("icetux-jump-right");
+  icetux.kick_left   = sprite_manager->load("icetux-kick-left");
+  icetux.kick_right  = sprite_manager->load("icetux-kick-right");
+  icetux.skid_right  = sprite_manager->load("icetux-skid-right");
+  icetux.skid_left   = sprite_manager->load("icetux-skid-left");
+  icetux.grab_left   = sprite_manager->load("icetux-grab-left");
+  icetux.grab_right  = sprite_manager->load("icetux-grab-right");
+  icetux.duck_left   = sprite_manager->load("icetux-duck-left");
+  icetux.duck_right  = sprite_manager->load("icetux-duck-right");
+
+
   /* Water: */
   img_water = new Surface(datadir + "/images/shared/water.png", IGNORE_ALPHA);
 
index a4da6d3..68cfb85 100644 (file)
@@ -31,7 +31,8 @@
 #include "sprite_manager.h"
 #include "resources.h"
 
-Sprite* img_bullet;
+Sprite* img_firebullet;
+Sprite* img_icebullet;
 Sprite* img_star;
 Sprite* img_growup;
 Sprite* img_iceflower;
@@ -43,7 +44,7 @@ Sprite* img_1up;
 #define BULLET_XM 6
 
 void
-Bullet::init(float x, float y, float xm, Direction dir)
+Bullet::init(float x, float y, float xm, Direction dir, int kind_)
 {
   life_count = 3;
   base.width = 4;
@@ -63,6 +64,7 @@ Bullet::init(float x, float y, float xm, Direction dir)
   base.y = y;
   base.ym = BULLET_STARTING_YM;
   old_base = base;
+  kind = kind_;
 }
 
 void
@@ -103,7 +105,10 @@ Bullet::action(double frame_ratio)
       life_count -= 1;
     }
 
-  base.ym = base.ym + 0.5 * frame_ratio;
+  if(kind == FIRE_BULLET)
+    base.ym = base.ym + 0.5 * frame_ratio;
+  else if(kind == FIRE_BULLET)
+    base.ym = 0;
 
   if (base.x < scroll_x ||
       base.x > scroll_x + screen->w ||
@@ -123,7 +128,10 @@ Bullet::draw()
   if (base.x >= scroll_x - base.width &&
       base.x <= scroll_x + screen->w)
     {
-      img_bullet->draw(base.x, base.y);
+      if(kind == FIRE_BULLET)
+        img_firebullet->draw(base.x, base.y);
+      else if(kind == FIRE_BULLET)
+        img_icebullet->draw(base.x, base.y);
     }
 }
 
@@ -333,11 +341,17 @@ Upgrade::collision(void* p_c_object, int c_object, CollisionType type)
           play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
           pplayer->grow();
         }
+      else if (kind == UPGRADE_FIREFLOWER)
+        {
+          play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
+          pplayer->grow();
+          pplayer->got_power = pplayer->FIRE_POWER;
+        }
       else if (kind == UPGRADE_ICEFLOWER)
         {
           play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
           pplayer->grow();
-          pplayer->got_coffee = true;
+          pplayer->got_power = pplayer->ICE_POWER;
         }
       else if (kind == UPGRADE_HERRING)
         {
@@ -365,7 +379,8 @@ void load_special_gfx()
   img_star      = sprite_manager->load("star");
   img_1up       = sprite_manager->load("1up");
 
-  img_bullet    = sprite_manager->load("bullet");
+  img_firebullet    = sprite_manager->load("firebullet");
+  img_icebullet    = sprite_manager->load("icebullet");
 }
 
 void free_special_gfx()
index 24ce8c2..a28c742 100644 (file)
@@ -32,6 +32,7 @@
 
 enum UpgradeKind {
   UPGRADE_GROWUP,
+  UPGRADE_FIREFLOWER,
   UPGRADE_ICEFLOWER,
   UPGRADE_HERRING,
   UPGRADE_1UP
@@ -65,14 +66,21 @@ private:
   void bump(Player* player);
 };
 
+enum BulletsKind {
+  FIRE_BULLET,
+  ICE_BULLET
+};
+
 class Bullet : public GameObject
 {
  public:
   int life_count;
   base_type base;
   base_type old_base;
+
+  int kind;
   
-  void init(float x, float y, float xm, Direction dir);
+  void init(float x, float y, float xm, Direction dir, int kind_);
   void action(double frame_ratio);
   void draw();
   void collision(int c_object);
index da3774c..daa399b 100644 (file)
@@ -89,7 +89,7 @@ World::apply_bonuses()
       break;
 
     case PlayerStatus::FLOWER_BONUS:
-      tux.got_coffee = true;
+      tux.got_power = tux.FIRE_POWER;  // FIXME: add ice power to here
       // fall through
 
     case PlayerStatus::GROWUP_BONUS:
@@ -546,11 +546,22 @@ World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind)
 void 
 World::add_bullet(float x, float y, float xm, Direction dir)
 {
-  if(bullets.size() > MAX_BULLETS-1)
-    return;
+  if(tux.got_power == tux.FIRE_POWER)
+    {
+    if(bullets.size() > MAX_FIRE_BULLETS-1)
+      return;
+    }
+  else if(tux.got_power == tux.ICE_POWER)
+    {
+    if(bullets.size() > MAX_ICE_BULLETS-1)
+      return;
+    }
 
   Bullet new_bullet;
-  new_bullet.init(x,y,xm,dir);
+  if(tux.got_power == tux.FIRE_POWER)
+    new_bullet.init(x,y,xm,dir, FIRE_BULLET);
+  else if(tux.got_power == tux.ICE_POWER)
+    new_bullet.init(x,y,xm,dir, ICE_BULLET);
   bullets.push_back(new_bullet);
   
   play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
index 30d9882..17cb39d 100644 (file)
@@ -648,7 +648,8 @@ WorldMap::update(float delta)
                     bool old_level_state = level->solved;
                     level->solved = true;
 
-                    if (session.get_world()->get_tux()->got_coffee)
+                    if (session.get_world()->get_tux()->got_power !=
+                          session.get_world()->get_tux()->NONE_POWER)
                       player_status.bonus = PlayerStatus::FLOWER_BONUS;
                     else if (session.get_world()->get_tux()->size == BIG)
                       player_status.bonus = PlayerStatus::GROWUP_BONUS;