huge CVS merge, see ChangeLog for details.
[supertux.git] / src / special.c
index 4963287..181c044 100644 (file)
@@ -4,7 +4,7 @@
 // Description:
 //
 //
-// Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
+// Author: Tobias Glaesser <tobi.web@gmx.de> & Bill Kendrick, (C) 2004
 //
 // Copyright: See COPYING file that comes with this distribution
 //
 #include "globals.h"
 #include "player.h"
 
+texture_type img_bullet;
+texture_type img_golden_herring;
+bitmask* bm_bullet;
+
 void create_special_bitmasks()
 {
   bm_bullet = bitmask_create_SDL(img_bullet.sdl_surface);
 }
 
-void bullet_init(bullet_type* pbullet)
+void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir)
 {
-  pbullet->it.alive = &pbullet->alive;
-  pbullet->it.x = &pbullet->x;
-  pbullet->it.y = &pbullet->y;
-  pbullet->it.width = &pbullet->width;
-  pbullet->it.height = &pbullet->height;
-  pbullet->it.updated = &pbullet->updated;
-
-  pbullet->width = 4;
-  pbullet->height = 4;
-  pbullet->updated = SDL_GetTicks();
-  pbullet->alive = NO;
+  pbullet->base.width = 4;
+  pbullet->base.height = 4;
+  pbullet->base.alive = YES;
+
+  if (dir == RIGHT)
+    {
+      pbullet->base.x = x + 32;
+      pbullet->base.xm = BULLET_XM + xm;
+    }
+  else
+    {
+      pbullet->base.x = x;
+      pbullet->base.xm = -BULLET_XM + xm;
+    }
+
+  pbullet->base.y = y;
+  pbullet->base.ym = BULLET_STARTING_YM;
 }
 
 void bullet_action(bullet_type* pbullet)
 {
-
-  double frame_ratio = get_frame_ratio(&pbullet->it);
-
-  if (pbullet->alive)
+  if (pbullet->base.alive)
     {
-      pbullet->x = pbullet->x + pbullet->xm * frame_ratio;
-      pbullet->y = pbullet->y + pbullet->ym * frame_ratio;
+      pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
+      pbullet->base.y = pbullet->base.y + pbullet->base.ym * frame_ratio;
 
-      if (issolid(pbullet->x, pbullet->y))
+      if (issolid(pbullet->base.x, pbullet->base.y))
         {
-          if (issolid(pbullet->x, pbullet->y - pbullet->ym))
-            pbullet->alive = NO;
+          if (issolid(pbullet->base.x, pbullet->base.y - pbullet->base.ym))
+            pbullet->base.alive = NO;
           else
             {
-              if (pbullet->ym >= 0)
+              if (pbullet->base.ym >= 0)
                 {
-                  pbullet->y = (int)(pbullet->y / 32) * 32 - 8;
+                  pbullet->base.y = (int)(pbullet->base.y / 32) * 32 - 8;
                 }
-              pbullet->ym = -pbullet->ym;
+              pbullet->base.ym = -pbullet->base.ym;
             }
         }
 
-      pbullet->ym = pbullet->ym + GRAVITY;
+      pbullet->base.ym = pbullet->base.ym + GRAVITY;
 
-      if (pbullet->x < scroll_x ||
-          pbullet->x > scroll_x + screen->w)
+      if (pbullet->base.x < scroll_x ||
+          pbullet->base.x > scroll_x + screen->w)
         {
-          pbullet->alive = NO;
+          pbullet->base.alive = NO;
         }
     }
 
@@ -77,11 +84,11 @@ void bullet_action(bullet_type* pbullet)
 
 void bullet_draw(bullet_type* pbullet)
 {
-  if (pbullet->alive  &&
-      pbullet->x >= scroll_x - pbullet->width &&
-      pbullet->x <= scroll_x + screen->w)
+  if (pbullet->base.alive  &&
+      pbullet->base.x >= scroll_x - pbullet->base.width &&
+      pbullet->base.x <= scroll_x + screen->w)
     {
-      texture_draw(&img_bullet, pbullet->x - scroll_x, pbullet->y,
+      texture_draw(&img_bullet, pbullet->base.x - scroll_x, pbullet->base.y,
                    NO_UPDATE);
     }
 }
@@ -90,36 +97,35 @@ void bullet_collision(bullet_type* pbullet, int c_object)
 {
 
   if(c_object == CO_BADGUY)
-    pbullet->alive = NO;
+    pbullet->base.alive = NO;
 
 }
 
-void upgrade_init(upgrade_type *pupgrade)
+void upgrade_init(upgrade_type *pupgrade, float x, float y, int kind)
 {
-  pupgrade->it.alive = &pupgrade->alive;
-  pupgrade->it.x = &pupgrade->x;
-  pupgrade->it.y = &pupgrade->y;
-  pupgrade->it.width = &pupgrade->width;
-  pupgrade->it.height = &pupgrade->height;
-  pupgrade->it.updated = &pupgrade->updated;
-
-  pupgrade->width = 32;
-  pupgrade->height = 0;
-  pupgrade->updated = SDL_GetTicks();
-  pupgrade->alive = NO;
+  pupgrade->base.width = 32;
+  pupgrade->base.height = 0;
+  pupgrade->base.alive = YES;
+  pupgrade->kind = kind;
+  pupgrade->base.x = x;
+  pupgrade->base.y = y;
+  pupgrade->base.xm = 2;
+  pupgrade->base.ym = -2;
+  pupgrade->base.height = 0;
 }
 
 void upgrade_action(upgrade_type *pupgrade)
 {
-  double frame_ratio = get_frame_ratio(&pupgrade->it);
 
-  if (pupgrade->alive)
+  if (pupgrade->base.alive)
     {
-      if (pupgrade->height < 32)
+      if (pupgrade->base.height < 32)
         {
           /* Rise up! */
 
-          pupgrade->height++;
+          pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
+         if(pupgrade->base.height > 32)
+         pupgrade->base.height = 32;
         }
       else
         {
@@ -128,88 +134,90 @@ void upgrade_action(upgrade_type *pupgrade)
           if (pupgrade->kind == UPGRADE_MINTS ||
               pupgrade->kind == UPGRADE_HERRING)
             {
-              pupgrade->x = pupgrade->x + pupgrade->xm * frame_ratio;
-              pupgrade->y = pupgrade->y + pupgrade->ym * frame_ratio;
+              pupgrade->base.x = pupgrade->base.x + pupgrade->base.xm * frame_ratio;
+              pupgrade->base.y = pupgrade->base.y + pupgrade->base.ym * frame_ratio;
 
-              if (issolid(pupgrade->x, pupgrade->y + 31) ||
-                  issolid(pupgrade->x + 31, pupgrade->y + 31))
+              if (issolid(pupgrade->base.x, pupgrade->base.y + 31.) ||
+                  issolid(pupgrade->base.x + 31., pupgrade->base.y + 31.))
                 {
-                  if (pupgrade->ym > 0)
+                  if (pupgrade->base.ym > 0)
                     {
                       if (pupgrade->kind == UPGRADE_MINTS)
                         {
-                          pupgrade->ym = 0;
+                          pupgrade->base.ym = 0;
                         }
                       else if (pupgrade->kind == UPGRADE_HERRING)
                         {
-                          pupgrade->ym = -24;
+                          pupgrade->base.ym = -8;
                         }
 
-                      pupgrade->y = (int)(pupgrade->y / 32) * 32;
+                      pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
                     }
                 }
               else
-                pupgrade->ym = pupgrade->ym + GRAVITY;
+                pupgrade->base.ym = pupgrade->base.ym + GRAVITY;
 
-              if (issolid(pupgrade->x, pupgrade->y))
-                {
-                  pupgrade->xm = -pupgrade->xm;
-                }
+                 if (issolid(pupgrade->base.x - 1, (int) pupgrade->base.y))
+                    {
+                     if(pupgrade->base.xm < 0)
+                      pupgrade->base.xm = -pupgrade->base.xm;
+                    }
+                   else if (issolid(pupgrade->base.x + pupgrade->base.width-1, (int) pupgrade->base.y))
+                   {
+                     if(pupgrade->base.xm > 0)
+                      pupgrade->base.xm = -pupgrade->base.xm;
+                   }
             }
 
 
           /* Off the screen?  Kill it! */
 
-          if (pupgrade->x < scroll_x)
-            pupgrade->alive = NO;
-        
-       }
+          if (pupgrade->base.x < scroll_x - pupgrade->base.width)
+            pupgrade->base.alive = NO;
+
+        }
     }
 }
 
 void upgrade_draw(upgrade_type* pupgrade)
 {
-  if (pupgrade->alive)
+SDL_Rect dest;
+  if (pupgrade->base.alive)
     {
-      if (pupgrade->height < 32)
+      if (pupgrade->base.height < 32)
         {
           /* Rising up... */
 
-          dest.x = pupgrade->x - scroll_x;
-          dest.y = pupgrade->y + 32 - pupgrade->height;
+          dest.x = (int)(pupgrade->base.x - scroll_x);
+          dest.y = (int)(pupgrade->base.y + 32 - pupgrade->base.height);
           dest.w = 32;
-          dest.h = pupgrade->height;
-
-          src.x = 0;
-          src.y = 0;
-          src.w = 32;
-          src.h = pupgrade->height;
+          dest.h = (int)pupgrade->base.height;
 
           if (pupgrade->kind == UPGRADE_MINTS)
-            SDL_BlitSurface(img_mints.sdl_surface, &src, screen, &dest);
+           texture_draw_part(&img_mints,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
           else if (pupgrade->kind == UPGRADE_COFFEE)
-            SDL_BlitSurface(img_coffee.sdl_surface, &src, screen, &dest);
+           texture_draw_part(&img_coffee,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
           else if (pupgrade->kind == UPGRADE_HERRING)
-            SDL_BlitSurface(img_golden_herring.sdl_surface, &src, screen, &dest);
+           texture_draw_part(&img_golden_herring,0,0,dest.x,dest.y,dest.w,dest.h,NO_UPDATE);
         }
       else
         {
           if (pupgrade->kind == UPGRADE_MINTS)
             {
               texture_draw(&img_mints,
-                           pupgrade->x - scroll_x, pupgrade->y,
+                           pupgrade->base.x - scroll_x, pupgrade->base.y,
                            NO_UPDATE);
             }
           else if (pupgrade->kind == UPGRADE_COFFEE)
             {
               texture_draw(&img_coffee,
-                           pupgrade->x - scroll_x, pupgrade->y,
+                           pupgrade->base.x - scroll_x, pupgrade->base.y,
                            NO_UPDATE);
             }
           else if (pupgrade->kind == UPGRADE_HERRING)
             {
               texture_draw(&img_golden_herring,
-                           pupgrade->x - scroll_x, pupgrade->y,
+                           pupgrade->base.x - scroll_x, pupgrade->base.y,
                            NO_UPDATE);
             }
         }
@@ -218,7 +226,7 @@ void upgrade_draw(upgrade_type* pupgrade)
 
 void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
 {
-player_type* pplayer = NULL;
+  player_type* pplayer = NULL;
 
   switch (c_object)
     {
@@ -226,9 +234,9 @@ player_type* pplayer = NULL;
       /* Remove the upgrade: */
 
       /* p_c_object is CO_PLAYER, so assign it to pplayer */
-      pplayer = p_c_object;
-      
-      pupgrade->alive = NO;
+      pplayer = (player_type*) p_c_object;
+
+      pupgrade->base.alive = NO;
 
       /* Affect the player: */
 
@@ -236,19 +244,20 @@ player_type* pplayer = NULL;
         {
           play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
           pplayer->size = BIG;
-          super_bkgd_time = 8;
+         pplayer->base.height = 64;
+          timer_start(&super_bkgd_timer, 350);
         }
       else if (pupgrade->kind == UPGRADE_COFFEE)
         {
           play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER);
           pplayer->got_coffee = YES;
-          super_bkgd_time = 4;
+          timer_start(&super_bkgd_timer, 250);
         }
       else if (pupgrade->kind == UPGRADE_HERRING)
         {
           play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
-          timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
-          super_bkgd_time = 4;
+          timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
+          timer_start(&super_bkgd_timer, 250);
           /* play the herring song ^^ */
           if (current_music != HURRYUP_MUSIC)
             {