[Tux4kids-commits] r583 - tuxmath/branches/factroids/src

fongog-guest at alioth.debian.org fongog-guest at alioth.debian.org
Sun Aug 3 22:20:08 UTC 2008


Author: fongog-guest
Date: 2008-08-03 22:20:07 +0000 (Sun, 03 Aug 2008)
New Revision: 583

Modified:
   tuxmath/branches/factroids/src/factroids.c
   tuxmath/branches/factroids/src/highscore.c
   tuxmath/branches/factroids/src/titlescreen.c
   tuxmath/branches/factroids/src/tuxmath.h
Log:
Add: A new highsocres lists for the fraction and factions activities!
Add: Intros



Modified: tuxmath/branches/factroids/src/factroids.c
===================================================================
--- tuxmath/branches/factroids/src/factroids.c	2008-08-03 22:19:37 UTC (rev 582)
+++ tuxmath/branches/factroids/src/factroids.c	2008-08-03 22:20:07 UTC (rev 583)
@@ -52,7 +52,7 @@
 /********* Enumerations ***********/
 
 enum{
-  FACTROIDS_GAME,
+  FACTOROIDS_GAME,
   FRACTIONS_GAME
 };
 
@@ -158,7 +158,7 @@
 static int gameover_counter;
 static int game_status;
 static int SDL_quit_received;
-static int done, quit;
+static int quit;
 static int digits[3];
 static int num;
 
@@ -176,43 +176,47 @@
 static int bkg_h, counter;
 static int xdead, ydead, isdead, countdead;
 
-//static int SDL_Surface *screen2;
+/*************** The Factor and Faraction Activiy game Functions ***************/
 
 static int FF_init(void);
 static void FF_intro(void);
+
 static void FF_handle_ship(void);
 static void FF_handle_asteroids(void);
 static void FF_handle_answer(void);
+
 static void FF_draw(void);
+static void FF_draw_bkgr(void);
+
 static void FF_add_level(void);
-static void FF_loose(void);
-static void FF_win(void);
+static int FF_over(int game_status);
 static void FF_exit_free(void);
+
 static int FF_add_laser(void);
 static int FF_add_asteroid(int x, int y, int xspeed, int yspeed, int size, int angle, int 				   angle_speed, int fact_num, int a, int b, int new_wave);
 static int FF_destroy_asteroid(int i, int xspeed, int yspeed);
 
+static void FF_ShowMessage(char* str1, char* str2, char* str3, char* str4);
+
 static int is_prime(int num);
 static int fast_cos(int angle);
 static int fast_sin(int angle);
 
 
+/************** factors(): The factor main function ********************/
 void factors(void){
 
 
   Uint32 last_time, now_time; 
   
-  done = 0;
   quit = 0;
   counter = 0;
   
-
-  
   #ifdef TUXMATH_DEBUG
      fprintf(stderr, "Entering factors():\n");
   #endif
 
-  FF_game=FACTROIDS_GAME;
+  FF_game=FACTOROIDS_GAME;
   
   if (!FF_init())
   {
@@ -223,12 +227,9 @@
   
   FF_intro();
   
-  while (!done){
+  while (game_status==GAME_IN_PROGRESS){
       last_time = SDL_GetTicks();
-      counter++;
-      if(tuxship.lives<=0)
-        done=1;
-      
+      counter++; 
    
     game_handle_user_events();
 
@@ -271,13 +272,14 @@
       SDL_Delay(now_time);
     }
   }
+  FF_over(game_status);
 }
 
+/************** fractions(): The fractions main function ********************/
 void fractions(void){
 
   Uint32 last_time, now_time; 
   
-  done = 0;
   quit = 0;
   counter = 0;
   
@@ -302,56 +304,53 @@
   FF_intro();
 
   /************ Main Loop **************/
-  while (!done){
+  while (game_status==GAME_IN_PROGRESS){
       last_time = SDL_GetTicks();
       counter++;
-      if(tuxship.lives<=0)
-        done=1;
       
-   
-    game_handle_user_events();
+      game_handle_user_events();
 
-    FF_handle_ship();
-    FF_handle_asteroids();
-    FF_handle_answer();
-    FF_draw();
+      FF_handle_ship();
+      FF_handle_asteroids();
+      FF_handle_answer();
+      FF_draw();
 
-    game_status = check_exit_conditions();
+      game_status = check_exit_conditions();
 
-    if (paused)
-    {
-      pause_game();
-      paused = 0;
-    }
+      if (paused)
+      {
+        pause_game();
+        paused = 0;
+      }
 
 
 #ifndef NOSOUND
-    if (Opts_UsingSound())
-    {
-      if (!Mix_PlayingMusic())
+      if (Opts_UsingSound())
       {
+        if (!Mix_PlayingMusic())
+        {
 	    Mix_PlayMusic(musics[MUS_GAME + (rand() % 3)], 0);
-      }  
-    }
+        }  
+      }
 #endif
 
-
-
       /* Pause (keep frame-rate event) */
-    now_time = SDL_GetTicks();
-    if (now_time < last_time + MS_PER_FRAME)
-    {
-      //Prevent any possibility of a time wrap-around
-      // (this is a very unlikely problem unless there is an SDL bug
-      //  or you leave tuxmath running for 49 days...)
-      now_time = (last_time+MS_PER_FRAME) - now_time;  // this holds the delay
-      if (now_time > MS_PER_FRAME)
-	now_time = MS_PER_FRAME;
-      SDL_Delay(now_time);
-    }
+      now_time = SDL_GetTicks();
+      if (now_time < last_time + MS_PER_FRAME)
+      {
+        //Prevent any possibility of a time wrap-around
+        // (this is a very unlikely problem unless there is an SDL bug
+        //  or you leave tuxmath running for 49 days...)
+        now_time = (last_time+MS_PER_FRAME) - now_time;  // this holds the delay
+        if (now_time > MS_PER_FRAME)
+	  now_time = MS_PER_FRAME;
+        SDL_Delay(now_time);
+      }
   }
+  FF_over(game_status);
 }
 
+/************ Initialize all vars... ****************/
 static int FF_init(void){
   int i;
   SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
@@ -362,6 +361,7 @@
   bgSrc.w=screen->w;
   bgSrc.h=screen->h;
   
+  escape_received = 0;
   game_status = GAME_IN_PROGRESS;  
   
   // Allocate memory 
@@ -398,8 +398,42 @@
 }
 
 
-static void FF_intro(void){}
+static void FF_intro(void){
+  
+  SDL_Event event;
+  SDL_Rect rect;
 
+  FF_draw_bkgr();
+  if(FF_game==FACTOROIDS_GAME)
+  {
+    FF_ShowMessage(_("THE FACTOR ACTIVIY"),
+		   _("To win, you need destroy all the asteroids finding their"),
+		   _("factor numbers... The rocks will split until you got the prime number!"),
+		   _("Type the factor number and shot presing return!"));
+  }
+  else if (FF_game==FRACTIONS_GAME)
+  {
+    FF_ShowMessage(_("THE FRACTION ACTIVIY"),
+		   _("To win, you need destroy all the asteroids finding a number that"),
+		   _("can simplify teh fration... The rocks will split until you got all"),
+		   _("Type the number and shot presing return!"));
+  }
+  while(1){
+    SDL_PollEvent(&event);
+    if (event.type == SDL_QUIT)
+    {
+      SDL_quit_received = 1;
+      quit = 1;
+    }
+    if (event.type == SDL_MOUSEBUTTONDOWN ||
+        event.type == SDL_KEYDOWN ||
+	event.type == SDL_KEYUP)
+    {
+      return;
+    }
+  }
+}
+
 static void FF_handle_ship(void){
 
 /****************** Ship center... ******************/
@@ -576,9 +610,8 @@
 
   /************ Draw Background ***************/ 
 
-  SDL_BlitSurface(images[BG_STARS], NULL, screen, NULL);
-  //if(bgSrc.y>bkg_h)
-  //  SDL_BlitSurface(images[BG_STARS], NULL, screen, &bgScreen);
+  FF_draw_bkgr();
+
 /******************* Draw laser *************************/
   for (i=0;i<MAX_LASER;i++){
     if(laser[i].alive)
@@ -620,7 +653,7 @@
      if(asteroid[i].size==2){
         SDL_BlitSurface(images[IMG_ASTEROID2], NULL, screen, &dest);
      }
-     if(FF_game==FACTROIDS_GAME)
+     if(FF_game==FACTOROIDS_GAME)
      {   
        sprintf(str, "%.1d", asteroid[i].fact_number);
        draw_nums(str, asteroid[i].x+20,asteroid[i].y+10);
@@ -703,6 +736,15 @@
 
 }
 
+static void FF_draw_bkgr(void)
+{
+
+  SDL_BlitSurface(images[BG_STARS], NULL, screen, NULL);
+  //if(bgSrc.y>bkg_h)
+  //  SDL_BlitSurface(images[BG_STARS], NULL, screen, &bgScreen);
+
+}
+
 static void FF_add_level(void)
 {
   int i;
@@ -713,7 +755,7 @@
   for (i=0; (i<(NUM_ASTEROIDS/2)) && NUM_ASTEROIDS<MAX_ASTEROIDS; i++){
    
    //int FF_add_asteroid(int x, int y, int xspeed, int yspeed, int size, int angle, int angle_speed, int fact_number, int a, int b, int new_wave)
-   if(FF_game==FACTROIDS_GAME){
+   if(FF_game==FACTOROIDS_GAME){
      FF_add_asteroid(rand()%(screen->w), rand()%(screen->h),
 		     rand()%4, rand()%3,
                      rand()%2, 
@@ -750,7 +792,7 @@
      }
    } 
    if((NUM_ASTEROIDS%2)==1){
-     if(FF_game==FACTROIDS_GAME){
+     if(FF_game==FACTOROIDS_GAME){
        FF_add_asteroid(rand()%(screen->w), rand()%(screen->h),
 		       (-1*rand()%4), (-1*rand()%3),
                        rand()%2, 
@@ -772,12 +814,142 @@
    }
 }
 
-static void FF_loose(void){
-  
+static int FF_over(int game_status){
+  Uint32 last_time, now_time; 
+  SDL_Rect dest_message;
+  SDL_Event event;
+
+#ifdef TUXMATH_DEBUG
+  print_exit_conditions();
+#endif
+
+  /* TODO: need better "victory" screen with animation, special music, etc., */
+  /* as well as options to review missed questions, play again using missed  */
+  /* questions as question list, etc.                                        */
+  switch (game_status)
+  {
+    case GAME_OVER_WON:
+    {
+      int looping = 1;
+//      int frame;
+      /* set up victory message: */
+      dest_message.x = (screen->w - images[IMG_GAMEOVER_WON]->w) / 2;
+      dest_message.y = (screen->h - images[IMG_GAMEOVER_WON]->h) / 2;
+      dest_message.w = images[IMG_GAMEOVER_WON]->w;
+      dest_message.h = images[IMG_GAMEOVER_WON]->h;
+
+      do
+      {
+        //frame++;
+        last_time = SDL_GetTicks();
+
+        /* draw flashing victory message: */
+        //if (((frame / 2) % 4))
+        //{
+          SDL_BlitSurface(images[IMG_GAMEOVER_WON], NULL, screen, &dest_message);
+        //}
+
+
+        SDL_Flip(screen);
+
+        while (1)
+        {
+	  SDL_PollEvent(&event);
+          if  (event.type == SDL_QUIT
+            || event.type == SDL_KEYDOWN
+            || event.type == SDL_MOUSEBUTTONDOWN)
+          {
+            looping = 0;
+	    break;
+          }
+        }
+
+        now_time = SDL_GetTicks();
+
+        if (now_time < last_time + MS_PER_FRAME)
+	  SDL_Delay(last_time + MS_PER_FRAME - now_time);
+      }
+      while (looping);
+      break;
+    }
+
+    case GAME_OVER_ERROR:
+    {
+#ifdef TUXMATH_DEBUG
+      printf("\ngame() exiting with error");
+#endif
+    }
+    case GAME_OVER_LOST:
+    case GAME_OVER_OTHER:
+    {
+      int looping = 1;
+
+      /* set up GAMEOVER message: */
+      dest_message.x = (screen->w - images[IMG_GAMEOVER]->w) / 2;
+      dest_message.y = (screen->h - images[IMG_GAMEOVER]->h) / 2;
+      dest_message.w = images[IMG_GAMEOVER]->w;
+      dest_message.h = images[IMG_GAMEOVER]->h;
+
+      do
+      {
+        //frame++;
+        last_time = SDL_GetTicks();
+
+        SDL_BlitSurface(images[IMG_GAMEOVER], NULL, screen, &dest_message);
+        SDL_Flip(screen);
+
+        while (1)
+        {
+	  SDL_PollEvent(&event);
+          if  (event.type == SDL_QUIT
+            || event.type == SDL_KEYDOWN
+            || event.type == SDL_MOUSEBUTTONDOWN)
+          {
+            looping = 0;
+	    break;
+          }
+        }
+
+        now_time = SDL_GetTicks();
+
+        if (now_time < last_time + MS_PER_FRAME)
+	  SDL_Delay(last_time + MS_PER_FRAME - now_time);
+      }
+      while (looping);
+
+      break;
+    }
+
+    case GAME_OVER_ESCAPE:
+    {
+      break;
+    }
+
+    case GAME_OVER_WINDOW_CLOSE:
+    {
+      break;
+    }
+
+  }
+
+  FF_exit_free();
+
+  /* Save score in case needed for high score table: */
+  Opts_SetLastScore(score);
+
+  /* Return the chosen command: */
+  if (GAME_OVER_WINDOW_CLOSE == game_status)
+  {
+    /* program exits: */
+    FF_exit_free();;
+    return 1;
+  }
+  else
+  {
+    /* return to title() screen: */
+    return 0;
+  }
 }
-static void FF_win(void){
-  
-}
 
 static void FF_exit_free()
 {
@@ -790,7 +962,6 @@
 int is_prime(int num)
 {
   int i;
-  //int divisor=2;
   if (num==0 || num==1 || num==-1) return 1;
   else if (num>0)
   {
@@ -908,7 +1079,7 @@
 		   }
                    if (num!=0)
 		   {  
-		     if(FF_game==FACTROIDS_GAME)
+		     if(FF_game==FACTOROIDS_GAME)
 		     {
                         if(((asteroid[k].fact_number%num)==0) && (num!=asteroid[k].fact_number))
 		        {
@@ -993,7 +1164,7 @@
 		     return 1;
 		   }
 
-		  if(FF_game==FACTROIDS_GAME)
+		  if(FF_game==FACTOROIDS_GAME)
 		  {
 
 
@@ -1071,7 +1242,7 @@
       asteroid[i].angle=angle;
       asteroid[i].angle_speed=angle_speed;
       
-      if(FF_game==FACTROIDS_GAME){
+      if(FF_game==FACTOROIDS_GAME){
 
          asteroid[i].fact_number=fact_number;
 
@@ -1135,7 +1306,7 @@
      if(asteroid[i].size>0){
       /* Break the rock into two smaller ones! */
       if(num!=0){
-        if(FF_game==FACTROIDS_GAME){
+        if(FF_game==FACTOROIDS_GAME){
           FF_add_asteroid(asteroid[i].x,
 	  	          asteroid[i].y,
 	  	          ((asteroid[i].xspeed + xspeed) / 2),
@@ -1185,9 +1356,75 @@
   return 0;
 }
 
-/************** MODIFIED FUNCS FROM game.c ******************/
+/************** MODIFIED FUNCS FROM game.c and titlescreen.c ******************/
 
+void FF_ShowMessage(char* str1, char* str2, char* str3, char* str4)
+{
+  SDL_Surface *s1, *s2, *s3, *s4;
+  SDL_Rect loc;
+  int finished = 0;
+  int tux_frame = 0;
+  Uint32 frame = 0;
+  Uint32 start = 0;
 
+  s1 = s2 = s3 = s4 = NULL;
+
+#ifdef TUXMATH_DEBUG
+  fprintf(stderr, "ShowMessage() - creating text\n" );
+#endif
+
+  if (str1)
+    s1 = BlackOutline(str1, default_font, &white);
+  if (str2)
+    s2 = BlackOutline(str2, default_font, &white);
+  if (str3)
+    s3 = BlackOutline(str3, default_font, &white);
+  /* When we get going with i18n may need to modify following - see below: */
+  if (str4)
+    s4 = BlackOutline(str4, default_font, &white);
+
+#ifdef TUXMATH_DEBUG
+  fprintf(stderr, "NotImplemented() - drawing screen\n" );
+#endif
+
+
+  /* Draw lines of text (do after drawing Tux so text is in front): */
+  if (s1)
+  {
+    loc.x = (screen->w / 2) - (s1->w/2); 
+    loc.y = (screen->h / 2) + 10;
+    SDL_BlitSurface( s1, NULL, screen, &loc);
+  }
+  if (s2)
+  {
+    loc.x = (screen->w / 2) - (s2->w/2); 
+    loc.y = (screen->h / 2) + 60;
+    SDL_BlitSurface( s2, NULL, screen, &loc);
+  }
+  if (s3)
+  {
+    loc.x = (screen->w / 2) - (s3->w/2); 
+    loc.y = (screen->h / 2) + 110;
+    SDL_BlitSurface( s3, NULL, screen, &loc);
+  }
+  if (s4)
+  {
+    loc.x = (screen->w / 2) - (s4->w/2); 
+    loc.y = (screen->h / 2) + 200;
+    SDL_BlitSurface( s4, NULL, screen, &loc);
+  }
+
+  /* and update: */
+  SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+
+  SDL_FreeSurface(s1);
+  SDL_FreeSurface(s2);
+  SDL_FreeSurface(s3);
+  SDL_FreeSurface(s4);
+}
+
+
 void game_handle_user_events(void)
 {
   SDL_Event event;
@@ -1198,7 +1435,6 @@
     if (event.type == SDL_QUIT)
     {
       SDL_quit_received = 1;
-      done = 1;
       quit = 1;
     }
     if (event.type == SDL_MOUSEBUTTONDOWN)
@@ -1215,7 +1451,8 @@
 	  if (key == SDLK_ESCAPE)
 	  {
             // Return to menu! 
-	            done = 1;
+            escape_received = 1;
+
 	  }
 	  
 	  // Key press... 
@@ -1414,7 +1651,6 @@
     key = SDLK_ESCAPE;
     //game_key_event(key);
     escape_received = 1;
-    done = 1;
     quit = 1;
     return -1;
   } 
@@ -1588,8 +1824,12 @@
   }
   if(tuxship.lives<=0)
   {
-     GAME_OVER_LOST;
+    return GAME_OVER_LOST;
   }
+  if(score>=10000 || wave >= 30 )
+  {
+    return GAME_OVER_WON;
+  }
   /* determine if game lost (i.e. all cities blown up): */
   /*if (!num_cities_alive)
   {

Modified: tuxmath/branches/factroids/src/highscore.c
===================================================================
--- tuxmath/branches/factroids/src/highscore.c	2008-08-03 22:19:37 UTC (rev 582)
+++ tuxmath/branches/factroids/src/highscore.c	2008-08-03 22:20:07 UTC (rev 583)
@@ -140,7 +140,7 @@
           /* "Right" button - go to next page: */
           if (inRect( rightRect, event.button.x, event.button.y ))
           {
-            if (diff_level < ACE_HIGH_SCORE)
+            if (diff_level < (NUM_HIGH_SCORE_LEVELS-1))
             {
               diff_level++;
               if (Opts_MenuSound())
@@ -243,6 +243,12 @@
             case ACE_HIGH_SCORE:
               srfc = BlackOutline(_("Ace"), title_font, &white);
               break;
+            case FACTORS_HIGH_SCORE:
+              srfc = BlackOutline(_("Factors"), title_font, &white);
+              break;
+            case FRACTIONS_HIGH_SCORE:
+              srfc = BlackOutline(_("Fractions"), title_font, &white);
+              break;
             default:
               srfc = BlackOutline(_("Space Cadet"), title_font, &white);
           }
@@ -624,7 +630,7 @@
 
   /* Make sure diff_level is valid: */
   if (diff_level < 0
-   || diff_level > ACE_HIGH_SCORE)
+   || diff_level > (NUM_HIGH_SCORE_LEVELS-1))
   {
     fprintf(stderr, "In insert_score(), diff_level invalid!\n");
     return 0;
@@ -704,6 +710,16 @@
         fprintf(fp, "\nAce:\n");
         break;
       }
+      case FACTORS_HIGH_SCORE:
+      {
+        fprintf(fp, "\nFactors:\n");
+        break;
+      }
+      case FRACTIONS_HIGH_SCORE:
+      {
+        fprintf(fp, "\nFractions:\n");
+        break;
+      }
     }
 
     for (j = 0; j < HIGH_SCORES_SAVED; j++)
@@ -777,9 +793,9 @@
 {
   /* Make sure diff_level is valid: */
   if (diff_level < 0
-   || diff_level > ACE_HIGH_SCORE)
+   || diff_level > (NUM_HIGH_SCORE_LEVELS-1))
   {
-    fprintf(stderr, "In HS_Score(), diff_level invalid!\n");
+    fprintf(stderr, "In HS_Score(), diff_level %d invalid!\n", diff_level);
     return -1;
   }
 
@@ -800,7 +816,7 @@
 {
   /* Make sure diff_level is valid: */
   if (diff_level < 0
-   || diff_level > ACE_HIGH_SCORE)
+   || diff_level > (NUM_HIGH_SCORE_LEVELS-1))
   {
     fprintf(stderr, "In HS_Score(), diff_level invalid!\n");
     return NULL;

Modified: tuxmath/branches/factroids/src/titlescreen.c
===================================================================
--- tuxmath/branches/factroids/src/titlescreen.c	2008-08-03 22:19:37 UTC (rev 582)
+++ tuxmath/branches/factroids/src/titlescreen.c	2008-08-03 22:20:07 UTC (rev 583)
@@ -283,7 +283,7 @@
 
   /* --- Pull tux & logo onscreen --- */
   /* NOTE we wind up with Tuxdest.y == (screen->h)  - (Tux->frame[0]->h), */
-  /* and Titledest.x == 0.                                                */
+  /* a 	nd Titledest.x == 0.                                                */
   if (current_bkg()
    && images[IMG_MENU_TITLE]
    && images[IMG_STOP]
@@ -827,6 +827,8 @@
     {(const unsigned char*)N_("Factors"),
      (const unsigned char*)N_("Fractions"),
      (const unsigned char*)N_("Main menu")};
+  const int factroids_high_score_tables[2] =
+    {FACTORS_HIGH_SCORE,FRACTIONS_HIGH_SCORE};
   sprite* sprites[3] =
     {NULL, NULL, NULL};
   menu_options menu_opts;
@@ -866,12 +868,38 @@
           // Return to main menu
           return 0;
     }
-  
 
+	hs_table = factroids_high_score_tables[choice];
+	if (check_score_place(hs_table, Opts_LastScore()) < HIGH_SCORES_SAVED){
+
+	  unsigned char player_name[HIGH_SCORE_NAME_LENGTH * 3];
+
+	  /* Get name from player: */
+	  HighScoreNameEntry(&player_name[0]);
+	  insert_score(player_name, hs_table, Opts_LastScore());
+	  /* Show the high scores. Note the user will see his/her */
+	  /* achievement even if (in the meantime) another player */
+	  /* has in fact already bumped this score off the table. */
+	  DisplayHighScores(hs_table);
+	  /* save to disk: */
+	  /* See "On File Locking" in fileops.c */
+	  append_high_score(hs_table,Opts_LastScore(),&player_name[0]);
+
+#ifdef TUXMATH_DEBUG
+	  print_high_scores(stderr);
+#endif
+	}
+       else {
+	fprintf(stderr, "\nCould not find config file\n");
+      }  
+
     menu_opts.starting_entry = choice;
     choice = choose_menu_item(menu_text,sprites,3,NULL,NULL);
+
+
   }
 
+
   return 0; 
 }
 

Modified: tuxmath/branches/factroids/src/tuxmath.h
===================================================================
--- tuxmath/branches/factroids/src/tuxmath.h	2008-08-03 22:19:37 UTC (rev 582)
+++ tuxmath/branches/factroids/src/tuxmath.h	2008-08-03 22:20:07 UTC (rev 583)
@@ -124,6 +124,8 @@
   SCOUT_HIGH_SCORE,
   RANGER_HIGH_SCORE,
   ACE_HIGH_SCORE,
+  FACTORS_HIGH_SCORE,
+  FRACTIONS_HIGH_SCORE,
   NUM_HIGH_SCORE_LEVELS
 };
 




More information about the Tux4kids-commits mailing list