Make Badguy activation dependent of Player position, not currently-visible screen
authorChristoph Sommer <mail@christoph-sommer.de>
Sun, 3 Feb 2008 17:29:23 +0000 (17:29 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sun, 3 Feb 2008 17:29:23 +0000 (17:29 +0000)
SVN-Revision: 5310

54 files changed:
src/badguy/angrystone.cpp
src/badguy/angrystone.hpp
src/badguy/badguy.cpp
src/badguy/badguy.hpp
src/badguy/bouncing_snowball.cpp
src/badguy/bouncing_snowball.hpp
src/badguy/dart.cpp
src/badguy/dart.hpp
src/badguy/darttrap.cpp
src/badguy/darttrap.hpp
src/badguy/dispenser.cpp
src/badguy/fish.cpp
src/badguy/flame.cpp
src/badguy/flyingsnowball.cpp
src/badguy/flyingsnowball.hpp
src/badguy/ghosttree.cpp
src/badguy/igel.cpp
src/badguy/kugelblitz.cpp
src/badguy/kugelblitz.hpp
src/badguy/mole.cpp
src/badguy/mole_rock.cpp
src/badguy/mole_rock.hpp
src/badguy/mrbomb.cpp
src/badguy/mriceblock.cpp
src/badguy/mriceblock.hpp
src/badguy/mrrocket.cpp
src/badguy/mrrocket.hpp
src/badguy/plant.cpp
src/badguy/plant.hpp
src/badguy/root.cpp
src/badguy/root.hpp
src/badguy/skullyhop.cpp
src/badguy/skullyhop.hpp
src/badguy/snail.cpp
src/badguy/snail.hpp
src/badguy/spidermite.cpp
src/badguy/spidermite.hpp
src/badguy/sspiky.cpp
src/badguy/sspiky.hpp
src/badguy/stalactite.cpp
src/badguy/stumpy.cpp
src/badguy/stumpy.hpp
src/badguy/toad.cpp
src/badguy/toad.hpp
src/badguy/totem.cpp
src/badguy/totem.hpp
src/badguy/treewillowisp.cpp
src/badguy/walking_badguy.cpp
src/badguy/walking_badguy.hpp
src/badguy/willowisp.cpp
src/badguy/yeti.cpp
src/badguy/yeti.hpp
src/badguy/zeekling.cpp
src/badguy/zeekling.hpp

index d6dd326..d44f9d8 100644 (file)
@@ -31,6 +31,10 @@ static const float RECOVER_TIME = .5;
 AngryStone::AngryStone(const lisp::Lisp& reader)
        : BadGuy(reader, "images/creatures/angrystone/angrystone.sprite"), state(IDLE)
 {
+  physic.set_velocity_x(0);
+  physic.set_velocity_y(0);
+  physic.enable_gravity(true);
+  sprite->set_action("idle");
 }
 
 void
@@ -45,15 +49,6 @@ AngryStone::write(lisp::Writer& writer)
 }
 
 void
-AngryStone::activate()
-{
-  physic.set_velocity_x(0);
-  physic.set_velocity_y(0);
-  physic.enable_gravity(true);
-  sprite->set_action("idle");
-}
-
-void
 AngryStone::collision_solid(const CollisionHit& hit)
 {
   // TODO
index 73466af..1a46e0c 100644 (file)
@@ -28,7 +28,6 @@ class AngryStone : public BadGuy
 public:
   AngryStone(const lisp::Lisp& reader);
 
-  void activate();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
index cddb7ac..0e9347e 100644 (file)
@@ -17,7 +17,6 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <config.h>
-
 #include "badguy.hpp"
 #include "object/camera.hpp"
 #include "object/tilemap.hpp"
 #include "random_generator.hpp"
 
 static const float SQUISH_TIME = 2;
+  
 static const float X_OFFSCREEN_DISTANCE = 1600;
 static const float Y_OFFSCREEN_DISTANCE = 1200;
 
 BadGuy::BadGuy(const Vector& pos, const std::string& sprite_name, int layer)
-  : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true),
+  : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), is_initialized(false),
     dir(LEFT), start_dir(AUTO), frozen(false), ignited(false),
-    state(STATE_INIT), on_ground_flag(false)
+    state(STATE_INIT), on_ground_flag(false), colgroup_active(COLGROUP_MOVING)
 {
   start_position = bbox.p1;
 
   sound_manager->preload("sounds/squish.wav");
   sound_manager->preload("sounds/fall.wav");
+
+  dir = (start_dir == AUTO) ? LEFT : start_dir;
 }
 
 BadGuy::BadGuy(const Vector& pos, Direction direction, const std::string& sprite_name, int layer)
-  : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true),
+  : MovingSprite(pos, sprite_name, layer, COLGROUP_DISABLED), countMe(true), is_initialized(false), 
     dir(direction), start_dir(direction), frozen(false), ignited(false),
-    state(STATE_INIT), on_ground_flag(false)
+    state(STATE_INIT), on_ground_flag(false), colgroup_active(COLGROUP_MOVING)
 {
   start_position = bbox.p1;
 
   sound_manager->preload("sounds/squish.wav");
   sound_manager->preload("sounds/fall.wav");
+
+  dir = (start_dir == AUTO) ? LEFT : start_dir;
 }
 
 BadGuy::BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int layer)
-  : MovingSprite(reader, sprite_name, layer, COLGROUP_DISABLED), countMe(true), dir(LEFT), start_dir(AUTO), frozen(false), ignited(false), state(STATE_INIT), on_ground_flag(false)
+  : MovingSprite(reader, sprite_name, layer, COLGROUP_DISABLED), countMe(true), is_initialized(false), dir(LEFT), start_dir(AUTO), frozen(false), ignited(false), state(STATE_INIT), on_ground_flag(false), colgroup_active(COLGROUP_MOVING)
 {
   start_position = bbox.p1;
 
@@ -71,6 +75,8 @@ BadGuy::BadGuy(const lisp::Lisp& reader, const std::string& sprite_name, int lay
 
   sound_manager->preload("sounds/squish.wav");
   sound_manager->preload("sounds/fall.wav");
+
+  dir = (start_dir == AUTO) ? LEFT : start_dir;
 }
 
 void
@@ -98,7 +104,7 @@ BadGuy::update(float elapsed_time)
     remove_me();
     return;
   }
-  if(is_offscreen()) {
+  if ((state != STATE_INACTIVE) && is_offscreen()) {
     if (state == STATE_ACTIVE) deactivate();
     set_state(STATE_INACTIVE);
   }
@@ -147,6 +153,11 @@ BadGuy::str2dir( std::string dir_str )
 }
 
 void
+BadGuy::initialize()
+{
+}
+
+void
 BadGuy::activate()
 {
 }
@@ -371,8 +382,8 @@ BadGuy::set_state(State state)
       state_timer.start(SQUISH_TIME);
       break;
     case STATE_ACTIVE:
-      set_group(COLGROUP_MOVING);
-      bbox.set_pos(start_position);
+      set_group(colgroup_active);
+      //bbox.set_pos(start_position);
       break;
     case STATE_INACTIVE:
       // was the badguy dead anyway?
@@ -392,79 +403,40 @@ BadGuy::set_state(State state)
 bool
 BadGuy::is_offscreen()
 {
-  float scroll_x = Sector::current()->camera->get_translation().x;
-  float scroll_y = Sector::current()->camera->get_translation().y;
-
-  if(bbox.p2.x < scroll_x - X_OFFSCREEN_DISTANCE
-      || bbox.p1.x > scroll_x + X_OFFSCREEN_DISTANCE + SCREEN_WIDTH
-      || bbox.p2.y < scroll_y - Y_OFFSCREEN_DISTANCE
-      || bbox.p1.y > scroll_y + Y_OFFSCREEN_DISTANCE + SCREEN_HEIGHT)
-    return true;
-
-  return false;
+  Player* player = get_nearest_player();
+  if (!player) return false;
+  Vector dist = player->get_bbox().get_middle() - get_bbox().get_middle();
+  if ((dist.x <= X_OFFSCREEN_DISTANCE+32) && (dist.y <= Y_OFFSCREEN_DISTANCE+32)) {
+    return false;
+  }
+  return true;
 }
 
 void
 BadGuy::try_activate()
 {
-  float scroll_x = Sector::current()->camera->get_translation().x;
-  float scroll_y = Sector::current()->camera->get_translation().y;
-
-  /* Activate badguys if they're just around the screen to avoid
-   * the effect of having badguys suddenly popping up from nowhere.
-   */
-  //Badguy left of screen
-  if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
-      start_position.x < scroll_x - bbox.get_width() &&
-      start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
-      start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) {
-    if (start_dir != AUTO) dir = start_dir; else dir = RIGHT;
-    set_state(STATE_ACTIVE);
-    activate();
-  //Badguy right of screen
-  } else if (start_position.x > scroll_x +  SCREEN_WIDTH &&
-      start_position.x < scroll_x + SCREEN_WIDTH + X_OFFSCREEN_DISTANCE &&
-      start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
-      start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) {
-    if (start_dir != AUTO) dir = start_dir; else dir = LEFT;
+  // In SuperTux 0.1.x, Badguys were activated when Tux<->Badguy center distance was approx. <= ~668px
+  // This doesn't work for wide-screen monitors which give us a virt. res. of approx. 1066px x 600px
+  Player* player = get_nearest_player();
+  if (!player) return;
+  Vector dist = player->get_bbox().get_middle() - get_bbox().get_middle();
+  if ((fabsf(dist.x) <= X_OFFSCREEN_DISTANCE) && (fabsf(dist.y) <= Y_OFFSCREEN_DISTANCE)) {
     set_state(STATE_ACTIVE);
-    activate();
-  //Badguy over or under screen
-  } else if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
-       start_position.x < scroll_x + SCREEN_WIDTH + X_OFFSCREEN_DISTANCE &&
-       ((start_position.y > scroll_y + SCREEN_HEIGHT &&
-         start_position.y < scroll_y + SCREEN_HEIGHT + Y_OFFSCREEN_DISTANCE) ||
-        (start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
-         start_position.y < scroll_y - bbox.get_height()  ))) {
-     if (start_dir != AUTO) dir = start_dir;
-     else{
-         // if nearest player is to our right, start facing right
-         Player* player = get_nearest_player();
-         if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
-             dir = RIGHT;
-         } else {
-                dir = LEFT;
-         }
-     }
-     set_state(STATE_ACTIVE);
-     activate();
-  } else if(state == STATE_INIT
-      && start_position.x > scroll_x - X_OFFSCREEN_DISTANCE
-      && start_position.x < scroll_x + X_OFFSCREEN_DISTANCE + SCREEN_WIDTH
-      && start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE
-      && start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE + SCREEN_HEIGHT ) {
-    if (start_dir != AUTO) {
-      dir = start_dir;
-    } else {
-      // if nearest player is to our right, start facing right
-      Player* player = get_nearest_player();
-      if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
-       dir = RIGHT;
-      } else {
-       dir = LEFT;
+    if (!is_initialized) {
+
+      // if starting direction was set to AUTO, this is our chance to re-orient the badguy
+      if (start_dir == AUTO) {
+        Player* player = get_nearest_player();
+        if (player && (player->get_bbox().p1.x > get_bbox().p2.x)) {
+          dir = RIGHT;
+        } else {
+          dir = LEFT;
+        }
       }
+
+      initialize();
+      is_initialized = true;
     }
-    set_state(STATE_ACTIVE);
     activate();
   }
 }
@@ -541,7 +513,7 @@ BadGuy::freeze()
 void
 BadGuy::unfreeze()
 {
-  set_group(COLGROUP_MOVING);
+  set_group(colgroup_active);
   frozen = false;
 }
 
@@ -579,3 +551,11 @@ BadGuy::is_ignited() const
 {
   return ignited;
 }
+  
+void 
+BadGuy::set_colgroup_active(CollisionGroup group)
+{
+  this->colgroup_active = group;
+  if (state == STATE_ACTIVE) set_group(group); 
+}
+
index 31a5a2d..2af09d2 100644 (file)
@@ -162,6 +162,9 @@ protected:
   /** called each frame when the badguy is not activated. */
   virtual void inactive_update(float elapsed_time);
 
+  bool is_initialized; /**< true if initialize() has already been called */
+  /** called immediately before the first call to initialize */
+  virtual void initialize();
   /**
    * called when the badguy has been activated. (As a side effect the dir
    * variable might have been changed so that it faces towards the player.
@@ -181,8 +184,6 @@ protected:
    */
   Player* get_nearest_player();
 
-  /// is the enemy activated
-  bool activated;
   /**
    * initial position of the enemy. Also the position where enemy respawns when
    * after being deactivated.
@@ -238,6 +239,8 @@ protected:
    */
   bool is_active();
 
+  void set_colgroup_active(CollisionGroup group); /**< changes colgroup_active. Also calls set_group when badguy is in STATE_ACTIVE */
+
 private:
   void try_activate();
 
@@ -246,6 +249,7 @@ private:
   Timer state_timer;
   bool on_ground_flag; /**< true if we touched something solid from above and update_on_ground_flag was called last frame */
   Vector floor_normal; /**< floor normal stored the last time when update_on_ground_flag was called and we touched something solid from above */
+  CollisionGroup colgroup_active; /**< CollisionGroup the badguy should be in while active */
 
 };
 
index f84561b..ae9e91d 100644 (file)
@@ -46,7 +46,7 @@ BouncingSnowball::write(lisp::Writer& writer)
 }
 
 void
-BouncingSnowball::activate()
+BouncingSnowball::initialize()
 {
   physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
   sprite->set_action(dir == LEFT ? "left" : "right");
index ed2c5cb..933eb65 100644 (file)
@@ -28,7 +28,7 @@ public:
   BouncingSnowball(const lisp::Lisp& reader);
   BouncingSnowball(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
index c5ad86e..9df6e8c 100644 (file)
@@ -78,11 +78,15 @@ Dart::write(lisp::Writer& writer)
 }
 
 void
-Dart::activate()
+Dart::initialize()
 {
   physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
   sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
+}
 
+void
+Dart::activate()
+{
   sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
   sound_source->set_position(get_pos());
   sound_source->set_looping(true);
index b8807e0..0fb6dc3 100644 (file)
@@ -34,6 +34,7 @@ public:
   Dart(const Dart& dart);
   ~Dart();
 
+  void initialize();
   void activate();
   void deactivate();
   void write(lisp::Writer& writer);
index be6cc1d..41cc585 100644 (file)
@@ -35,6 +35,9 @@ DartTrap::DartTrap(const lisp::Lisp& reader)
   countMe = false;
   sound_manager->preload("sounds/dartfire.wav");
   if (start_dir == AUTO) log_warning << "Setting a DartTrap's direction to AUTO is no good idea" << std::endl;
+  state = IDLE;
+  set_colgroup_active(COLGROUP_DISABLED);
+  if (initial_delay == 0) initial_delay = 0.1f;
 }
 
 void
@@ -50,13 +53,14 @@ DartTrap::write(lisp::Writer& writer)
 }
 
 void
-DartTrap::activate()
+DartTrap::initialize()
 {
-  state = IDLE;
   sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
-  set_group(COLGROUP_DISABLED);
+}
 
-  if (initial_delay == 0) initial_delay = 0.1f;
+void
+DartTrap::activate()
+{
   fire_timer.start(initial_delay);
 }
 
index 1ba8059..da18766 100644 (file)
@@ -31,6 +31,7 @@ class DartTrap : public BadGuy
 public:
   DartTrap(const lisp::Lisp& reader);
 
+  void initialize();
   void activate();
   void write(lisp::Writer& writer);
   void active_update(float elapsed_time);
index 613f06e..c603946 100644 (file)
@@ -64,11 +64,6 @@ Dispenser::write(lisp::Writer& writer)
 void
 Dispenser::activate()
 {
-   if(frozen)
-     return;
-   if (badguy == "mrrocket") {
-      sprite->set_action(dir == LEFT ? "working-left" : "working-right");
-   }
    dispense_timer.start(cycle, true);
    launch_badguy();
 }
index 8035120..93898d4 100644 (file)
@@ -125,7 +125,7 @@ void
 Fish::start_waiting()
 {
   waiting.start(FISH_WAIT_TIME);
-  set_group(COLGROUP_DISABLED);
+  set_colgroup_active(COLGROUP_DISABLED);
   physic.enable_gravity(false);
   physic.set_velocity_y(0);
 }
@@ -135,7 +135,7 @@ Fish::jump()
 {
   physic.set_velocity_y(FISH_JUMP_POWER);
   physic.enable_gravity(true);
-  set_group(COLGROUP_MOVING);
+  set_colgroup_active(COLGROUP_MOVING);
 }
 
 void
index 7f8d356..8f035a7 100644 (file)
@@ -33,6 +33,8 @@ Flame::Flame(const lisp::Lisp& reader)
                       start_position.y + sin(angle) * radius));
   countMe = false;
   sound_manager->preload(SOUNDFILE);
+
+  set_colgroup_active(COLGROUP_TOUCHABLE);
 }
 
 void
@@ -62,8 +64,6 @@ Flame::active_update(float elapsed_time)
 void
 Flame::activate()
 {
-  set_group(COLGROUP_TOUCHABLE);
-
   sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
   sound_source->set_position(get_pos());
   sound_source->set_looping(true);
index a0abf23..9cc2363 100644 (file)
@@ -58,12 +58,17 @@ FlyingSnowBall::write(lisp::Writer& writer)
 }
 
 void
-FlyingSnowBall::activate()
+FlyingSnowBall::initialize()
 {
   sprite->set_action(dir == LEFT ? "left" : "right");
   mode = FLY_UP;
   physic.set_velocity_y(FLYSPEED);
   timer.start(FLYTIME/2);
+}
+
+void
+FlyingSnowBall::activate()
+{
   puff_timer.start(systemRandom.randf(PUFF_INTERVAL_MIN, PUFF_INTERVAL_MAX));
 }
 
index 43e9324..7a00ddb 100644 (file)
@@ -28,6 +28,7 @@ public:
   FlyingSnowBall(const lisp::Lisp& reader);
   FlyingSnowBall(const Vector& pos);
 
+  void initialize();
   void activate();
   void write(lisp::Writer& writer);
   void active_update(float elapsed_time);
index 973afa8..61b5d57 100644 (file)
@@ -38,6 +38,7 @@ GhostTree::GhostTree(const lisp::Lisp& lisp)
     treecolor(0), suck_lantern(0)
 {
   glow_sprite.reset(sprite_manager->create("images/creatures/ghosttree/ghosttree-glow.sprite"));
+  set_colgroup_active(COLGROUP_TOUCHABLE);
 }
 
 GhostTree::~GhostTree()
@@ -64,7 +65,6 @@ GhostTree::activate()
   willowisp_timer.start(1.0f, true);
   colorchange_timer.start(13, true);
   root_timer.start(5, true);
-  set_group(COLGROUP_TOUCHABLE);
 }
 
 void
index b8450d2..60bb104 100644 (file)
@@ -55,7 +55,7 @@ Igel::write(lisp::Writer& writer)
 void
 Igel::be_normal()
 {
-  activate();
+  initialize();
 }
 
 void
index cbfdd99..0022171 100644 (file)
@@ -52,7 +52,7 @@ Kugelblitz::write(lisp::Writer& writer)
 }
 
 void
-Kugelblitz::activate()
+Kugelblitz::initialize()
 {
   physic.set_velocity_y(300);
   physic.set_velocity_x(-20); //fall a little to the left
index 5f327f2..b169997 100644 (file)
@@ -29,7 +29,7 @@ class Kugelblitz : public BadGuy
 public:
   Kugelblitz(const lisp::Lisp& reader);
 
-  void activate();
+  void initialize();
   HitResponse collision_badguy(BadGuy& other, const CollisionHit& hit);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_player(Player& player, const CollisionHit& hit);
index 5132743..54dfe17 100644 (file)
@@ -138,27 +138,27 @@ Mole::set_state(MoleState new_state)
   switch (new_state) {
     case PRE_THROWING:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       timer.start(IDLE_TIME);
       break;
     case THROWING:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       timer.start(THROW_TIME);
       throw_timer.start(THROW_INTERVAL);
       break;
     case POST_THROWING:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       timer.start(IDLE_TIME);
       break;
     case PEEKING:
       sprite->set_action("peeking", 1);
-      set_group(COLGROUP_STATIC);
+      set_colgroup_active(COLGROUP_STATIC);
       break;
     case DEAD:
       sprite->set_action("idle");
-      set_group(COLGROUP_DISABLED);
+      set_colgroup_active(COLGROUP_DISABLED);
       break;
   }
 
index c9252ff..5de7914 100644 (file)
@@ -65,7 +65,7 @@ MoleRock::write(lisp::Writer& writer)
 }
 
 void
-MoleRock::activate()
+MoleRock::initialize()
 {
   physic.set_velocity(initial_velocity);
   sprite->set_action("default");
index 42a7e05..f5bb95b 100644 (file)
@@ -34,7 +34,7 @@ public:
   MoleRock(const MoleRock& mole_rock);
   ~MoleRock();
 
-  void activate();
+  void initialize();
   void deactivate();
   void write(lisp::Writer& writer);
 
index 93a58c2..cc74c01 100644 (file)
@@ -115,7 +115,7 @@ MrBomb::grab(MovingObject&, const Vector& pos, Direction dir)
   movement = pos - get_pos();
   this->dir = dir;
   sprite->set_action(dir == LEFT ? "iced-left" : "iced-right");
-  set_group(COLGROUP_DISABLED);
+  set_colgroup_active(COLGROUP_DISABLED);
   grabbed = true;
 }
 
@@ -123,7 +123,7 @@ void
 MrBomb::ungrab(MovingObject& , Direction dir)
 {
   this->dir = dir;
-  set_group(COLGROUP_MOVING);
+  set_colgroup_active(COLGROUP_MOVING);
   grabbed = false;
 }
 
index 481bf08..7cd8d86 100644 (file)
@@ -57,9 +57,9 @@ MrIceBlock::write(lisp::Writer& writer)
 }
 
 void
-MrIceBlock::activate()
+MrIceBlock::initialize()
 {
-  WalkingBadguy::activate();
+  WalkingBadguy::initialize();
   set_state(ICESTATE_NORMAL);
 }
 
@@ -227,7 +227,7 @@ MrIceBlock::set_state(IceState state)
 
   switch(state) {
     case ICESTATE_NORMAL:
-      WalkingBadguy::activate();
+      WalkingBadguy::initialize();
       break;
     case ICESTATE_FLAT:
       if(dir == UP) {
@@ -266,7 +266,7 @@ MrIceBlock::grab(MovingObject&, const Vector& pos, Direction dir)
   this->dir = dir;
   sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
   set_state(ICESTATE_GRABBED);
-  set_group(COLGROUP_DISABLED);
+  set_colgroup_active(COLGROUP_DISABLED);
 }
 
 void
@@ -274,7 +274,7 @@ MrIceBlock::ungrab(MovingObject& , Direction dir)
 {
   this->dir = dir;
   set_state(dir == UP ? ICESTATE_FLAT : ICESTATE_KICKED);
-  set_group(COLGROUP_MOVING);
+  set_colgroup_active(COLGROUP_MOVING);
 }
 
 bool
index 9d6eb97..ddf3847 100644 (file)
@@ -29,7 +29,7 @@ public:
   MrIceBlock(const lisp::Lisp& reader);
   MrIceBlock(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   HitResponse collision(GameObject& object, const CollisionHit& hit);
   void collision_solid(const CollisionHit& hit);
index 4ac7045..33c6020 100644 (file)
@@ -46,7 +46,7 @@ MrRocket::write(lisp::Writer& writer)
 }
 
 void
-MrRocket::activate()
+MrRocket::initialize()
 {
   physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED);
   physic.enable_gravity(false);
index 628df37..4ff1209 100644 (file)
@@ -29,7 +29,7 @@ public:
   MrRocket(const lisp::Lisp& reader);
   MrRocket(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void active_update(float elapsed_time);
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
index 5830d2b..27db59b 100644 (file)
@@ -42,7 +42,7 @@ Plant::write(lisp::Writer& writer)
 }
 
 void
-Plant::activate()
+Plant::initialize()
 {
   //FIXME: turns sspiky around for debugging
   dir = dir == LEFT ? RIGHT : LEFT;
index 7216514..97aea8b 100644 (file)
@@ -27,7 +27,7 @@ class Plant : public BadGuy
 public:
   Plant(const lisp::Lisp& reader);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
index cad33cb..5254687 100644 (file)
@@ -35,6 +35,7 @@ Root::Root(const Vector& pos)
   base_sprite->set_action("appearing", 1);
   base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action
   physic.enable_gravity(false);
+  set_colgroup_active(COLGROUP_TOUCHABLE);
 }
 
 Root::~Root()
@@ -42,12 +43,6 @@ Root::~Root()
 }
 
 void
-Root::activate()
-{
-  set_group(COLGROUP_TOUCHABLE);
-}
-
-void
 Root::deactivate()
 {
   remove_me(); 
index d693f23..b3a302c 100644 (file)
@@ -30,7 +30,6 @@ public:
   Root(const Vector& pos);
   ~Root();
 
-  void activate();
   void deactivate();
   void active_update(float elapsed_time);
   virtual void draw(DrawingContext& context);
index 76339f8..3c1fe3e 100644 (file)
@@ -52,7 +52,7 @@ SkullyHop::write(lisp::Writer& writer)
 }
 
 void
-SkullyHop::activate()
+SkullyHop::initialize()
 {
   // initial state is JUMPING, because we might start airborne
   state = JUMPING;
index 02624b7..970ed93 100644 (file)
@@ -32,7 +32,7 @@ public:
   SkullyHop(const lisp::Lisp& reader);
   SkullyHop(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
index d68aad7..33d1915 100644 (file)
@@ -57,9 +57,9 @@ Snail::write(lisp::Writer& writer)
 }
 
 void
-Snail::activate()
+Snail::initialize()
 {
-  WalkingBadguy::activate();
+  WalkingBadguy::initialize();
   be_normal();
 }
 
@@ -69,7 +69,7 @@ Snail::be_normal()
   if (state == STATE_NORMAL) return;
 
   state = STATE_NORMAL;
-  WalkingBadguy::activate();
+  WalkingBadguy::initialize();
 }
 
 void
index 642df55..0d31ca8 100644 (file)
@@ -31,7 +31,7 @@ public:
   Snail(const lisp::Lisp& reader);
   Snail(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
index 96a90a0..8ea7e74 100644 (file)
@@ -49,7 +49,7 @@ SpiderMite::write(lisp::Writer& writer)
 }
 
 void
-SpiderMite::activate()
+SpiderMite::initialize()
 {
   sprite->set_action(dir == LEFT ? "left" : "right");
   mode = FLY_UP;
index ee36b5b..1e17f09 100644 (file)
@@ -28,7 +28,7 @@ public:
   SpiderMite(const lisp::Lisp& reader);
   SpiderMite(const Vector& pos);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void active_update(float elapsed_time);
   void collision_solid(const CollisionHit& hit);
index ad80b8d..68ebaaa 100644 (file)
@@ -39,7 +39,7 @@ SSpiky::write(lisp::Writer& writer)
 }
 
 void
-SSpiky::activate()
+SSpiky::initialize()
 {
   state = SSPIKY_SLEEPING;
   physic.set_velocity_x(0);
@@ -99,7 +99,7 @@ SSpiky::active_update(float elapsed_time) {
     if(sprite->animation_done()) {
       // start walking
       state = SSPIKY_WALKING;
-      WalkingBadguy::activate();
+      WalkingBadguy::initialize();
     }
 
     BadGuy::active_update(elapsed_time);
index 8e346cd..b6a35ed 100644 (file)
@@ -27,7 +27,7 @@ class SSpiky : public WalkingBadguy
 public:
   SSpiky(const lisp::Lisp& reader);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
index 8bde2fb..8dc7f84 100644 (file)
@@ -72,7 +72,7 @@ void
 Stalactite::squish()
 {
   state = STALACTITE_SQUISHED;
-  set_group(COLGROUP_MOVING_ONLY_STATIC);
+  set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
   sprite->set_action("squished");
   if(!timer.started())
     timer.start(SQUISH_TIME);
index c53fe39..5f9b7ae 100644 (file)
@@ -55,7 +55,7 @@ Stumpy::write(lisp::Writer& writer)
 }
 
 void
-Stumpy::activate()
+Stumpy::initialize()
 {
   switch (mystate) {
     case STATE_INVINCIBLE:
@@ -64,7 +64,7 @@ Stumpy::activate()
       physic.set_velocity_x(0);
       break;
     case STATE_NORMAL:
-      WalkingBadguy::activate();
+      WalkingBadguy::initialize();
       break;
   }
 }
@@ -76,7 +76,7 @@ Stumpy::active_update(float elapsed_time)
     case STATE_INVINCIBLE:
       if (invincible_timer.check()) {
        mystate = STATE_NORMAL;
-        WalkingBadguy::activate();
+        WalkingBadguy::initialize();
       }
       BadGuy::active_update(elapsed_time);
       break;
index 80117fe..1559bfe 100644 (file)
@@ -28,7 +28,7 @@ public:
   Stumpy(const lisp::Lisp& reader);
   Stumpy(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void active_update(float elapsed_time);
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
index 26da7e3..3df4901 100644 (file)
@@ -51,7 +51,7 @@ Toad::write(lisp::Writer& writer)
 }
 
 void
-Toad::activate()
+Toad::initialize()
 {
   // initial state is JUMPING, because we might start airborne
   state = JUMPING;
index 8067162..bbdc35f 100644 (file)
@@ -32,7 +32,7 @@ public:
   Toad(const lisp::Lisp& reader);
   Toad(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
index 139aa14..cd4d975 100644 (file)
@@ -74,7 +74,7 @@ Totem::write(lisp::Writer& writer)
 }
 
 void
-Totem::activate()
+Totem::initialize()
 {
   if (!carried_by) {
     physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
@@ -96,7 +96,7 @@ Totem::active_update(float elapsed_time)
     if (on_ground() && might_fall())
     {
       dir = (dir == LEFT ? RIGHT : LEFT);
-      activate();
+      initialize();
     }
 
     Sector* s = Sector::current();
@@ -174,11 +174,11 @@ Totem::collision_solid(const CollisionHit& hit)
   // If we are hit from the direction we are facing: turn around
   if (hit.left && (dir == LEFT)) {
     dir = RIGHT;
-    activate();
+    initialize();
   }
   if (hit.right && (dir == RIGHT)) {
     dir = LEFT;
-    activate();
+    initialize();
   }
 }
 
@@ -205,11 +205,11 @@ Totem::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
   // If we are hit from the direction we are facing: turn around
   if(hit.left && (dir == LEFT)) {
     dir = RIGHT;
-    activate();
+    initialize();
   }
   if(hit.right && (dir == RIGHT)) {
     dir = LEFT;
-    activate();
+    initialize();
   }
 
   return CONTINUE;
@@ -235,7 +235,7 @@ Totem::jump_on(Totem* target)
   target->carrying = this;
 
   this->carried_by = target;
-  this->activate();
+  this->initialize();
   bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
 
   sound_manager->play( LAND_ON_TOTEM_SOUND , get_pos());
@@ -255,7 +255,7 @@ Totem::jump_off() {
 
   this->carried_by = 0;
 
-  this->activate();
+  this->initialize();
   bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
 
 
index 682fe45..74022c5 100644 (file)
@@ -33,7 +33,7 @@ public:
   Totem(const Totem& totem);
   ~Totem();
 
-  void activate();
+  void initialize();
   void active_update(float elapsed_time);
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
index e1eb027..4a0c06b 100644 (file)
@@ -38,6 +38,8 @@ TreeWillOWisp::TreeWillOWisp(GhostTree* tree, const Vector& pos,
   this->angle  = 0;
   this->speed  = speed;
   start_position = tree->get_pos() + treepos_delta;
+
+  set_colgroup_active(COLGROUP_MOVING);
 }
 
 TreeWillOWisp::~TreeWillOWisp()
@@ -53,8 +55,6 @@ TreeWillOWisp::activate()
   sound_source->set_gain(2.0);
   sound_source->set_reference_distance(32);
   sound_source->play();
-
-  set_group(COLGROUP_MOVING);
 }
 
 void
@@ -62,7 +62,7 @@ TreeWillOWisp::vanish()
 {
   mystate = STATE_VANISHING;
   sprite->set_action("vanishing", 1);
-  set_group(COLGROUP_DISABLED);
+  set_colgroup_active(COLGROUP_DISABLED);
 }
 
 void
index 3b8f7ab..fe57032 100644 (file)
@@ -46,7 +46,7 @@ WalkingBadguy::write(lisp::Writer& writer)
 }
 
 void
-WalkingBadguy::activate()
+WalkingBadguy::initialize()
 {
   if(frozen)
     return;
@@ -129,7 +129,7 @@ void
 WalkingBadguy::unfreeze()
 {
   BadGuy::unfreeze();
-  WalkingBadguy::activate();
+  WalkingBadguy::initialize();
 }
 
 
index 3200cb7..f5a7eb6 100644 (file)
@@ -34,7 +34,7 @@ public:
   WalkingBadguy(const Vector& pos, Direction direction, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer = LAYER_OBJECTS);
   WalkingBadguy(const lisp::Lisp& reader, const std::string& sprite_name, const std::string& walk_left_action, const std::string& walk_right_action, int layer = LAYER_OBJECTS);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void active_update(float elapsed_time);
   void collision_solid(const CollisionHit& hit);
index bc70de8..b0fe7c6 100644 (file)
@@ -60,6 +60,8 @@ WillOWisp::WillOWisp(const lisp::Lisp& reader)
   countMe = false;
   sound_manager->preload(SOUNDFILE);
   sound_manager->preload("sounds/warp.wav");
+
+  sprite->set_action("idle");
 }
 
 void
@@ -136,8 +138,6 @@ WillOWisp::active_update(float elapsed_time)
 void
 WillOWisp::activate()
 {
-  sprite->set_action("idle");
-
   sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
   sound_source->set_position(get_pos());
   sound_source->set_looping(true);
@@ -172,7 +172,7 @@ WillOWisp::vanish()
 {
   mystate = STATE_VANISHING;
   sprite->set_action("vanishing", 1);
-  set_group(COLGROUP_DISABLED);
+  set_colgroup_active(COLGROUP_DISABLED);
 }
 
 bool
index 2085551..1c03906 100644 (file)
@@ -67,7 +67,7 @@ Yeti::~Yeti()
 }
 
 void
-Yeti::activate()
+Yeti::initialize()
 {
   dir = RIGHT;
   jump_down();
@@ -219,7 +219,7 @@ void Yeti::take_hit(Player& )
 
     state = SQUISHED;
     state_timer.start(SQUISH_TIME);
-    set_group(COLGROUP_MOVING_ONLY_STATIC);
+    set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
     sprite->set_action("dead");
 
     if (countMe) Sector::current()->get_level()->stats.badguys++;
index cfc6d05..a3c996f 100644 (file)
@@ -33,7 +33,7 @@ public:
 
   void draw(DrawingContext& context);
   void write(lisp::Writer& writer);
-  void activate();
+  void initialize();
   void active_update(float elapsed_time);
   void collision_solid(const CollisionHit& hit);
   bool collision_squished(GameObject& object);
index 0ea43d6..ffea907 100644 (file)
@@ -29,12 +29,16 @@ Zeekling::Zeekling(const lisp::Lisp& reader)
        : BadGuy(reader, "images/creatures/zeekling/zeekling.sprite"), last_player(0)
 {
   state = FLYING;
+  speed = systemRandom.rand(130, 171);
+  physic.enable_gravity(false);
 }
 
 Zeekling::Zeekling(const Vector& pos, Direction d)
        : BadGuy(pos, d, "images/creatures/zeekling/zeekling.sprite"), last_player(0)
 {
   state = FLYING;
+  speed = systemRandom.rand(130, 171);
+  physic.enable_gravity(false);
 }
 
 void
@@ -49,11 +53,9 @@ Zeekling::write(lisp::Writer& writer)
 }
 
 void
-Zeekling::activate()
+Zeekling::initialize()
 {
-  speed = systemRandom.rand(130, 171);
   physic.set_velocity_x(dir == LEFT ? -speed : speed);
-  physic.enable_gravity(false);
   sprite->set_action(dir == LEFT ? "left" : "right");
 }
 
index 7958276..3979dd1 100644 (file)
@@ -30,7 +30,7 @@ public:
   Zeekling(const lisp::Lisp& reader);
   Zeekling(const Vector& pos, Direction d);
 
-  void activate();
+  void initialize();
   void write(lisp::Writer& writer);
   void collision_solid(const CollisionHit& hit);
   void active_update(float elapsed_time);