[Tux4kids-commits] r1421 - in branches/commonification/tuxtype/trunk: data/images/tux src

Bolesław Kulbabiński bolekk-guest at alioth.debian.org
Wed Aug 12 20:32:43 UTC 2009


Author: bolekk-guest
Date: 2009-08-12 20:32:43 +0000 (Wed, 12 Aug 2009)
New Revision: 1421

Modified:
   branches/commonification/tuxtype/trunk/data/images/tux/walk0.png
   branches/commonification/tuxtype/trunk/src/playgame.c
Log:
playgame.c images can be loaded in appropriate sizes

Modified: branches/commonification/tuxtype/trunk/data/images/tux/walk0.png
===================================================================
(Binary files differ)

Modified: branches/commonification/tuxtype/trunk/src/playgame.c
===================================================================
--- branches/commonification/tuxtype/trunk/src/playgame.c	2009-08-12 20:03:19 UTC (rev 1420)
+++ branches/commonification/tuxtype/trunk/src/playgame.c	2009-08-12 20:32:43 UTC (rev 1421)
@@ -42,10 +42,32 @@
 static sprite* fish_sprite = NULL;
 static sprite* splat_sprite = NULL;
 
+/* positioning constants */
+#define POSITIONED_SPRITES 9
+const int sprite_ids[POSITIONED_SPRITES] = {
+  ANIM_NUMS,
+  ANIM_SPLAT,
+  ANIM_TUX_WALKING,
+  ANIM_TUX_STANDING,
+  ANIM_TUX_RUNNING,
+  ANIM_TUX_GULPING,
+  ANIM_TUX_WINNING,
+  ANIM_TUX_YIPING
+};
 
+/* x y w h */
+const float sprite_pos[POSITIONED_SPRITES][4] = {
+  {0.0, 0.0, 0.05, 0.05},
+  {0.0, 0.0, 0.1, 0.1},
+  {0.0, 0.0, 0.2, 0.2},
+  {0.0, 0.0, 0.2, 0.2},
+  {0.0, 0.0, 0.2, 0.2},
+  {0.0, 0.0, 0.2, 0.2},
+  {0.0, 0.0, 0.2, 0.2},
+  {0.0, 0.0, 0.2, 0.2}
+};
 
 
-
 /* Local function prototypes: */
 static void AddSplat(int* splats, struct fishypoo* f, int* curlives, int* frame);
 static void CheckCollision(int fishies, int* fish_left, int frame );
@@ -81,17 +103,23 @@
 /*                                                                      */
 /************************************************************************/
 
-void LoadCascadeMedia()
+int LoadCascadeMedia()
 {
-  SetSprite(ANIM_NUMS, NULL);
+  SDL_Rect rt;
+  int i;
+
+  for(i = 0; i < POSITIONED_SPRITES; i++)
+  {
+    SetRect(&rt, sprite_pos[i]);
+    if(!SetSprite(sprite_ids[i], &rt))
+      return 0;
+  }
+
+  /* NOTE: fishes' sizes should match letter size but we don't want the
+     letters to be too small. */
   SetSprite(ANIM_FISHY, NULL);
-  SetSprite(ANIM_SPLAT, NULL);
-  SetSprite(ANIM_TUX_WALKING, NULL);
-  SetSprite(ANIM_TUX_STANDING, NULL);
-  SetSprite(ANIM_TUX_RUNNING, NULL);
-  SetSprite(ANIM_TUX_GULPING, NULL);
-  SetSprite(ANIM_TUX_WINNING, NULL);
-  SetSprite(ANIM_TUX_YIPING, NULL);
+
+  return 1;
 }
 
 
@@ -107,7 +135,7 @@
   int quitting = 0;
   int curlevel = 0;
   int i;
-  int curlives;
+  int curlives = 0;
   int oldlives = 0;
   int oldfish_left = 0;
   int fish_left = 0;
@@ -138,7 +166,11 @@
 
 //	SNOW_init();
 
-  LoadCascadeMedia();
+  if(!LoadCascadeMedia())
+  {
+    /* NOTE: probably the game should not be run if this happens ... */
+    fprintf(stderr, "PlayCascade(): WARNING, media not loaded properly!\n");
+  }
   LoadTuxAnims();
   LoadFishies();
   LoadOthers();
@@ -274,8 +306,21 @@
               SwitchScreenMode();
 
               DrawBackground();
+
+              /* free flipped sprites */
+              for (i = 0; i < TUX_NUM_STATES; i++ )
+              {
+                if (tux_object.spr[i][LEFT])
+                  FreeSprite(tux_object.spr[i][LEFT]);
+                tux_object.spr[i][LEFT] = NULL;
+              }
+
+              LoadCascadeMedia();
+              LoadTuxAnims();
+              LoadFishies();
+              LoadOthers();
+
               ResetObjects();
-
             }
 
             if (event.key.keysym.sym == SDLK_F12)




More information about the Tux4kids-commits mailing list