huge CVS merge, see ChangeLog for details.
[supertux.git] / src / special.c
index 1242841..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);
@@ -29,7 +33,6 @@ void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir)
 {
   pbullet->base.width = 4;
   pbullet->base.height = 4;
-  pbullet->base.updated = SDL_GetTicks();
   pbullet->base.alive = YES;
 
   if (dir == RIGHT)
@@ -49,9 +52,6 @@ void bullet_init(bullet_type* pbullet, float x, float y, float xm, int dir)
 
 void bullet_action(bullet_type* pbullet)
 {
-
-  double frame_ratio = get_frame_ratio(&pbullet->base);
-
   if (pbullet->base.alive)
     {
       pbullet->base.x = pbullet->base.x + pbullet->base.xm * frame_ratio;
@@ -112,12 +112,10 @@ void upgrade_init(upgrade_type *pupgrade, float x, float y, int kind)
   pupgrade->base.xm = 2;
   pupgrade->base.ym = -2;
   pupgrade->base.height = 0;
-  pupgrade->base.updated = SDL_GetTicks();
 }
 
 void upgrade_action(upgrade_type *pupgrade)
 {
-  double frame_ratio = get_frame_ratio(&pupgrade->base);
 
   if (pupgrade->base.alive)
     {
@@ -125,7 +123,9 @@ void upgrade_action(upgrade_type *pupgrade)
         {
           /* Rise up! */
 
-          pupgrade->base.height++;
+          pupgrade->base.height = pupgrade->base.height + 0.7 * frame_ratio;
+         if(pupgrade->base.height > 32)
+         pupgrade->base.height = 32;
         }
       else
         {
@@ -137,8 +137,8 @@ void upgrade_action(upgrade_type *pupgrade)
               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->base.x, pupgrade->base.y + 31) ||
-                  issolid(pupgrade->base.x + 31, pupgrade->base.y + 31))
+              if (issolid(pupgrade->base.x, pupgrade->base.y + 31.) ||
+                  issolid(pupgrade->base.x + 31., pupgrade->base.y + 31.))
                 {
                   if (pupgrade->base.ym > 0)
                     {
@@ -148,7 +148,7 @@ void upgrade_action(upgrade_type *pupgrade)
                         }
                       else if (pupgrade->kind == UPGRADE_HERRING)
                         {
-                          pupgrade->base.ym = -24;
+                          pupgrade->base.ym = -8;
                         }
 
                       pupgrade->base.y = (int)(pupgrade->base.y / 32) * 32;
@@ -157,10 +157,16 @@ void upgrade_action(upgrade_type *pupgrade)
               else
                 pupgrade->base.ym = pupgrade->base.ym + GRAVITY;
 
-              if (issolid(pupgrade->base.x, pupgrade->base.y))
-                {
-                  pupgrade->base.xm = -pupgrade->base.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;
+                   }
             }
 
 
@@ -175,28 +181,24 @@ void upgrade_action(upgrade_type *pupgrade)
 
 void upgrade_draw(upgrade_type* pupgrade)
 {
+SDL_Rect dest;
   if (pupgrade->base.alive)
     {
       if (pupgrade->base.height < 32)
         {
           /* Rising up... */
 
-          dest.x = pupgrade->base.x - scroll_x;
-          dest.y = pupgrade->base.y + 32 - pupgrade->base.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->base.height;
-
-          src.x = 0;
-          src.y = 0;
-          src.w = 32;
-          src.h = pupgrade->base.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
         {
@@ -232,7 +234,7 @@ void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
       /* Remove the upgrade: */
 
       /* p_c_object is CO_PLAYER, so assign it to pplayer */
-      pplayer = p_c_object;
+      pplayer = (player_type*) p_c_object;
 
       pupgrade->base.alive = NO;
 
@@ -242,6 +244,7 @@ void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
         {
           play_sound(sounds[SND_EXCELLENT], SOUND_CENTER_SPEAKER);
           pplayer->size = BIG;
+         pplayer->base.height = 64;
           timer_start(&super_bkgd_timer, 350);
         }
       else if (pupgrade->kind == UPGRADE_COFFEE)
@@ -253,7 +256,7 @@ void upgrade_collision(upgrade_type* pupgrade, void* p_c_object, int c_object)
       else if (pupgrade->kind == UPGRADE_HERRING)
         {
           play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
-          timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
+          timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME);
           timer_start(&super_bkgd_timer, 250);
           /* play the herring song ^^ */
           if (current_music != HURRYUP_MUSIC)