- coverted badguy type into an object
authorIngo Ruhnke <grumbel@gmx.de>
Wed, 24 Mar 2004 16:12:51 +0000 (16:12 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Wed, 24 Mar 2004 16:12:51 +0000 (16:12 +0000)
SVN-Revision: 336

src/badguy.cpp
src/badguy.h
src/collision.cpp
src/gameloop.cpp
src/level.cpp
src/leveleditor.cpp
src/player.cpp
src/scene.cpp
src/scene.h
src/texture.cpp
src/worldmap.cpp

index ad9de97..f174734 100644 (file)
@@ -31,156 +31,150 @@ texture_type img_laptop_right[3];
 texture_type img_money_left[2];
 texture_type img_money_right[2];
 
-bitmask *bm_bsod;
-
-void badguy_create_bitmasks()
-{
-  /*bm_bsod = img_bsod_left[0];*/
-}
-
-void badguy_init(bad_guy_type* pbad, float x, float y, BadGuyKind kind)
+void
+BadGuy::init(float x, float y, BadGuyKind kind_)
 {
-  pbad->base.width  = 32;
-  pbad->base.height = 32;
-  pbad->mode     = NORMAL;
-  pbad->dying    = DYING_NOT;
-  pbad->kind     = kind;
-  pbad->base.x   = x;
-  pbad->base.y   = y;
-  pbad->base.xm  = 1.3;
-  pbad->base.ym  = 4.8;
-  pbad->old_base = pbad->base;
-  pbad->dir      = LEFT;
-  pbad->seen     = false;
-  timer_init(&pbad->timer, true);
-  physic_init(&pbad->physic);
+  base.width  = 32;
+  base.height = 32;
+  mode     = NORMAL;
+  dying    = DYING_NOT;
+  kind     = kind_;
+  base.x   = x;
+  base.y   = y;
+  base.xm  = 1.3;
+  base.ym  = 4.8;
+  old_base = base;
+  dir      = LEFT;
+  seen     = false;
+  timer_init(&timer, true);
+  physic_init(&physic);
 }
 
-void badguy_action_bsod(bad_guy_type* pbad)
+void BadGuy::action_bsod()
 {
   /* --- BLUE SCREEN OF DEATH MONSTER: --- */
 
   /* Move left/right: */
-  if (pbad->dying == DYING_NOT ||
-      pbad->dying == DYING_FALLING)
+  if (dying == DYING_NOT ||
+      dying == DYING_FALLING)
     {
-      if (pbad->dir == RIGHT)
-        pbad->base.x = pbad->base.x + pbad->base.xm * frame_ratio;
-      else if (pbad->dir == LEFT)
-        pbad->base.x = pbad->base.x - pbad->base.xm * frame_ratio;
+      if (dir == RIGHT)
+        base.x = base.x + base.xm * frame_ratio;
+      else if (dir == LEFT)
+        base.x = base.x - base.xm * frame_ratio;
     }
 
 
   /* Move vertically: */
 
-  pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
+  base.y = base.y + base.ym * frame_ratio;
 
-  if (pbad->dying != DYING_FALLING)
-    collision_swept_object_map(&pbad->old_base,&pbad->base);
-  if (pbad->base.y > screen->h)
-    bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
+  if (dying != DYING_FALLING)
+    collision_swept_object_map(&old_base,&base);
+  if (base.y > screen->h)
+    bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(this));
                
   /* Bump into things horizontally: */
 
-  if (!pbad->dying)
+  if (!dying)
     {
-      if (issolid( pbad->base.x, (int) pbad->base.y + 16))
+      if (issolid( base.x, (int) base.y + 16))
         {
-          pbad->dir = RIGHT;
+          dir = RIGHT;
         }
-      else if (issolid( pbad->base.x + pbad->base.width, (int) pbad->base.y + 16))
+      else if (issolid( base.x + base.width, (int) base.y + 16))
         {
-          pbad->dir = LEFT;
+          dir = LEFT;
         }
     }
 
   /* Fall if we get off the ground: */
 
-  if (pbad->dying != DYING_FALLING)
+  if (dying != DYING_FALLING)
     {
-      if (!issolid(pbad->base.x+16, pbad->base.y + 32))
+      if (!issolid(base.x+16, base.y + 32))
         {
-          if(!physic_is_set(&pbad->physic))
+          if(!physic_is_set(&physic))
             {
-              physic_set_state(&pbad->physic,PH_VT);
-              physic_set_start_vy(&pbad->physic,2.);
+              physic_set_state(&physic,PH_VT);
+              physic_set_start_vy(&physic,2.);
             }
 
-          pbad->base.ym = physic_get_velocity(&pbad->physic);
+          base.ym = physic_get_velocity(&physic);
         }
       else
         {
           /* Land: */
 
-          if (pbad->base.ym > 0)
+          if (base.ym > 0)
             {
-              pbad->base.y = (int)(pbad->base.y / 32) * 32;
-              pbad->base.ym = 0;
+              base.y = (int)(base.y / 32) * 32;
+              base.ym = 0;
             }
-          physic_init(&pbad->physic);
+          physic_init(&physic);
         }
     }
   else
     {
-      if(!physic_is_set(&pbad->physic))
+      if(!physic_is_set(&physic))
         {
-          physic_set_state(&pbad->physic,PH_VT);
-          physic_set_start_vy(&pbad->physic,2.);
+          physic_set_state(&physic,PH_VT);
+          physic_set_start_vy(&physic,2.);
         }
-      pbad->base.ym = physic_get_velocity(&pbad->physic);
+      base.ym = physic_get_velocity(&physic);
     }
 
-  if (pbad->base.y > screen->h)
-    bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
+  if (base.y > screen->h)
+    bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(this));
 }
 
-void badguy_action_laptop(bad_guy_type* pbad)
+void BadGuy::action_laptop()
 {
   /* --- LAPTOP MONSTER: --- */
 
   /* Move left/right: */
 
-  if (pbad->mode == NORMAL || pbad->mode == KICK)
+  if (mode == NORMAL || mode == KICK)
     {
-      if (pbad->dying == DYING_NOT ||
-          pbad->dying == DYING_FALLING)
+      if (dying == DYING_NOT ||
+          dying == DYING_FALLING)
         {
-          if (pbad->dir == RIGHT)
-            pbad->base.x = pbad->base.x + pbad->base.xm * frame_ratio;
-          else if (pbad->dir == LEFT)
-            pbad->base.x = pbad->base.x - pbad->base.xm * frame_ratio;
+          if (dir == RIGHT)
+            base.x = base.x + base.xm * frame_ratio;
+          else if (dir == LEFT)
+            base.x = base.x - base.xm * frame_ratio;
         }
     }
-  else if (pbad->mode == HELD)
+  else if (mode == HELD)
     { /* FIXME: The pbad object shouldn't know about pplayer objects. */
       /* If we're holding the laptop */
-      pbad->dir=tux.dir;
-      if(pbad->dir==RIGHT)
+      dir=tux.dir;
+      if(dir==RIGHT)
         {
-          pbad->base.x = tux.base.x + 16;
-          pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height;
+          base.x = tux.base.x + 16;
+          base.y = tux.base.y + tux.base.height/1.5 - base.height;
         }
       else /* facing left */
         {
-          pbad->base.x = tux.base.x - 16;
-          pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height;
+          base.x = tux.base.x - 16;
+          base.y = tux.base.y + tux.base.height/1.5 - base.height;
         }
-      if(collision_object_map(&pbad->base))
+      if(collision_object_map(&base))
         {
-          pbad->base.x = tux.base.x;
-          pbad->base.y = tux.base.y + tux.base.height/1.5 - pbad->base.height;
+          base.x = tux.base.x;
+          base.y = tux.base.y + tux.base.height/1.5 - base.height;
         }
 
       if(tux.input.fire != DOWN) /* SHOOT! */
         {
-          if(pbad->dir == LEFT)
-            pbad->base.x -= 24;
+          if(dir == LEFT)
+            base.x -= 24;
           else
-            pbad->base.x += 24;
+            base.x += 24;
 
-          pbad->mode=KICK;
-          pbad->base.xm = 8;
-          pbad->base.ym = 8;
+          mode=KICK;
+          base.xm = 8;
+          base.ym = 8;
           play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
         }
     }
@@ -188,35 +182,35 @@ void badguy_action_laptop(bad_guy_type* pbad)
 
   /* Move vertically: */
 
-  if(pbad->mode != HELD)
-    pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
+  if(mode != HELD)
+    base.y = base.y + base.ym * frame_ratio;
 
-  if (pbad->dying != DYING_FALLING)
-    collision_swept_object_map(&pbad->old_base,&pbad->base);
-  if (pbad->base.y > screen->h)
-    bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
+  if (dying != DYING_FALLING)
+    collision_swept_object_map(&old_base,&base);
+  if (base.y > screen->h)
+    bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(this));
   /* Bump into things horizontally: */
 
   /* Bump into things horizontally: */
 
-  if (!pbad->dying)
+  if (!dying)
     {
-      int changed = pbad->dir;
-      if (issolid( pbad->base.x, (int) pbad->base.y + 16))
+      int changed = dir;
+      if (issolid( base.x, (int) base.y + 16))
         {
-          pbad->dir = RIGHT;
+          dir = RIGHT;
         }
-      else if (issolid( pbad->base.x + pbad->base.width, (int) pbad->base.y + 16))
+      else if (issolid( base.x + base.width, (int) base.y + 16))
         {
-          pbad->dir = LEFT;
+          dir = LEFT;
         }
-      if(pbad->mode == KICK && changed != pbad->dir)
+      if(mode == KICK && changed != dir)
         {
           /* handle stereo sound */
           /* FIXME: In theory a badguy object doesn't know anything about player objects */
-          if (tux.base.x  > pbad->base.x)
+          if (tux.base.x  > base.x)
             play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
-          else if (tux.base.x  < pbad->base.x)
+          else if (tux.base.x  < base.x)
             play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
           else
             play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
@@ -227,321 +221,321 @@ void badguy_action_laptop(bad_guy_type* pbad)
 
   /* Fall if we get off the ground: */
 
-  if (pbad->dying != DYING_FALLING)
+  if (dying != DYING_FALLING)
     {
-      if (!issolid(pbad->base.x+16, pbad->base.y + 32))
+      if (!issolid(base.x+16, base.y + 32))
         {
-          if(!physic_is_set(&pbad->physic))
+          if(!physic_is_set(&physic))
             {
-              physic_set_state(&pbad->physic,PH_VT);
-              physic_set_start_vy(&pbad->physic,0.);
+              physic_set_state(&physic,PH_VT);
+              physic_set_start_vy(&physic,0.);
             }
 
-          if(pbad->mode != HELD)
+          if(mode != HELD)
             {
-              pbad->base.ym = physic_get_velocity(&pbad->physic);
+              base.ym = physic_get_velocity(&physic);
             }
         }
       else
         {
           /* Land: */
 
-          if (pbad->base.ym > 0)
+          if (base.ym > 0)
             {
-              pbad->base.y = (int)(pbad->base.y / 32) * 32;
-              pbad->base.ym = 0;
+              base.y = (int)(base.y / 32) * 32;
+              base.ym = 0;
             }
-          physic_init(&pbad->physic);
+          physic_init(&physic);
         }
     }
   else
     {
-      if(!physic_is_set(&pbad->physic))
+      if(!physic_is_set(&physic))
         {
-          physic_set_state(&pbad->physic,PH_VT);
-          physic_set_start_vy(&pbad->physic,0.);
+          physic_set_state(&physic,PH_VT);
+          physic_set_start_vy(&physic,0.);
         }
-      pbad->base.ym = physic_get_velocity(&pbad->physic);
+      base.ym = physic_get_velocity(&physic);
     }
 }
 
-void badguy_action_money(bad_guy_type* pbad)
+void BadGuy::action_money()
 {
   /* --- MONEY BAGS: --- */
 
 
   /* Move vertically: */
 
-  pbad->base.y = pbad->base.y + pbad->base.ym * frame_ratio;
+  base.y = base.y + base.ym * frame_ratio;
 
-  if (pbad->dying != DYING_FALLING)
-    collision_swept_object_map(&pbad->old_base,&pbad->base);
+  if (dying != DYING_FALLING)
+    collision_swept_object_map(&old_base,&base);
 
-  if (pbad->base.y > screen->h)
-    bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
+  if (base.y > screen->h)
+    bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(this));
 
-  if(physic_get_state(&pbad->physic) == -1)
+  if(physic_get_state(&physic) == -1)
     {
-      physic_set_state(&pbad->physic,PH_VT);
-      physic_set_start_vy(&pbad->physic,0.);
+      physic_set_state(&physic,PH_VT);
+      physic_set_start_vy(&physic,0.);
     }
 
-  if (pbad->dying != DYING_FALLING)
+  if (dying != DYING_FALLING)
     {
-      if(issolid(pbad->base.x, pbad->base.y + 32))
+      if(issolid(base.x, base.y + 32))
         {
-          physic_set_state(&pbad->physic,PH_VT);
-          physic_set_start_vy(&pbad->physic,6.);
-          pbad->base.ym = physic_get_velocity(&pbad->physic);
+          physic_set_state(&physic,PH_VT);
+          physic_set_start_vy(&physic,6.);
+          base.ym = physic_get_velocity(&physic);
         }
-      else if(issolid(pbad->base.x, pbad->base.y))
+      else if(issolid(base.x, base.y))
         { /* This works, but isn't the best solution imagineable */
-          physic_set_state(&pbad->physic,PH_VT);
-          physic_set_start_vy(&pbad->physic,0.);
-          pbad->base.ym = physic_get_velocity(&pbad->physic);
-          ++pbad->base.y;
+          physic_set_state(&physic,PH_VT);
+          physic_set_start_vy(&physic,0.);
+          base.ym = physic_get_velocity(&physic);
+          ++base.y;
         }
       else
         {
-          pbad->base.ym = physic_get_velocity(&pbad->physic);
+          base.ym = physic_get_velocity(&physic);
         }
     }
   else
     {
-      if(!physic_is_set(&pbad->physic))
+      if(!physic_is_set(&physic))
         {
-          physic_set_state(&pbad->physic,PH_VT);
-          physic_set_start_vy(&pbad->physic,0.);
+          physic_set_state(&physic,PH_VT);
+          physic_set_start_vy(&physic,0.);
         }
-      pbad->base.ym = physic_get_velocity(&pbad->physic);
+      base.ym = physic_get_velocity(&physic);
     } 
 }
 
-void badguy_action(bad_guy_type* pbad)
+void
+BadGuy::action()
 { 
-  if (pbad->seen)
+  if (seen)
     {
-      switch (pbad->kind)
+      switch (kind)
         {
         case BAD_BSOD:
-          badguy_action_bsod(pbad);
+          action_bsod();
           break;
     
         case BAD_LAPTOP:
-          badguy_action_bsod(pbad);
+          action_bsod();
           break;
       
         case BAD_MONEY:
-          badguy_action_money(pbad);
+          action_money();
           break;
         }
     }
 
   /* Handle mode timer: */
-  if (pbad->mode == FLAT && pbad->mode != HELD)
+  if (mode == FLAT && mode != HELD)
     {
-      if(!timer_check(&pbad->timer))
+      if(!timer_check(&timer))
         {
-          pbad->mode = NORMAL;
-          pbad->base.xm = 4;
+          mode = NORMAL;
+          base.xm = 4;
         }
     }
-  else if (pbad->mode == KICK)
+  else if (mode == KICK)
     {
-      timer_check(&pbad->timer);
+      timer_check(&timer);
     }
 
   // Handle dying timer:
-  if (pbad->dying == DYING_SQUISHED)
+  if (dying == DYING_SQUISHED)
     {
       /* Remove it if time's up: */
-      if(!timer_check(&pbad->timer))
-        bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
+      if(!timer_check(&timer))
+        bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(this));
     }
 
   // Remove if it's far off the screen:
-  if (pbad->base.x < scroll_x - OFFSCREEN_DISTANCE)
+  if (base.x < scroll_x - OFFSCREEN_DISTANCE)
     {
-      bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(pbad));
+      bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(this));
       return;
     }
   else /* !seen */
     {
       // Once it's on screen, it's activated!
-      if (pbad->base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
-        pbad->seen = true;
+      if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
+        seen = true;
     }
 }
 
-void badguy_draw_bsod(bad_guy_type* pbad)
+void
+BadGuy::draw_bsod()
 {
   /* --- BLUE SCREEN OF DEATH MONSTER: --- */
-  if (pbad->dying == DYING_NOT)
+  if (dying == DYING_NOT)
     {
       /* Alive: */
-
-      if (pbad->dir == LEFT)
+      if (dir == LEFT)
         {
           texture_draw(&img_bsod_left[(frame / 5) % 4],
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
       else
         {
           texture_draw(&img_bsod_right[(frame / 5) % 4],
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
     }
-  else if (pbad->dying == DYING_FALLING)
+  else if (dying == DYING_FALLING)
     {
       /* Falling: */
 
-      if (pbad->dir == LEFT)
+      if (dir == LEFT)
         {
           texture_draw(&img_bsod_falling_left,
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
       else
         {
           texture_draw(&img_bsod_falling_right,
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
     }
-  else if (pbad->dying == DYING_SQUISHED)
+  else if (dying == DYING_SQUISHED)
     {
       /* Dying - Squished: */
 
-      if (pbad->dir == LEFT)
+      if (dir == LEFT)
         {
           texture_draw(&img_bsod_squished_left,
-                       pbad->base.x - scroll_x,
-                       pbad->base.y + 24);
+                       base.x - scroll_x,
+                       base.y + 24);
         }
       else
         {
           texture_draw(&img_bsod_squished_right,
-                       pbad->base.x - scroll_x,
-                       pbad->base.y + 24);
+                       base.x - scroll_x,
+                       base.y + 24);
         }
     }
 }
 
-void badguy_draw_laptop(bad_guy_type* pbad)
+void BadGuy::draw_laptop()
 {
   /* --- LAPTOP MONSTER: --- */
-  if (pbad->dying == DYING_NOT)
+  if (dying == DYING_NOT)
     {
       /* Alive: */
 
-      if (pbad->mode == NORMAL)
+      if (mode == NORMAL)
         {
           /* Not flat: */
-
-          if (pbad->dir == LEFT)
+          if (dir == LEFT)
             {
               texture_draw(&img_laptop_left[(frame / 5) % 3],
-                           pbad->base.x - scroll_x,
-                           pbad->base.y);
+                           base.x - scroll_x,
+                           base.y);
             }
           else
             {
               texture_draw(&img_laptop_right[(frame / 5) % 3],
-                           pbad->base.x - scroll_x,
-                           pbad->base.y);
+                           base.x - scroll_x,
+                           base.y);
             }
         }
       else
         {
           /* Flat: */
 
-          if (pbad->dir == LEFT)
+          if (dir == LEFT)
             {
               texture_draw(&img_laptop_flat_left,
-                           pbad->base.x - scroll_x,
-                           pbad->base.y);
+                           base.x - scroll_x,
+                           base.y);
             }
           else
             {
               texture_draw(&img_laptop_flat_right,
-                           pbad->base.x - scroll_x,
-                           pbad->base.y);
+                           base.x - scroll_x,
+                           base.y);
             }
         }
     }
-  else if (pbad->dying == DYING_FALLING)
+  else if (dying == DYING_FALLING)
     {
       /* Falling: */
 
-      if (pbad->dir == LEFT)
+      if (dir == LEFT)
         {
           texture_draw(&img_laptop_falling_left,
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
       else
         {
           texture_draw(&img_laptop_falling_right,
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
     }
 }
 
-void badguy_draw_money(bad_guy_type* pbad)
+void BadGuy::draw_money()
 {
-  if (pbad->base.ym != 300 /* > -16*/)
+  if (base.ym != 300 /* > -16*/)
     {
-      if (pbad->dir == LEFT)
+      if (dir == LEFT)
         {
           texture_draw(&img_money_left[0],
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
       else
         {
           texture_draw(&img_money_right[0],
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
     }
   else
     {
-      if (pbad->dir == LEFT)
+      if (dir == LEFT)
         {
           texture_draw(&img_money_left[1],
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
       else
         {
           texture_draw(&img_money_right[1],
-                       pbad->base.x - scroll_x,
-                       pbad->base.y);
+                       base.x - scroll_x,
+                       base.y);
         }
     }
 }
 
-void badguy_draw(bad_guy_type* pbad)
+void BadGuy::draw()
 {
   // Don't try to draw stuff that is outside of the screen
-  if (pbad->base.x > scroll_x - 32 &&
-      pbad->base.x < scroll_x + screen->w)
+  if (base.x > scroll_x - 32 &&
+      base.x < scroll_x + screen->w)
     {
-      switch (pbad->kind)
+      switch (kind)
         {
         case BAD_BSOD:
-          badguy_draw_bsod(pbad);
+          draw_bsod();
           break;
     
         case BAD_LAPTOP:
-          badguy_draw_laptop(pbad);
+          draw_laptop();
           break;
     
         case BAD_MONEY:
-          badguy_draw_money(pbad);
+          draw_money();
           break;
 
         default:
@@ -551,27 +545,27 @@ void badguy_draw(bad_guy_type* pbad)
     }
 }
 
-void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object)
+void
+BadGuy::collision(void *p_c_object, int c_object)
 {
-  bad_guy_type* pbad_c = NULL;
-  player_type* pplayer_c = NULL;
+  BadGuy* pbad_c    = NULL;
+  player_type*  pplayer_c = NULL;
 
   switch (c_object)
     {
     case CO_BULLET:
-      pbad->dying = DYING_FALLING;
-      pbad->base.ym = -8;
+      dying = DYING_FALLING;
+      base.ym = -8;
 
       /* Gain some points: */
-
-      if (pbad->kind == BAD_BSOD)
-        add_score(pbad->base.x - scroll_x, pbad->base.y,
+      if (kind == BAD_BSOD)
+        add_score(base.x - scroll_x, base.y,
                   50 * score_multiplier);
-      else if (pbad->kind == BAD_LAPTOP)
-        add_score(pbad->base.x - scroll_x, pbad->base.y,
+      else if (kind == BAD_LAPTOP)
+        add_score(base.x - scroll_x, base.y,
                   25 * score_multiplier);
-      else if (pbad->kind == BAD_MONEY)
-        add_score(pbad->base.x - scroll_x, pbad->base.y,
+      else if (kind == BAD_MONEY)
+        add_score(base.x - scroll_x, base.y,
                   50 * score_multiplier);
 
       /* Play death sound: */
@@ -579,12 +573,12 @@ void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object)
       break;
 
     case CO_BADGUY:
-      pbad_c = (bad_guy_type*) p_c_object;
-      if (pbad->mode == NORMAL)
+      pbad_c = (BadGuy*) p_c_object;
+      if (mode == NORMAL)
       {
       /* do nothing */
       }
-      else if(pbad->mode == KICK)
+      else if(mode == KICK)
         {
           /* We're in kick mode, kill the other guy
             and yourself(wuahaha) : */
@@ -593,12 +587,12 @@ void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object)
           pbad_c->base.ym = -8;
           play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
 
-          add_score(pbad->base.x - scroll_x,
-                    pbad->base.y, 100);
+          add_score(base.x - scroll_x,
+                    base.y, 100);
                  pbad_c->dying = DYING_FALLING;
                  
-          pbad->dying = DYING_FALLING;
-          pbad->base.ym = -8;
+          dying = DYING_FALLING;
+          base.ym = -8;
 
           add_score(pbad_c->base.x - scroll_x,
                     pbad_c->base.y, 100);
@@ -607,60 +601,60 @@ void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object)
 
     case CO_PLAYER:
       pplayer_c = (player_type*) p_c_object;
-      if(pbad->kind != BAD_MONEY)
+      if(kind != BAD_MONEY)
         {
-          if (pbad->kind == BAD_BSOD)
+          if (kind == BAD_BSOD)
             {
-              pbad->dying = DYING_SQUISHED;
-              timer_start(&pbad->timer,4000);
+              dying = DYING_SQUISHED;
+              timer_start(&timer,4000);
               physic_set_state(&pplayer_c->vphysic,PH_VT);
               physic_set_start_vy(&pplayer_c->vphysic,2.);
-             pplayer_c->base.y = pbad->base.y - pplayer_c->base.height - 1;
+             pplayer_c->base.y = base.y - pplayer_c->base.height - 1;
 
-              add_score(pbad->base.x - scroll_x, pbad->base.y,
+              add_score(base.x - scroll_x, base.y,
                         50 * score_multiplier);
 
               play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
             }
-          else if (pbad->kind == BAD_LAPTOP)
+          else if (kind == BAD_LAPTOP)
             {
 
-              if (pbad->mode == NORMAL || pbad->mode == KICK)
+              if (mode == NORMAL || mode == KICK)
                 {
                   /* Flatten! */
 
                   play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
-                  pbad->mode = FLAT;
-                  pbad->base.xm = 4;
+                  mode = FLAT;
+                  base.xm = 4;
 
-                  timer_start(&pbad->timer,10000);
+                  timer_start(&timer,10000);
 
                   physic_set_state(&pplayer_c->vphysic,PH_VT);
                   physic_set_start_vy(&pplayer_c->vphysic,2.);
-                 pplayer_c->base.y = pbad->base.y - pplayer_c->base.height - 1;
+                 pplayer_c->base.y = base.y - pplayer_c->base.height - 1;
                 }
-              else if (pbad->mode == FLAT)
+              else if (mode == FLAT)
                 {
                   /* Kick! */
                   play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
 
-                  if (pplayer_c->base.x < pbad->base.x + (pbad->base.width/2))
-                    pbad->dir = RIGHT;
+                  if (pplayer_c->base.x < base.x + (base.width/2))
+                    dir = RIGHT;
                   else
-                    pbad->dir = LEFT;
+                    dir = LEFT;
 
-                  pbad->base.xm = 5;
-                 pbad->mode = KICK;
+                  base.xm = 5;
+                 mode = KICK;
 
-                  timer_start(&pbad->timer,5000);
+                  timer_start(&timer,5000);
                 }
                
               physic_set_state(&pplayer_c->vphysic,PH_VT);
               physic_set_start_vy(&pplayer_c->vphysic,2.);
-             pplayer_c->base.y = pbad->base.y - pplayer_c->base.height - 1;
+             pplayer_c->base.y = base.y - pplayer_c->base.height - 1;
              
-              add_score(pbad->base.x - scroll_x,
-                        pbad->base.y,
+              add_score(base.x - scroll_x,
+                        base.y,
                         25 * score_multiplier);
 
               /* play_sound(sounds[SND_SQUISH]); */
@@ -671,3 +665,5 @@ void badguy_collision(bad_guy_type* pbad, void *p_c_object, int c_object)
     }
 
 }
+
+// EOF //
index 07034c3..9a1869a 100644 (file)
 #define KICK 2
 #define HELD 3
 
+extern texture_type img_bsod_squished_left;
+extern texture_type img_bsod_squished_right;
+extern texture_type img_bsod_falling_left;
+extern texture_type img_bsod_falling_right;
+extern texture_type img_laptop_flat_left;
+extern texture_type img_laptop_flat_right;
+extern texture_type img_laptop_falling_left;
+extern texture_type img_laptop_falling_right;
+extern texture_type img_bsod_left[4];
+extern texture_type img_bsod_right[4];
+extern texture_type img_laptop_left[3];
+extern texture_type img_laptop_right[3];
+extern texture_type img_money_left[2];
+extern texture_type img_money_right[2];
+
 /* Bad guy kinds: */
 enum BadGuyKind {
   BAD_BSOD,
@@ -35,53 +50,35 @@ enum BadGuyKind {
 };
 
 /* Badguy type: */
-struct bad_guy_type
+class BadGuy
 {
+ public:
   int mode;
   DyingType dying;
   BadGuyKind kind;
   bool seen;
   int dir;
-  int frame;
   base_type base;
   base_type old_base;
   timer_type timer;
   physic_type physic;
-};
-
-extern texture_type img_bsod_squished_left;
-extern texture_type img_bsod_squished_right;
-extern texture_type img_bsod_falling_left;
-extern texture_type img_bsod_falling_right;
-extern texture_type img_laptop_flat_left;
-extern texture_type img_laptop_flat_right;
-extern texture_type img_laptop_falling_left;
-extern texture_type img_laptop_falling_right;
-extern texture_type img_bsod_left[4];
-extern texture_type img_bsod_right[4];
-extern texture_type img_laptop_left[3];
-extern texture_type img_laptop_right[3];
-extern texture_type img_money_left[2];
-extern texture_type img_money_right[2];
-
-extern bitmask *bm_bsod;
 
-void badguy_create_bitmasks();
+ public:
+  void init(float x, float y, BadGuyKind kind);
 
-void badguy_init(bad_guy_type* pbad, float x, float y, BadGuyKind kind);
+  void action();
+  void draw();
 
-void badguy_action(bad_guy_type* pbad);
-void badguy_draw(bad_guy_type* pbad);
+  void action_bsod();
+  void action_laptop();
+  void action_money();
 
-void badguy_action_bsod(bad_guy_type* pbad);
-void badguy_action_laptop(bad_guy_type* pbad);
-void badguy_action_money(bad_guy_type* pbad);
+  void draw_bsod();
+  void draw_laptop();
+  void draw_money();
 
-void badguy_draw_bsod(bad_guy_type* pbad);
-void badguy_draw_laptop(bad_guy_type* pbad);
-void badguy_draw_money(bad_guy_type* pbad);
-
-void badguy_collision(bad_guy_type* pbad, void* p_c_object, int c_object);
+  void collision(void* p_c_object, int c_object);
+};
 
 #endif /*SUPERTUX_BADGUY_H*/
 
index 82be6bc..0dc2d35 100644 (file)
@@ -219,7 +219,7 @@ void collision_handler()
                 {
                   /* We have detected a collision and now call the collision functions of the collided objects. */
                   bullet_collision(&bullets[i], CO_BADGUY);
-                  badguy_collision(&bad_guys[j], &bullets[i], CO_BULLET);
+                  bad_guys[j].collision(&bullets[i], CO_BULLET);
                 }
             }
         }
@@ -237,8 +237,8 @@ void collision_handler()
                   if(rectcollision(&bad_guys[i].base, &bad_guys[j].base))
                     {
                       /* We have detected a collision and now call the collision functions of the collided objects. */
-                      badguy_collision(&bad_guys[j], &bad_guys[i], CO_BADGUY);
-                      badguy_collision(&bad_guys[i], &bad_guys[j], CO_BADGUY);
+                      bad_guys[j].collision(&bad_guys[i], CO_BADGUY);
+                      bad_guys[i].collision(&bad_guys[j], CO_BADGUY);
                     }
                 }
             }
@@ -257,7 +257,7 @@ void collision_handler()
               tux.previous_base.y + tux.previous_base.height < bad_guys[i].base.y + bad_guys[i].base.height/2 &&
               bad_guys[i].kind != BAD_MONEY && bad_guys[i].mode != HELD)
             {
-              badguy_collision(&bad_guys[i], &tux, CO_PLAYER);
+              bad_guys[i].collision(&tux, CO_PLAYER);
             }
           else
             {
index 6df7eb7..ecfa31e 100644 (file)
@@ -51,7 +51,6 @@ static texture_type img_cloud[2][4];
 static SDL_Event event;
 static SDLKey key;
 static char level_subset[100];
-static char str[60];
 static float fps_fps;
 static int st_gl_mode;
 static unsigned int last_update_time;
@@ -70,8 +69,8 @@ void drawresultscreen(void);
 
 void levelintro(void)
 {
+  char str[60];
   /* Level Intro: */
-
   clearscreen(0, 0, 0);
 
   sprintf(str, "LEVEL %d", level);
@@ -450,7 +449,7 @@ int game_action(void)
 
   for (i = 0; i < bad_guys.size(); i++)
     {
-      badguy_action(&bad_guys[i]);
+      bad_guys[i].action();
     }
 
   /* Handle all possible collisions. */
@@ -511,7 +510,7 @@ void game_draw(void)
 
   for (i = 0; i < bad_guys.size(); ++i)
     {
-      badguy_draw(&bad_guys[i]);
+      bad_guys[i].draw();
     }
 
   /* (Tux): */
@@ -1585,7 +1584,7 @@ void trybumpbadguy(float x, float y)
 /* (Status): */
 void drawstatus(void)
 {
-  int i;
+  char str[60];
 
   sprintf(str, "%d", score);
   text_draw(&white_text, "SCORE", 0, 0, 1);
@@ -1622,7 +1621,7 @@ void drawstatus(void)
       text_draw(&gold_text, str, screen->h + 60, 40, 1);
     }
 
-  for(i=0; i < tux.lives; ++i)
+  for(int i=0; i < tux.lives; ++i)
     {
       texture_draw(&tux_life,565+(18*i),20);
     }
index d8c2085..db25e4c 100644 (file)
@@ -216,7 +216,7 @@ void level_default(st_level* plevel)
 
 /* Load data for this level: */
 /* Returns -1, if the loading of the level failed. */
-int level_load(st_level* plevel,const  char *subset, int level)
+int level_load(st_level* plevel, const  char *subset, int level)
 {
   char filename[1024];
 
index d69edd3..562401a 100644 (file)
@@ -1332,7 +1332,7 @@ void le_change(float x, float y, unsigned char c)
           /* if there is a bad guy over there, remove it */
           for(i = 0; i < bad_guys.size(); ++i)
               if(xx == bad_guys[i].base.x/32 && yy == bad_guys[i].base.y/32)
-                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(&bad_guys[i]));
+                  bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(&bad_guys[i]));
 
           if(c == '0')  /* if it's a bad guy */
             add_bad_guy(xx*32, yy*32, BAD_BSOD);
@@ -1373,7 +1373,7 @@ void le_change(float x, float y, unsigned char c)
           for(i = 0; i < bad_guys.size(); ++i)
               if(bad_guys[i].base.x/32 >= x1 && bad_guys[i].base.x/32 <= x2
                   && bad_guys[i].base.y/32 >= y1 && bad_guys[i].base.y/32 <= y2)
-                  bad_guys.erase(static_cast<std::vector<bad_guy_type>::iterator>(&bad_guys[i]));
+                  bad_guys.erase(static_cast<std::vector<BadGuy>::iterator>(&bad_guys[i]));
 
           for(xx = x1; xx <= x2; xx++)
             for(yy = y1; yy <= y2; yy++)
index 7fdbd2e..6e33c74 100644 (file)
@@ -803,12 +803,12 @@ void player_draw(player_type* pplayer)
 
 void player_collision(player_type* pplayer, void* p_c_object, int c_object)
 {
-  bad_guy_type* pbad_c = NULL;
+  BadGuy* pbad_c = NULL;
 
   switch (c_object)
     {
     case CO_BADGUY:
-      pbad_c = (bad_guy_type*) p_c_object;
+      pbad_c = (BadGuy*) p_c_object;
       /* Hurt the player if he just touched it: */
 
       if (!pbad_c->dying && !pplayer->dying &&
index dcdc038..f85d603 100644 (file)
@@ -29,7 +29,7 @@ int frame;
 std::vector<bouncy_distro_type> bouncy_distros;
 std::vector<broken_brick_type> broken_bricks;
 std::vector<bouncy_brick_type> bouncy_bricks;
-std::vector<bad_guy_type> bad_guys;
+std::vector<BadGuy> bad_guys;
 std::vector<floating_score_type> floating_scores;
 std::vector<upgrade_type> upgrades;
 std::vector<bullet_type> bullets;
@@ -133,8 +133,8 @@ void add_bouncy_brick(float x, float y)
 
 void add_bad_guy(float x, float y, BadGuyKind kind)
 {
-  bad_guy_type new_bad_guy;
-  badguy_init(&new_bad_guy,x,y,kind);
+  BadGuy new_bad_guy;
+  new_bad_guy.init(x,y,kind);
   bad_guys.push_back(new_bad_guy);
 }
 
index e12d48d..dc3e1fa 100644 (file)
@@ -39,7 +39,7 @@ extern int frame;
 extern std::vector<bouncy_distro_type> bouncy_distros;
 extern std::vector<broken_brick_type> broken_bricks;
 extern std::vector<bouncy_brick_type> bouncy_bricks;
-extern std::vector<bad_guy_type> bad_guys;
+extern std::vector<BadGuy> bad_guys;
 extern std::vector<floating_score_type> floating_scores;
 extern std::vector<upgrade_type> upgrades;
 extern std::vector<bullet_type> bullets;
index 1b420ad..f2e9253 100644 (file)
@@ -73,13 +73,12 @@ void texture_load_part_gl(texture_type* ptexture, const std::string& file, int x
 /* Quick utility function for texture creation */
 static int power_of_two(int input)
 {
-       int value = 1;
-        int a;
+  int value = 1;
 
-       while ( value < input ) {
-               value <<= 1;
-       }
-       return value;
+  while ( value < input ) {
+    value <<= 1;
+  }
+  return value;
 }
 
 void texture_create_gl(SDL_Surface * surf, GLuint * tex)
index d56af64..e18a450 100644 (file)
@@ -34,11 +34,11 @@ TileManager* TileManager::instance_  = 0;
 
 TileManager::TileManager()
 {
-  std::string filename = datadir +  "images/worldmap/antarctica.scm";
-  lisp_object_t* root_obj = lisp_read_from_file(filename);
+  std::string stwt_filename = datadir +  "images/worldmap/antarctica.scm";
+  lisp_object_t* root_obj = lisp_read_from_file(stwt_filename);
  
   if (!root_obj)
-    st_abort("Couldn't load file", filename);
+    st_abort("Couldn't load file", stwt_filename);
 
   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap-tiles") == 0)
     {