make badguys bounce of each other again, make bombs and kicked mriceblocks kill other...
authorMatthias Braun <matze@braunis.de>
Mon, 29 Nov 2004 00:12:25 +0000 (00:12 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 29 Nov 2004 00:12:25 +0000 (00:12 +0000)
SVN-Revision: 2218

18 files changed:
TODO
src/badguy/badguy.cpp
src/badguy/bomb.cpp
src/badguy/bomb.h
src/badguy/bouncing_snowball.cpp
src/badguy/bouncing_snowball.h
src/badguy/jumpy.cpp
src/badguy/jumpy.h
src/badguy/mrbomb.cpp
src/badguy/mrbomb.h
src/badguy/mriceblock.cpp
src/badguy/mriceblock.h
src/badguy/snowball.cpp
src/badguy/snowball.h
src/badguy/spiky.cpp
src/badguy/spiky.h
src/object/block.cpp
src/object/block.h

diff --git a/TODO b/TODO
index d26e624..49cd9f6 100644 (file)
--- a/TODO
+++ b/TODO
@@ -45,8 +45,6 @@ L: low priority
     - implement wingling
     - implement tree (really?)
     - bring back stay on platform flag
-    - make enemies bounce of upon each other again
-    - make enemies fall again - ok
  ** implement ability to cary mriceblock (and other objects) around - delayed
     for  after big commit...
  * smoke clouds are too fast
index 25825a4..f95f201 100644 (file)
@@ -97,7 +97,7 @@ BadGuy::collision(GameObject& other, const CollisionHit& hit)
         return collision_solid(other, hit);
 
       BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
-      if(badguy)
+      if(badguy && badguy->state == STATE_ACTIVE)
         return collision_badguy(*badguy, hit);
 
       Player* player = dynamic_cast<Player*> (&other);
index 2897e68..c7445a2 100644 (file)
@@ -41,6 +41,13 @@ Bomb::collision_player(Player& player, const CollisionHit& )
   return ABORT_MOVE;
 }
 
+HitResponse
+Bomb::collision_badguy(BadGuy& badguy, const CollisionHit& )
+{
+  badguy.kill_fall();
+  return ABORT_MOVE;
+}
+
 void
 Bomb::active_action(float )
 {
index fc3beec..3813776 100644 (file)
@@ -11,6 +11,7 @@ public:
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
   HitResponse collision_player(Player& player, const CollisionHit& hit);
+  HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
   void active_action(float elapsed_time);
   void kill_fall();
 
index 431cac2..06d70f8 100644 (file)
@@ -67,3 +67,17 @@ BouncingSnowball::collision_solid(GameObject& , const CollisionHit& hit)
   return CONTINUE;
 }
 
+HitResponse
+BouncingSnowball::collision_badguy(BadGuy& , const CollisionHit& hit)
+{
+  if(fabsf(hit.normal.x) > .8) { // left/right?
+    dir = dir == LEFT ? RIGHT : LEFT;
+    sprite->set_action(dir == LEFT ? "left" : "right");    
+    physic.set_velocity_x(-physic.get_velocity_x());
+  } else if(hit.normal.y < -.8) { // grounf
+    physic.set_velocity_y(JUMPSPEED);
+  }
+
+  return CONTINUE;
+}
+
index d53badf..63afe05 100644 (file)
@@ -12,6 +12,7 @@ public:
   void activate();
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+  HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
 
 protected:
   bool collision_squished(Player& player);
index bc8dffe..abc48ab 100644 (file)
@@ -24,15 +24,26 @@ Jumpy::write(lisp::Writer& writer)
 }
 
 HitResponse
-Jumpy::collision_solid(GameObject& , const CollisionHit& hit)
+Jumpy::collision_solid(GameObject& , const CollisionHit& chit)
+{
+  return hit(chit);
+}
+
+HitResponse
+Jumpy::collision_badguy(BadGuy& , const CollisionHit& chit)
+{
+  return hit(chit);
+}
+
+HitResponse
+Jumpy::hit(const CollisionHit& chit)
 {
   // hit floor?
-  if(hit.normal.y < -.5) {
+  if(chit.normal.y < -.5) {
     physic.set_velocity_y(JUMPSPEED);
-  } else if(hit.normal.y < .5) { // bumped on roof
+  } else if(chit.normal.y < .5) { // bumped on roof
     physic.set_velocity_y(0);
   }
 
   return CONTINUE;
 }
-
index e33f6eb..eaeafa6 100644 (file)
@@ -8,10 +8,13 @@ class Jumpy : public BadGuy
 public:
   Jumpy(const lisp::Lisp& reader);
 
-  virtual HitResponse collision_solid(GameObject& other,
-      const CollisionHit& hit);
+  HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+  HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
 
-  virtual void write(lisp::Writer& writer);
+  void write(lisp::Writer& writer);
+
+private:
+  HitResponse hit(const CollisionHit& hit);
 };
 
 #endif
index 76222d2..bc9903d 100644 (file)
@@ -66,3 +66,14 @@ MrBomb::collision_solid(GameObject& , const CollisionHit& hit)
   return CONTINUE;
 }
 
+HitResponse
+MrBomb::collision_badguy(BadGuy& , const CollisionHit& hit)
+{
+  if(fabsf(hit.normal.x) > .8) { // left or right
+    dir = dir == LEFT ? RIGHT : LEFT;
+    sprite->set_action(dir == LEFT ? "left" : "right");    
+    physic.set_velocity_x(-physic.get_velocity_x());
+  }
+
+  return CONTINUE;
+}
index fda40fb..4e7943c 100644 (file)
@@ -12,6 +12,7 @@ public:
   void activate();
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+  HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
 
 protected:
   bool collision_squished(Player& player);
index e0bdbf6..9c5ad78 100644 (file)
@@ -1,6 +1,7 @@
 #include <config.h>
 
 #include "mriceblock.h"
+#include "object/block.h"
 
 static const float WALKSPEED = 80;
 static const float KICKSPEED = 500;
@@ -59,7 +60,7 @@ MrIceBlock::active_action(float elapsed_time)
 }
 
 HitResponse
-MrIceBlock::collision_solid(GameObject& , const CollisionHit& hit)
+MrIceBlock::collision_solid(GameObject& object, const CollisionHit& hit)
 {
   if(fabsf(hit.normal.y) > .5) { // floor or roof
     physic.set_velocity_y(0);
@@ -72,13 +73,23 @@ MrIceBlock::collision_solid(GameObject& , const CollisionHit& hit)
       sprite->set_action(dir == LEFT ? "left" : "right");
       physic.set_velocity_x(-physic.get_velocity_x());       
       break;
-    case ICESTATE_KICKED:
+    case ICESTATE_KICKED: {
+      BonusBlock* bonusblock = dynamic_cast<BonusBlock*> (&object);
+      if(bonusblock) {
+        bonusblock->try_open();
+      }
+      Brick* brick = dynamic_cast<Brick*> (&object);
+      if(brick) {
+        brick->try_break();
+      }
+      
       dir = dir == LEFT ? RIGHT : LEFT;
       sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
       physic.set_velocity_x(-physic.get_velocity_x());
       SoundManager::get()->play_sound(IDToSound(SND_RICOCHET), get_pos(),
           Sector::current()->player->get_pos());
       break;
+    }
     case ICESTATE_FLAT:
       physic.set_velocity_x(0);
       break;
@@ -87,6 +98,29 @@ MrIceBlock::collision_solid(GameObject& , const CollisionHit& hit)
   return CONTINUE;
 }
 
+HitResponse
+MrIceBlock::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
+{
+  switch(ice_state) {
+    case ICESTATE_NORMAL:
+      if(fabsf(hit.normal.x) > .8) {
+        dir = dir == LEFT ? RIGHT : LEFT;
+        sprite->set_action(dir == LEFT ? "left" : "right");
+        physic.set_velocity_x(-physic.get_velocity_x());               
+      }
+      return CONTINUE;
+    case ICESTATE_FLAT:
+      return FORCE_MOVE;
+    case ICESTATE_KICKED:
+      badguy.kill_fall();
+      return FORCE_MOVE;
+    default:
+      assert(false);
+  }
+
+  return ABORT_MOVE;
+}
+
 bool
 MrIceBlock::collision_squished(Player& player)
 {
index 3a6d2a6..54ec05d 100644 (file)
@@ -11,7 +11,8 @@ public:
 
   void activate();
   void write(lisp::Writer& writer);
-  HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+  HitResponse collision_solid(GameObject& object, const CollisionHit& hit);
+  HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
 
   void active_action(float elapsed_time);
 
index 4442d02..4efd938 100644 (file)
@@ -64,3 +64,15 @@ SnowBall::collision_solid(GameObject& , const CollisionHit& hit)
   return CONTINUE;
 }
 
+HitResponse
+SnowBall::collision_badguy(BadGuy& , const CollisionHit& hit)
+{
+  if(fabsf(hit.normal.x) > .8) { // left or right hit
+    dir = dir == LEFT ? RIGHT : LEFT;
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());       
+  }
+
+  return CONTINUE;
+}
+
index 47acaf0..172aac9 100644 (file)
@@ -12,6 +12,7 @@ public:
   void activate();
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+  HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
   
 protected:
   bool collision_squished(Player& player);
index 255bb9e..b419740 100644 (file)
@@ -44,3 +44,15 @@ Spiky::collision_solid(GameObject& , const CollisionHit& hit)
   return CONTINUE;
 }
 
+HitResponse
+Spiky::collision_badguy(BadGuy& , const CollisionHit& hit)
+{
+  if(fabsf(hit.normal.x) > .8) { // left or right
+    dir = dir == LEFT ? RIGHT : LEFT;
+    sprite->set_action(dir == LEFT ? "left" : "right");
+    physic.set_velocity_x(-physic.get_velocity_x());
+  }
+
+  return CONTINUE;
+}
+
index 2c48e29..fb24749 100644 (file)
@@ -11,6 +11,7 @@ public:
   void activate();
   void write(lisp::Writer& writer);
   HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+  HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
 };
 
 #endif
index 0dcc549..ccede81 100644 (file)
@@ -101,7 +101,13 @@ BonusBlock::BonusBlock(const Vector& pos, int newdata)
 }
 
 void
-BonusBlock::hit(Player& player)
+BonusBlock::hit(Player& )
+{
+  try_open();
+}
+
+void
+BonusBlock::try_open()
 {
   if(sprite->get_action_name() == "empty") {
     SoundManager::get()->play_sound(IDToSound(SND_BRICK));
@@ -109,6 +115,7 @@ BonusBlock::hit(Player& player)
   }
   
   Sector* sector = Sector::current();
+  Player& player = *(sector->player);
   switch(data) {
     case 1: // coin
       Sector::current()->add_object(new BouncyCoin(get_pos()));
@@ -170,13 +177,23 @@ Brick::Brick(const Vector& pos, int data)
 }
 
 void
-Brick::hit(Player& player)
+Brick::hit(Player& )
+{
+  if(sprite->get_action_name() == "empty")
+    return;
+  
+  try_break(true);
+}
+
+void
+Brick::try_break(bool playerhit)
 {
   if(sprite->get_action_name() == "empty")
     return;
   
   SoundManager::get()->play_sound(IDToSound(SND_BRICK));
   Sector* sector = Sector::current();
+  Player& player = *(sector->player);
   if(coin_counter > 0) {
     sector->add_object(new BouncyCoin(get_pos()));
     coin_counter--;
@@ -185,7 +202,7 @@ Brick::hit(Player& player)
       sprite->set_action("empty");
     start_bounce();
   } else if(breakable) {
-    if(player.size == SMALL) {
+    if(playerhit && player.size == SMALL) {
       start_bounce();
       return;
     }
index 3f97f7f..ae11d22 100644 (file)
@@ -36,6 +36,8 @@ class BonusBlock : public Block
 public:
   BonusBlock(const Vector& pos, int data);
 
+  void try_open();
+
 protected:
   virtual void hit(Player& player);
 
@@ -48,6 +50,8 @@ class Brick : public Block
 public:
   Brick(const Vector& pos, int data);
 
+  void try_break(bool playerhit = false);
+
 protected:
   virtual void hit(Player& player);