[Tux4kids-commits] r1386 - in branches/commonification/tuxmath/trunk: data/images/tux src

Bolesław Kulbabiński bolekk-guest at alioth.debian.org
Thu Aug 6 20:19:03 UTC 2009


Author: bolekk-guest
Date: 2009-08-06 20:19:02 +0000 (Thu, 06 Aug 2009)
New Revision: 1386

Added:
   branches/commonification/tuxmath/trunk/data/images/tux/tux-alarm.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-console0.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-left0.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-left1.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-right0.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-right1.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-fist0.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-relax.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-yay0.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-yes0.png
Removed:
   branches/commonification/tuxmath/trunk/data/images/tux/tux-console4.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt1.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt2.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt3.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt4.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-fist2.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-relax1.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-relax2.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-yay2.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-yes2.png
Modified:
   branches/commonification/tuxmath/trunk/data/images/tux/Makefile.am
   branches/commonification/tuxmath/trunk/data/images/tux/tux-console1.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-console2.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-console3.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-fist1.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-yay1.png
   branches/commonification/tuxmath/trunk/data/images/tux/tux-yes1.png
   branches/commonification/tuxmath/trunk/src/factoroids.c
   branches/commonification/tuxmath/trunk/src/fileops.h
   branches/commonification/tuxmath/trunk/src/fileops_media.c
   branches/commonification/tuxmath/trunk/src/game.c
Log:
changes in handling tux animations in TuxMath games

Modified: branches/commonification/tuxmath/trunk/data/images/tux/Makefile.am
===================================================================
--- branches/commonification/tuxmath/trunk/data/images/tux/Makefile.am	2009-08-06 17:39:45 UTC (rev 1385)
+++ branches/commonification/tuxmath/trunk/data/images/tux/Makefile.am	2009-08-06 20:19:02 UTC (rev 1386)
@@ -3,34 +3,39 @@
 
 tuxdir = $(pkgdatadir)/images/tux
 
-dist_tux_DATA = bigtux0.png \
-  bigtux1.png \
-  bigtux2.png \
-  bigtux3.png \
-  bigtux4.png \
-  bigtux5.png \
-  bigtux6.png \
-  bigtux.svg \
-  console_led.png \
-  console_bash.png \
-  tux-console1.png \
-  tux-console2.png \
-  tux-console3.png \
-  tux-console4.png \
-  tux-drat.png \
-  tux-egypt1.png \
-  tux-egypt2.png \
-  tux-egypt3.png \
-  tux-egypt4.png \
-  tux-fist1.png \
-  tux-fist2.png \
-  tux-kiss1.png \
-  tux-kiss2.png \
-  tux-relax1.png \
-  tux-relax2.png \
-  tux-sit.png \
-  tux-yay1.png \
-  tux-yay2.png \
-  tux-yes1.png \
-  tux-yes2.png \
-  tux-yipe.png
+dist_tux_DATA = bigtux0.png\
+bigtux1.png\
+bigtux2.png\
+bigtux3.png\
+bigtux4.png\
+bigtux5.png\
+bigtux6.png\
+bigtux.svg\
+console_bash.png\
+console_led.png\
+console.png\
+Roos_bigtux0.png\
+Roos_bigtux1.png\
+Roos_bigtux2.png\
+Roos_bigtux3.png\
+tux-alarm.png\
+tux-console0.png\
+tux-console1.png\
+tux-console2.png\
+tux-console3.png\
+tux-drat.png\
+tux-egypt-left0.png\
+tux-egypt-left1.png\
+tux-egypt-right0.png\
+tux-egypt-right1.png\
+tux-fist0.png\
+tux-fist1.png\
+tux-kiss1.png\
+tux-kiss2.png\
+tux-relax.png\
+tux-sit.png\
+tux-yay0.png\
+tux-yay1.png\
+tux-yes0.png\
+tux-yes1.png\
+tux-yipe.png

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-alarm.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-alarm.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-console0.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-console0.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: branches/commonification/tuxmath/trunk/data/images/tux/tux-console1.png
===================================================================
(Binary files differ)

Modified: branches/commonification/tuxmath/trunk/data/images/tux/tux-console2.png
===================================================================
(Binary files differ)

Modified: branches/commonification/tuxmath/trunk/data/images/tux/tux-console3.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-console4.png
===================================================================
(Binary files differ)

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-left0.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-left0.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-left1.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-left1.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-right0.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-right0.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-right1.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt-right1.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt1.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt2.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt3.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-egypt4.png
===================================================================
(Binary files differ)

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-fist0.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-fist0.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: branches/commonification/tuxmath/trunk/data/images/tux/tux-fist1.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-fist2.png
===================================================================
(Binary files differ)

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-relax.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-relax.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-relax1.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-relax2.png
===================================================================
(Binary files differ)

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-yay0.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-yay0.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: branches/commonification/tuxmath/trunk/data/images/tux/tux-yay1.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-yay2.png
===================================================================
(Binary files differ)

Added: branches/commonification/tuxmath/trunk/data/images/tux/tux-yes0.png
===================================================================
(Binary files differ)


Property changes on: branches/commonification/tuxmath/trunk/data/images/tux/tux-yes0.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: branches/commonification/tuxmath/trunk/data/images/tux/tux-yes1.png
===================================================================
(Binary files differ)

Deleted: branches/commonification/tuxmath/trunk/data/images/tux/tux-yes2.png
===================================================================
(Binary files differ)

Modified: branches/commonification/tuxmath/trunk/src/factoroids.c
===================================================================
--- branches/commonification/tuxmath/trunk/src/factoroids.c	2009-08-06 17:39:45 UTC (rev 1385)
+++ branches/commonification/tuxmath/trunk/src/factoroids.c	2009-08-06 20:19:02 UTC (rev 1386)
@@ -175,7 +175,7 @@
 static int tux_pressing;
 static int doing_answer;
 static int level_start_wait;
-static int tux_img;
+static SDL_Surface* tux_img;
 //static int FF_level;
 
 static asteroid_type* asteroid = NULL;
@@ -201,7 +201,7 @@
 static void FF_draw(void);
 static void FF_draw_bkgr(void);
 static void FF_draw_led_console(void);
-static void draw_console_image(int i);
+static void draw_console_image(SDL_Surface* img);
 
 static SDL_Surface* current_bkgd()
   { return screen->flags & SDL_FULLSCREEN ? scaled_bkgd : bkgd; }
@@ -232,7 +232,8 @@
   
   quit = 0;
   counter = 0;
-  tux_img = IMG_TUX_CONSOLE1;
+  sprites[ANIM_TUX_CONSOLE]->cur = 0;
+  tux_img = sprites[ANIM_TUX_CONSOLE]->frame[0];
 
   DEBUGMSG(debug_factoroids, "Entering factors():\n");
 
@@ -252,10 +253,8 @@
     
     if(counter%15 == 0)
     {
-      if(tux_img<IMG_TUX_CONSOLE4)
-        tux_img++;
-      else 
-        tux_img=IMG_TUX_CONSOLE1;
+      NextFrame(sprites[ANIM_TUX_CONSOLE]);
+      tux_img = sprites[ANIM_TUX_CONSOLE]->frame[sprites[ANIM_TUX_CONSOLE]->cur];
     }
 
     game_handle_user_events();
@@ -312,7 +311,8 @@
   
   quit = 0;
   counter = 0;
-  tux_img = IMG_TUX_CONSOLE1;
+  sprites[ANIM_TUX_CONSOLE]->cur = 0;
+  tux_img = sprites[ANIM_TUX_CONSOLE]->frame[0];
 
   DEBUGMSG(debug_factoroids, "Entering factors():\n");
   /*****Initalizing the Factor activiy *****/
@@ -330,13 +330,11 @@
   {
     last_time = SDL_GetTicks();
     counter++;
-      
+
     if(counter%15 == 0)
-    {    
-      if(tux_img < IMG_TUX_CONSOLE4)
-        tux_img++;
-      else 
-        tux_img = IMG_TUX_CONSOLE1;
+    {
+      NextFrame(sprites[ANIM_TUX_CONSOLE]);
+      tux_img = sprites[ANIM_TUX_CONSOLE]->frame[sprites[ANIM_TUX_CONSOLE]->cur];
     }
 
     game_handle_user_events();
@@ -979,7 +977,7 @@
   int y;
 
   /* draw new console image with "monitor" for LED numbers: */
-  draw_console_image(IMG_CONSOLE_LED);
+  draw_console_image(images[IMG_CONSOLE_LED]);
   /* set y to draw LED numbers into Tux's "monitor": */
   y = (screen->h
      - images[IMG_CONSOLE_LED]->h
@@ -1037,16 +1035,16 @@
 }
 
 /* Draw image at lower center of screen: */
-void draw_console_image(int i)
+void draw_console_image(SDL_Surface* img)
 {
   SDL_Rect dest;
 
-  dest.x = (screen->w - images[i]->w) / 2;
-  dest.y = (screen->h - images[i]->h);
-  dest.w = images[i]->w;
-  dest.h = images[i]->h;
+  dest.x = (screen->w - img->w) / 2;
+  dest.y = (screen->h - img->h);
+  dest.w = img->w;
+  dest.h = img->h;
 
-  SDL_BlitSurface(images[i], NULL, screen, &dest);
+  SDL_BlitSurface(img, NULL, screen, &dest);
 }
 
 static void FF_draw_bkgr(void)

Modified: branches/commonification/tuxmath/trunk/src/fileops.h
===================================================================
--- branches/commonification/tuxmath/trunk/src/fileops.h	2009-08-06 17:39:45 UTC (rev 1385)
+++ branches/commonification/tuxmath/trunk/src/fileops.h	2009-08-06 20:19:02 UTC (rev 1386)
@@ -76,25 +76,11 @@
   IMG_KEYPAD_NO_NEG,
   IMG_CONSOLE_LED,
   IMG_CONSOLE_BASH,
-  IMG_TUX_CONSOLE1,
-  IMG_TUX_CONSOLE2,
-  IMG_TUX_CONSOLE3,
-  IMG_TUX_CONSOLE4,
-  IMG_TUX_RELAX1,
-  IMG_TUX_RELAX2,
-  IMG_TUX_EGYPT1,
-  IMG_TUX_EGYPT2,
-  IMG_TUX_EGYPT3,
-  IMG_TUX_EGYPT4,
+  IMG_TUX_RELAX,
+  IMG_TUX_ALARM,
   IMG_TUX_DRAT,
   IMG_TUX_YIPE,
-  IMG_TUX_YAY1,
-  IMG_TUX_YAY2,
-  IMG_TUX_YES1,
-  IMG_TUX_YES2,
   IMG_TUX_SIT,
-  IMG_TUX_FIST1,
-  IMG_TUX_FIST2,
   IMG_PENGUIN_FLAPDOWN,
   IMG_PENGUIN_FLAPUP,
   IMG_PENGUIN_INCOMING,
@@ -145,10 +131,16 @@
 
 /* Names for animated images (sprites) */
 enum {
-  IMG_COMET,
-  IMG_BONUS_COMET,
-  IMG_COMET_EXPL,
-  IMG_BONUS_COMET_EXPL,
+  ANIM_COMET,
+  ANIM_BONUS_COMET,
+  ANIM_COMET_EXPL,
+  ANIM_BONUS_COMET_EXPL,
+  ANIM_TUX_CONSOLE,
+  ANIM_TUX_EGYPT_LEFT,
+  ANIM_TUX_EGYPT_RIGHT,
+  ANIM_TUX_YAY,
+  ANIM_TUX_YES,
+  ANIM_TUX_FIST,
   NUM_SPRITES
 };
 

Modified: branches/commonification/tuxmath/trunk/src/fileops_media.c
===================================================================
--- branches/commonification/tuxmath/trunk/src/fileops_media.c	2009-08-06 17:39:45 UTC (rev 1385)
+++ branches/commonification/tuxmath/trunk/src/fileops_media.c	2009-08-06 20:19:02 UTC (rev 1386)
@@ -71,25 +71,11 @@
   "status/keypad_no_neg.png",
   "tux/console_led.png",
   "tux/console_bash.png",
-  "tux/tux-console1.png",
-  "tux/tux-console2.png",
-  "tux/tux-console3.png",
-  "tux/tux-console4.png",
-  "tux/tux-relax1.png",
-  "tux/tux-relax2.png",
-  "tux/tux-egypt1.png",
-  "tux/tux-egypt2.png",
-  "tux/tux-egypt3.png",
-  "tux/tux-egypt4.png",
+  "tux/tux-relax.svg",
+  "tux/tux-alarm.svg",
   "tux/tux-drat.png",
   "tux/tux-yipe.png",
-  "tux/tux-yay1.png",
-  "tux/tux-yay2.png",
-  "tux/tux-yes1.png",
-  "tux/tux-yes2.png",
   "tux/tux-sit.png",
-  "tux/tux-fist1.png",
-  "tux/tux-fist2.png",
   "penguins/flapdown.png",
   "penguins/flapup.png",
   "penguins/incoming.png",
@@ -141,7 +127,13 @@
   "comets/comet",
   "comets/bonus_comet",
   "comets/cometex",
-  "comets/bonus_cometex"
+  "comets/bonus_cometex",
+  "tux/tux-console",
+  "tux/tux-egypt-left",
+  "tux/tux-egypt-right",
+  "tux/tux-yay",
+  "tux/tux-yes",
+  "tux/tux-fist"
   };
 
   char fn[PATH_MAX];

Modified: branches/commonification/tuxmath/trunk/src/game.c
===================================================================
--- branches/commonification/tuxmath/trunk/src/game.c	2009-08-06 17:39:45 UTC (rev 1385)
+++ branches/commonification/tuxmath/trunk/src/game.c	2009-08-06 20:19:02 UTC (rev 1386)
@@ -45,7 +45,7 @@
 #define MS_PER_FRAME (1000 / FPS)
 
 #define CITY_EXPL_START (3 * 5)  /* Must be mult. of 5 (number of expl frames) */
-#define ANIM_FRAME_START (4 * 2) /* Must be mult. of 2 (number of tux frames) */
+#define ANIM_FRAME_LENGTH 4 /* number of real frames per one animation frame */
 #define GAMEOVER_COUNTER_START 40
 #define LEVEL_START_WAIT_START 20
 #define LASER_START 5
@@ -89,12 +89,9 @@
 static int num_attackers;
 static float speed;
 static int demo_countdown;
-static int tux_anim;
 static int tux_anim_frame;
 static int num_cities_alive;
 static int num_comets_alive;
-static int tux_img;
-static int old_tux_img;
 static int frame;
 static int neg_answer_picked;
 static int tux_pressing;
@@ -107,6 +104,10 @@
 static int extra_life_earned;
 static int key_pressed;
 
+static SDL_Surface* tux_img = NULL;
+static SDL_Surface* old_tux_img = NULL;
+static sprite* tux_anim = NULL;
+
 /* Feedback-related variables */
 static int city_expl_height;
 static int comet_feedback_number;
@@ -169,7 +170,7 @@
 static void game_write_messages(void);
 static void draw_led_console(void);
 static void draw_question_counter(void);
-static void draw_console_image(int i);
+static void draw_console_image(SDL_Surface* img);
 
 static void reset_level(void);
 static int add_comet(void);
@@ -195,6 +196,7 @@
 int game(void)
 {
   Uint32 last_time, now_time;
+  int num_frames;
 
   DEBUGMSG(debug_game, "Entering game():\n");
 
@@ -342,32 +344,38 @@
         }
 
         /* draw dancing tux: */
-        draw_console_image(IMG_CONSOLE_BASH);
+        draw_console_image(images[IMG_CONSOLE_BASH]);
         /* walk tux back and forth */
         tux_offset += tux_step;
         /* select tux_egypt images according to which way tux is headed: */
         if (tux_step < 0)
-          tux_img = IMG_TUX_EGYPT1 + ((frame / 3) % 2);
+        {
+          num_frames = sprites[ANIM_TUX_EGYPT_LEFT]->num_frames;
+          tux_img = sprites[ANIM_TUX_EGYPT_LEFT]->frame[(frame / 3) % num_frames];
+        }
         else
-          tux_img = IMG_TUX_EGYPT3 + ((frame / 3) % 2);
+        {
+          num_frames = sprites[ANIM_TUX_EGYPT_LEFT]->num_frames;
+          tux_img = sprites[ANIM_TUX_EGYPT_RIGHT]->frame[(frame / 3) % num_frames];
+        }
 
         /* turn around if we go far enough: */
-        if (tux_offset >= (screen->w)/2
-         || tux_offset <= -(screen->w)/2)
+        if (tux_offset >= (GetScreen()->w)/2
+         || tux_offset <= -(GetScreen()->w)/2)
         {
           tux_step = -tux_step;
         }
 
-        dest_tux.x = ((screen->w - images[tux_img]->w) / 2) + tux_offset;
-        dest_tux.y = (screen->h - images[tux_img]->h);
-        dest_tux.w = images[tux_img]->w;
-        dest_tux.h = images[tux_img]->h;
+        dest_tux.x = ((GetScreen()->w - tux_img->w) / 2) + tux_offset;
+        dest_tux.y = (GetScreen()->h - tux_img->h);
+        dest_tux.w = tux_img->w;
+        dest_tux.h = tux_img->h;
 
-        SDL_BlitSurface(images[tux_img], NULL, screen, &dest_tux);
+        SDL_BlitSurface(tux_img, NULL, GetScreen(), &dest_tux);
 
 /*        draw_console_image(tux_img);*/
 
-        SDL_Flip(screen);
+        SDL_Flip(GetScreen());
 
         now_time = SDL_GetTicks();
 
@@ -632,8 +640,8 @@
   paused = 0;
   doing_answer = 0;
   tux_pressing = 0;
-  tux_img = IMG_TUX_RELAX1;
-  tux_anim = -1;
+  tux_img = images[IMG_TUX_RELAX];
+  tux_anim = NULL;
   tux_anim_frame = 0;
 
   // Initialize the messages
@@ -702,7 +710,7 @@
 
   // Here are some things that have to happen before we can safely
   // draw the screen
-  tux_img = IMG_TUX_CONSOLE1;
+  tux_img = sprites[ANIM_TUX_CONSOLE]->frame[0];
   old_tux_img = tux_img;
   tux_pressing = 0;
   frame = 0;
@@ -1184,10 +1192,10 @@
     {
       /* ... pick an animation to play: */
       if ((rand() % 10) < 5)
-        tux_anim = IMG_TUX_YES1;
+        tux_anim = sprites[ANIM_TUX_YES];
       else
-        tux_anim = IMG_TUX_YAY1;
-      tux_anim_frame = ANIM_FRAME_START;
+        tux_anim = sprites[ANIM_TUX_YAY];
+      tux_anim_frame = tux_anim->num_frames * ANIM_FRAME_LENGTH;
     }
 
     /* Increment score: */
@@ -1211,9 +1219,9 @@
     PlaySound(sounds[SND_BUZZ]);
 
     if ((rand() % 10) < 5)
-      tux_img = IMG_TUX_DRAT;
+      tux_img = images[IMG_TUX_DRAT];
     else
-      tux_img = IMG_TUX_YIPE;
+      tux_img = images[IMG_TUX_YIPE];
   }
 
   /* Clear digits: */
@@ -1238,11 +1246,11 @@
 
   level_start_wait--;
   if (level_start_wait > LEVEL_START_WAIT_START / 4)
-    tux_img = IMG_TUX_RELAX1;
+    tux_img = images[IMG_TUX_RELAX];
   else if (level_start_wait > 0)
-    tux_img = IMG_TUX_RELAX2;
+    tux_img = images[IMG_TUX_ALARM];
   else
-    tux_img = IMG_TUX_SIT;
+    tux_img = images[IMG_TUX_SIT];
 
   if (level_start_wait == LEVEL_START_WAIT_START / 4)
   {
@@ -1253,13 +1261,15 @@
 void game_handle_tux(void)
 {
   static int tux_same_counter;
+  int num_frames;
+
   /* If Tux pressed a button, pick a new (different!) stance: */
   if (tux_pressing)
   {
-
+    num_frames = sprites[ANIM_TUX_CONSOLE]->num_frames;
     do
     {
-      tux_img = IMG_TUX_CONSOLE1 + (rand() % 4);
+      tux_img = sprites[ANIM_TUX_CONSOLE]->frame[rand() % num_frames];
     }
     while (tux_img == old_tux_img);
 
@@ -1267,13 +1277,13 @@
   }
 
   /* If Tux is being animated, show the animation: */
-  if (tux_anim != -1)
+  if(tux_anim)
   {
     tux_anim_frame--;
-    if (tux_anim_frame < 0)
-      tux_anim = -1;
+    if(tux_anim_frame < 0)
+      tux_anim = NULL;
     else
-      tux_img = tux_anim + 1 - (tux_anim_frame / (ANIM_FRAME_START / 2));
+      tux_img = tux_anim->frame[tux_anim->num_frames - 1 - (tux_anim_frame / ANIM_FRAME_LENGTH)];
   }
 
   /* Reset Tux to sitting if he's been doing nothing for a while: */
@@ -1282,7 +1292,7 @@
     tux_same_counter++;
     if (tux_same_counter >= 20)
     {
-      tux_img = IMG_TUX_SIT;
+      tux_img = images[IMG_TUX_SIT];
     }
   }
   else
@@ -1391,8 +1401,8 @@
           slowdown = 1;
         }
 
-        tux_anim = IMG_TUX_FIST1;
-        tux_anim_frame = ANIM_FRAME_START;
+        tux_anim = sprites[ANIM_TUX_FIST];
+        tux_anim_frame = tux_anim->num_frames * ANIM_FRAME_LENGTH;
 
         /* Destroy comet: */
         comets[i].expl = 0;
@@ -1402,7 +1412,7 @@
       if (comets[i].expl >= 0)
       {
         comets[i].expl++;
-        if (comets[i].expl >= sprites[IMG_COMET_EXPL]->num_frames * 2) {
+        if (comets[i].expl >= sprites[ANIM_COMET_EXPL]->num_frames * 2) {
           comets[i].alive = 0;
           comets[i].expl = -1;
           if (bonus_comet_counter > 1 && comets[i].zapped) {
@@ -1892,7 +1902,7 @@
       if (comets[i].expl == -1)
       {
         /* Decide which image to display: */
-        img = sprites[IMG_COMET]->frame[(frame + i) % sprites[IMG_COMET]->num_frames];
+        img = sprites[ANIM_COMET]->frame[(frame + i) % sprites[ANIM_COMET]->num_frames];
         /* Display the formula (flashing, in the bottom half
                    of the screen) */
         if (comets[i].y < screen->h / 2 || frame % 8 < 6)
@@ -1907,7 +1917,7 @@
       else
       {
         /* show each frame of explosion twice */
-        img = sprites[IMG_COMET_EXPL]->frame[comets[i].expl / 2];
+        img = sprites[ANIM_COMET_EXPL]->frame[comets[i].expl / 2];
         comet_str = comets[i].flashcard.answer_string;
       }
 
@@ -1933,7 +1943,7 @@
       if (comets[i].expl == -1)
       {
         /* Decide which image to display: */
-        img = sprites[IMG_BONUS_COMET]->frame[(frame + i) % sprites[IMG_BONUS_COMET]->num_frames];
+        img = sprites[ANIM_BONUS_COMET]->frame[(frame + i) % sprites[ANIM_BONUS_COMET]->num_frames];
         /* Display the formula (flashing, in the bottom half
                    of the screen) */
         if (comets[i].y < screen->h / 2 || frame % 8 < 6)
@@ -1947,7 +1957,7 @@
       }
       else
       {
-        img = sprites[IMG_BONUS_COMET_EXPL]->frame[comets[i].expl / 2];
+        img = sprites[ANIM_BONUS_COMET_EXPL]->frame[comets[i].expl / 2];
         comet_str = comets[i].flashcard.answer_string;
       }
 
@@ -2918,16 +2928,16 @@
 
 
 /* Draw image at lower center of screen: */
-void draw_console_image(int i)
+void draw_console_image(SDL_Surface* img)
 {
   SDL_Rect dest;
 
-  dest.x = (screen->w - images[i]->w) / 2;
-  dest.y = (screen->h - images[i]->h);
-  dest.w = images[i]->w;
-  dest.h = images[i]->h;
+  dest.x = (screen->w - img->w) / 2;
+  dest.y = (screen->h - img->h);
+  dest.w = img->w;
+  dest.h = img->h;
 
-  SDL_BlitSurface(images[i], NULL, screen, &dest);
+  SDL_BlitSurface(img, NULL, screen, &dest);
 }
 
 
@@ -2974,7 +2984,7 @@
   int y;
 
   /* draw new console image with "monitor" for LED numbers: */
-  draw_console_image(IMG_CONSOLE_LED);
+  draw_console_image(images[IMG_CONSOLE_LED]);
   /* set y to draw LED numbers into Tux's "monitor": */
   y = (screen->h
      - images[IMG_CONSOLE_LED]->h




More information about the Tux4kids-commits mailing list