Corrected collition with bag of money
[supertux.git] / src / scene.c
index bcbfb01..92c8c2d 100644 (file)
 #include <stdlib.h>
 #include "scene.h"
 
+int score, distros, level, next_level, game_pause, quit, score_multiplier, endpos, counting_distros, distro_counter;
+timer_type  super_bkgd_timer;
+float scroll_x;
+int frame;
+bouncy_distro_type *bouncy_distros;
+broken_brick_type *broken_bricks;
+bouncy_brick_type *bouncy_bricks;
+bad_guy_type *bad_guys;
+floating_score_type *floating_scores;
+upgrade_type *upgrades;
+bullet_type *bullets;
+int num_bad_guys;
+int num_bouncy_distros;
+int num_broken_bricks;
+int num_bouncy_bricks;
+int num_floating_scores;
+int num_upgrades;
+int num_bullets;
+player_type tux;
+texture_type img_box_full, img_box_empty, img_mints, img_coffee, img_super_bkgd, img_red_glow;
+timer_type time_left;
+double frame_ratio;
+
 /* Initialize all 'dynamic' arrays */
 void arrays_init(void)
 {
@@ -46,47 +69,12 @@ free(bullets);
 
 void set_defaults(void)
 {
-  int i;
-
-  /* Reset arrays: */
-
-  for (i = 0; i < num_bouncy_distros; i++)
-    bouncy_distros[i].base.alive = NO;
-
-  for (i = 0; i < num_broken_bricks; i++)
-    broken_bricks[i].base.alive = NO;
-
-  for (i = 0; i < num_bouncy_bricks; i++)
-    bouncy_bricks[i].base.alive = NO;
-       
-  for (i = 0; i < num_bad_guys; i++)
-  {
-    /*bad_guys[i].alive = NO;*/
-    badguy_init(&bad_guys[i]);
-    }
-  for (i = 0; i < num_floating_scores; i++)
-    floating_scores[i].base.alive = NO;
-
-  for (i = 0; i < num_upgrades; i++)
-  {
-    /*upgrades[i].alive = NO;*/
-    upgrade_init(&upgrades[i]);
-    }
-
-  for (i = 0; i < num_bullets; i++)
-  {
-    /*bullets[i].alive = NO;*/
-    bullet_init(&bullets[i]);
-    }
-
-
   /* Set defaults: */
   
   scroll_x = 0;
 
   score_multiplier = 1;
-  super_bkgd_time = 0;
+  timer_init(&super_bkgd_timer);
 
   counting_distros = NO;
   distro_counter = 0;
@@ -99,14 +87,14 @@ void set_defaults(void)
 
 /* Add score: */
 
-void add_score(int x, int y, int s)
+void add_score(float x, float y, int s)
 {
   int i, found;
 
 
   /* Add the score: */
 
-  score = score + s;
+  score += s;
 
 
   /* Add a floating score thing to the game: */
@@ -122,7 +110,7 @@ void add_score(int x, int y, int s)
   if (found == -1)
   {
   ++num_floating_scores;
-  floating_scores = realloc(floating_scores,num_floating_scores*sizeof(floating_score_type));
+  floating_scores = (floating_score_type*) realloc(floating_scores,num_floating_scores*sizeof(floating_score_type));
   floating_score_init(&floating_scores[num_floating_scores-1],x,y,s);
   found = -1;
   }
@@ -150,16 +138,13 @@ void add_bouncy_distro(float x, float y)
   if (found == -1)
   {
   ++num_bouncy_distros;
-  bouncy_distros = realloc(bouncy_distros,num_bouncy_distros*sizeof(bouncy_distro_type));
+  bouncy_distros = (bouncy_distro_type*) realloc(bouncy_distros,num_bouncy_distros*sizeof(bouncy_distro_type));
   found = num_bouncy_distros - 1;
   }
     
   if (found != -1)
     {
-      bouncy_distros[found].base.alive = YES;
-      bouncy_distros[found].base.x = x;
-      bouncy_distros[found].base.y = y;
-      bouncy_distros[found].base.ym = -6;
+       bouncy_distro_init(&bouncy_distros[found],x,y);
     }
 }
 
@@ -168,11 +153,11 @@ void add_bouncy_distro(float x, float y)
 
 void add_broken_brick(float x, float y)
 {
-  add_broken_brick_piece(x, y, -4, -16);
-  add_broken_brick_piece(x, y + 16, -6, -12);
+  add_broken_brick_piece(x, y, -1, -4);
+  add_broken_brick_piece(x, y + 16, -1.5, -3);
 
-  add_broken_brick_piece(x + 16, y, 4, -16);
-  add_broken_brick_piece(x + 16, y + 16, 6, -12);
+  add_broken_brick_piece(x + 16, y, 1, -4);
+  add_broken_brick_piece(x + 16, y + 16, 1.5, -3);
 }
 
 
@@ -193,17 +178,13 @@ void add_broken_brick_piece(float x, float y, float xm, float ym)
   if (found == -1)
   {
   ++num_broken_bricks;
-  broken_bricks = realloc(broken_bricks,num_broken_bricks*sizeof(broken_brick_type));
+  broken_bricks = (broken_brick_type*) realloc(broken_bricks,num_broken_bricks*sizeof(broken_brick_type));
   found = num_broken_bricks - 1;
   }
 
   if (found != -1)
     {
-      broken_bricks[found].base.alive = YES;
-      broken_bricks[found].base.x = x;
-      broken_bricks[found].base.y = y;
-      broken_bricks[found].base.xm = xm;
-      broken_bricks[found].base.ym = ym;
+       broken_brick_init(&broken_bricks[found], x, y, xm, ym);
     }
 }
 
@@ -225,18 +206,13 @@ void add_bouncy_brick(float x, float y)
   if (found == -1)
   {
   ++num_bouncy_bricks;
-  bouncy_bricks = realloc(bouncy_bricks,num_bouncy_bricks*sizeof(bouncy_brick_type));
+  bouncy_bricks = (bouncy_brick_type*) realloc(bouncy_bricks,num_bouncy_bricks*sizeof(bouncy_brick_type));
   found = num_bouncy_bricks - 1;
   }
 
   if (found != -1)
     {
-      bouncy_bricks[found].base.alive = YES;
-      bouncy_bricks[found].base.x = x;
-      bouncy_bricks[found].base.y = y;
-      bouncy_bricks[found].offset = 0;
-      bouncy_bricks[found].offset_m = -BOUNCY_BRICK_SPEED;
-      bouncy_bricks[found].shape = shape(x, y);
+      bouncy_brick_init(&bouncy_bricks[found],x,y);
     }
 }
 
@@ -258,24 +234,13 @@ void add_bad_guy(float x, float y, int kind)
   if (found == -1)
   {
   ++num_bad_guys;
-  bad_guys = realloc(bad_guys,num_bad_guys*sizeof(bad_guy_type));
-  badguy_init(&bad_guys[num_bad_guys-1]);
+  bad_guys = (bad_guy_type*) realloc(bad_guys,num_bad_guys*sizeof(bad_guy_type));
   found = num_bad_guys - 1;
   }
 
   if (found != -1)
     {
-      bad_guys[found].base.alive = YES;
-      bad_guys[found].mode = NORMAL;
-      bad_guys[found].dying = NO;
-      bad_guys[found].kind = kind;
-      bad_guys[found].base.x = x;
-      bad_guys[found].base.y = y;
-      bad_guys[found].base.xm = 1.3;
-      bad_guys[found].base.ym = 1.5;
-      bad_guys[found].dir = LEFT;
-      bad_guys[found].seen = NO;
-      timer_init(&bad_guys[found].timer);
+       badguy_init(&bad_guys[found], x, y, kind);
     }
 }
 
@@ -283,12 +248,9 @@ void add_bad_guy(float x, float y, int kind)
 
 void add_upgrade(float x, float y, int kind)
 {
-  int i, r, found;
-  /* we use this pointer to check, if realloc() returned a new memory address */
-  upgrade_type * pointee = upgrades;
+  int i, found;
 
   found = -1;
-  r = 0;
 
   for (i = 0; i < num_upgrades && found == -1; i++)
     {
@@ -299,30 +261,13 @@ void add_upgrade(float x, float y, int kind)
   if (found == -1)
   {
   ++num_upgrades;
-  upgrades = realloc(upgrades,num_upgrades*sizeof(upgrade_type));
-  if(upgrades != pointee)
-  r = 1;
-  upgrade_init(&upgrades[num_upgrades-1]);
+  upgrades = (upgrade_type*) realloc(upgrades,num_upgrades*sizeof(upgrade_type));
   found = num_upgrades - 1;
   }
 
   if (found != -1)
     {
-      if(r == 1)
-      {
-        for (i = 0; i < num_upgrades && found == -1; i++)
-    {
-       upgrade_init(&upgrades[i]);
-    }
-      }
-      upgrade_init(&upgrades[found]);
-      upgrades[found].base.alive = YES;
-      upgrades[found].kind = kind;
-      upgrades[found].base.x = x;
-      upgrades[found].base.y = y;
-      upgrades[found].base.xm = 2;
-      upgrades[found].base.ym = -2;
-      upgrades[found].base.height = 0;
+      upgrade_init(&upgrades[found], x, y, kind);
     }
 }
 
@@ -343,29 +288,13 @@ void add_bullet(float x, float y, float xm, int dir)
   if (found == -1)
   {
   ++num_bullets;
-  bullets = realloc(bullets,num_bullets*sizeof(bullet_type));
-  bullet_init(&bullets[num_bullets-1]);
+  bullets = (bullet_type*) realloc(bullets,num_bullets*sizeof(bullet_type));
   found = num_bullets - 1;
   }
 
   if (found != -1)
     {
-      bullet_init(&bullets[found]);
-      bullets[found].base.alive = YES;
-
-      if (dir == RIGHT)
-        {
-          bullets[found].base.x = x + 32;
-          bullets[found].base.xm = BULLET_XM + xm;
-        }
-      else
-        {
-          bullets[found].base.x = x;
-          bullets[found].base.xm = -BULLET_XM + xm;
-        }
-
-      bullets[found].base.y = y;
-      bullets[found].base.ym = BULLET_STARTING_YM;
+      bullet_init(&bullets[found], x, y, xm, dir);
 
       play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
     }