Badguys from the start of the level were not appearing. Fixed.
authorRicardo Cruz <rick2@aeiou.pt>
Thu, 21 Oct 2004 18:03:23 +0000 (18:03 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Thu, 21 Oct 2004 18:03:23 +0000 (18:03 +0000)
SVN-Revision: 2045

src/badguy.cpp
src/leveleditor.cpp
src/sector.cpp
src/sector.h

index b8f8f3b..e4f04ff 100644 (file)
@@ -161,8 +161,8 @@ BadGuy::init()
 {
   base.x = 0;
   base.y = 0;
-  base.width  = 0;
-  base.height = 0;
+  base.width  = 32;
+  base.height = 32;
   
   mode     = NORMAL;
   dying    = DYING_NOT;
@@ -188,20 +188,6 @@ BadGuy::init()
       while(collision_object_map(base))
         --base.y;
     }
-
-  if(Sector::current()->camera) {
-    Vector scroll = Sector::current()->camera->get_translation();
-
-    if(start_position.x > scroll.x - X_OFFSCREEN_DISTANCE &&
-        start_position.x < scroll.x + screen->w + X_OFFSCREEN_DISTANCE &&
-        start_position.y > scroll.y - Y_OFFSCREEN_DISTANCE &&
-        start_position.y < scroll.y + screen->h + Y_OFFSCREEN_DISTANCE) {
-      activate(LEFT);
-    }
-  } } else {
-    if(start_position.x >= 0 && start_position.x < screen->w
-        && start_position.y >= 0 && start_position.y < screen->h)
-      activate(LEFT);
   }
 }
 
@@ -229,7 +215,7 @@ BadGuy::activate(Direction activation_dir)
 
   dir = activation_dir;
   float dirsign = activation_dir == LEFT ? -1 : 1;
-  
+
   set_action("left", "right");
   if(kind == BAD_MRBOMB) {
     physic.set_velocity(dirsign * BADGUY_WALK_SPEED, 0);
@@ -772,14 +758,6 @@ BadGuy::action_spiky(double elapsed_time)
     check_horizontal_bump();
 
   fall();
-#if 0
-  // jump when we're about to fall
-  if (physic.get_velocity_y() == 0 && 
-          !issolid(base.x+base.width/2, base.y + base.height)) {
-    physic.enable_gravity(true);
-    physic.set_velocity_y(2);
-  }
-#endif
 
   physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
   if (dying != DYING_FALLING)
@@ -794,6 +772,13 @@ BadGuy::action_snowball(double elapsed_time)
 
   fall();
 
+  // jump when we're about to fall
+  if (physic.get_velocity_y() == 0 && 
+          !issolid(base.x+base.width/2, base.y + base.height)) {
+    physic.enable_gravity(true);
+    physic.set_velocity_y(2);
+  }
+
   physic.apply(elapsed_time, base.x, base.y, Sector::current()->gravity);
   if (dying != DYING_FALLING)
     collision_swept_object_map(&old_base,&base);
@@ -876,37 +861,44 @@ BadGuy::action(float elapsed_time)
          kill_me(0);
       }
 
-  if(!seen) {
-    /* activate badguys if they're just inside the offscreen_distance around the
-     * screen. Don't activate them inside the screen, since that might have the
-     * effect of badguys suddenly popping up from nowhere
+  if(!seen)
+    {
+    /* Activate badguys if they're just around the screen to avoid
+     * the effect of having badguys suddenly popping up from nowhere.
      */
     if (start_position.x > scroll_x - X_OFFSCREEN_DISTANCE &&
-        start_position.x < scroll_x - base.width)
+        start_position.x < scroll_x - base.width &&
+        start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
+        start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE)
       activate(RIGHT);
-    else if(start_position.x > scroll_y - Y_OFFSCREEN_DISTANCE &&
-        start_position.y < scroll_y - base.height)
+    else if (start_position.x > scroll_x + screen->w &&
+        start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
+        start_position.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
+        start_position.y < scroll_y + Y_OFFSCREEN_DISTANCE)
       activate(LEFT);
-    else if(start_position.x > scroll_x + screen->w &&
-        start_position.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE)
+    /* Special case for badguys on start of the level.
+     * If in the future, it's possible to set Tux start pos, this case
+     * should contemplate that. */
+    else if (start_position.x > 0 && start_position.x < screen->w &&
+             start_position.y > 0 && start_position.y < screen->h)
       activate(LEFT);
-    else if(start_position.y > scroll_y + screen->h &&
-        start_position.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
-      activate(LEFT);
-  } else {
+    }
+  else
+    {
     if(base.x + base.width < scroll_x - X_OFFSCREEN_DISTANCE*4
       || base.x > scroll_x + screen->w + X_OFFSCREEN_DISTANCE*4
       || base.y + base.height < scroll_y - Y_OFFSCREEN_DISTANCE*4
-      || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4) {
+      || base.y > scroll_y + screen->h + Y_OFFSCREEN_DISTANCE*4)
+      {
       seen = false;
       if(dying != DYING_NOT)
         remove_me();
+      }
     }
-  }
-  
+
   if(!seen)
     return;
-  
+
   switch (kind)
     {
     case BAD_MRICEBLOCK:
@@ -1007,7 +999,7 @@ BadGuy::set_action(std::string left, std::string right)
   else
     {
       // FIXME: Using the image size for the physics and collision is
-      // a bad idea, since images should always overlap there physical
+      // a bad idea, since images should always overlap their physical
       // representation
       if(left != 0) {
         if(base.width == 0 && base.height == 0) {
@@ -1205,7 +1197,7 @@ BadGuy::kill_me(int score)
 void
 BadGuy::explode(bool right_way)
 {
-  BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
+  BadGuy *badguy = Sector::current()->add_bad_guy(base.x, base.y, BAD_BOMB, true);
   if(right_way)
     {
     badguy->timer.start(0);
index 4e23130..9ce1e0e 100644 (file)
@@ -132,7 +132,7 @@ for(int i = 0; i < NUM_BadGuyKinds; i++)
 
   BadGuyKind kind = BadGuyKind(i);
   BadGuy badguy(kind, 0,0);
-//  badguy.activate(LEFT);
+  badguy.activate(LEFT);
 
   Surface *img = badguy.get_image();
   tiles_board->add_button(Button(img, "", SDLKey(SDLK_1+i)), -(i+1));
@@ -623,7 +623,7 @@ if(sector)
           {
           BadGuyKind kind = BadGuyKind((-id)-1);
           BadGuy badguy(kind, 0,0);
-//          badguy.activate(LEFT);
+          badguy.activate(LEFT);
           Surface *img = badguy.get_image();
 
           context.draw_surface(img, Vector(event.button.x - 8,
@@ -786,8 +786,8 @@ foregrounds = solids = backgrounds = 0;
 for(Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); i++)
   {
   BadGuy* badguy = dynamic_cast<BadGuy*> (*i);
-//  if(badguy)
-//    badguy->activate(LEFT);
+  if(badguy)
+    badguy->activate(LEFT);
 
   TileMap* tilemap = dynamic_cast<TileMap*> (*i);
   if(tilemap)
@@ -869,7 +869,7 @@ if(newtile < 0)  // add object
   else if(newtile == OBJ_DOOR)
     sector->add_object(new Door(x, y));
   else
-    sector->add_object(new BadGuy(BadGuyKind((-newtile)-1), x, y));
+    sector->add_bad_guy(x, y, BadGuyKind((-newtile)-1), true);
 
   sector->update_game_objects();
   }
index 316b22f..1420d7f 100644 (file)
@@ -701,10 +701,12 @@ Sector::add_bouncy_brick(const Vector& pos)
 }
 
 BadGuy*
-Sector::add_bad_guy(float x, float y, BadGuyKind kind)
+Sector::add_bad_guy(float x, float y, BadGuyKind kind, bool activate)
 {
   BadGuy* badguy = new BadGuy(kind, x, y);
   add_object(badguy);
+  if(activate)
+    badguy->activate(LEFT);
   return badguy;
 }
                                                                                 
index 7b6c6ca..467fd1d 100644 (file)
@@ -107,7 +107,7 @@ public:
       const Vector& movement, Tile* tile);
   void add_bouncy_brick(const Vector& pos);
                                                                                 
-  BadGuy* add_bad_guy(float x, float y, BadGuyKind kind);
+  BadGuy* add_bad_guy(float x, float y, BadGuyKind kind, bool activate);
                                                                                 
   void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind);
   bool add_bullet(const Vector& pos, float xm, Direction dir);