[Tux4kids-commits] r630 - in tuxmath/trunk: data/missions/multiplay src

cheezmeister-guest at alioth.debian.org cheezmeister-guest at alioth.debian.org
Fri Aug 15 18:12:49 UTC 2008


Author: cheezmeister-guest
Date: 2008-08-15 18:12:47 +0000 (Fri, 15 Aug 2008)
New Revision: 630

Modified:
   tuxmath/trunk/data/missions/multiplay/mpoptions
   tuxmath/trunk/src/SDL_extras.c
   tuxmath/trunk/src/SDL_extras.h
   tuxmath/trunk/src/campaign.c
   tuxmath/trunk/src/campaign.h
   tuxmath/trunk/src/multiplayer.c
Log:
1.Conditional omission of score display
2.Fixed player cycling bug in multiplayer elimination
3.Fixed delay in skipping out of multiplayer winner screen


Modified: tuxmath/trunk/data/missions/multiplay/mpoptions
===================================================================
--- tuxmath/trunk/data/missions/multiplay/mpoptions	2008-08-15 14:37:32 UTC (rev 629)
+++ tuxmath/trunk/data/missions/multiplay/mpoptions	2008-08-15 18:12:47 UTC (rev 630)
@@ -1,7 +1,7 @@
 #master option file for multiplay
 
 play_through_list = 1
-avg_list_length = 20
+avg_list_length = 10
 vary_list_length = 1
 comprehensive = 0
 mp_multiplayer = 1

Modified: tuxmath/trunk/src/SDL_extras.c
===================================================================
--- tuxmath/trunk/src/SDL_extras.c	2008-08-15 14:37:32 UTC (rev 629)
+++ tuxmath/trunk/src/SDL_extras.c	2008-08-15 18:12:47 UTC (rev 630)
@@ -515,15 +515,24 @@
 
 }
 
-
-int WaitForKeypress(void)
+/*
+Block application until SDL receives an appropriate event. Events can be
+a single or OR'd combination of event masks. 
+e.g. e = WaitForEvent(SDL_KEYDOWNMASK | SDL_QUITMASK)
+*/
+SDL_EventType WaitForEvent(SDL_EventMask events)
 {
   SDL_Event evt;
   while (1)
+  {
     while (SDL_PollEvent(&evt) )
-      if (evt.type == SDL_KEYDOWN)
-        return evt.key.keysym.sym;
-      else SDL_Delay(50);
+    {
+      if (SDL_EVENTMASK(evt.type) & events)
+        return evt.type;
+      else 
+        SDL_Delay(50);
+    }
+  }
 }
 /* Swiped shamelessly from TuxPaint
    Based on code from: http://www.codeproject.com/cs/media/imageprocessing4.asp

Modified: tuxmath/trunk/src/SDL_extras.h
===================================================================
--- tuxmath/trunk/src/SDL_extras.h	2008-08-15 14:37:32 UTC (rev 629)
+++ tuxmath/trunk/src/SDL_extras.h	2008-08-15 18:12:47 UTC (rev 630)
@@ -44,7 +44,7 @@
 int  inRect(SDL_Rect r, int x, int y);
 void DarkenScreen(Uint8 bits);
 void SwitchScreenMode(void);
-int WaitForKeypress(void);
+SDL_EventType WaitForEvent(SDL_EventMask events);
 SDL_Surface* Blend(SDL_Surface *S1, SDL_Surface *S2,float gamma);
 SDL_Surface *zoom(SDL_Surface * src, int new_w, int new_h);
 

Modified: tuxmath/trunk/src/campaign.c
===================================================================
--- tuxmath/trunk/src/campaign.c	2008-08-15 14:37:32 UTC (rev 629)
+++ tuxmath/trunk/src/campaign.c	2008-08-15 18:12:47 UTC (rev 630)
@@ -37,18 +37,23 @@
     for (j = 1; j <= NUM_ROUNDS; ++j)
     {
       printf("Round %d\n", j);
-      
+     
+      //read in settings 
       read_named_config_file("campaign/campaign");    
       readStageSettings(i);
       readRoundSettings(i, j);
+      Opts_SetKeepScore(0);
           
       snprintf(roundmessage, 10, "Round %d", j);
       game_set_start_message(roundmessage, "", "", "");
 
-      Opts_SetKeepScore(0);
       MC_PrintMathOptions(stdout, 0);
+
+      //play!
       printf("Starting game...\n");
-      gameresult = game();
+      gameresult = game();
+      
+      //move on if we've won, game over if not
       if (gameresult == GAME_OVER_WON)
         ;
       else if (gameresult == GAME_OVER_LOST)
@@ -76,8 +81,8 @@
       
       if (endcampaign)
         return 0;
+    }
       
-    }
     //if we've beaten the last stage, there is no bonus, skip to win sequence
     if (i == NUM_STAGES - 1)
     {
@@ -110,14 +115,15 @@
   SDL_Rect textarea = screen->clip_rect;
   SDL_Surface* loadedsprite = LoadImage(sprites[stage], IMG_REGULAR|IMG_NOT_REQUIRED);
   
-  if (loadedsprite)
+  if (loadedsprite) //stretch the tiny sprite to 3x
   {
     icon = zoom(loadedsprite, loadedsprite->w*3, loadedsprite->h*3);
     textarea.x = icon->w;
     textarea.y = icon->h;
     textarea.w = screen->w - icon->w;
     textarea.h = screen->h - icon->h;
-  }
+  }
+  //show this stage's text
   tmdprintf("Briefing\n");
   SDL_BlitSurface(icon, NULL, screen, NULL);
   scroll_text(briefings[stage], textarea, 1);

Modified: tuxmath/trunk/src/campaign.h
===================================================================
--- tuxmath/trunk/src/campaign.h	2008-08-15 14:37:32 UTC (rev 629)
+++ tuxmath/trunk/src/campaign.h	2008-08-15 18:12:47 UTC (rev 630)
@@ -1,6 +1,12 @@
 #ifndef CAMPAIGN_H
 #define CAMPAIGN_H
 
+/*
+ * campaign.h - prose and function declarations for TuxMath's 'Mission mode' 
+ * 
+ * Author: B. Luchen
+ */
+ 
 #include "SDL_extras.h"
 
 #define TESTING_CAMPAIGN

Modified: tuxmath/trunk/src/multiplayer.c
===================================================================
--- tuxmath/trunk/src/multiplayer.c	2008-08-15 14:37:32 UTC (rev 629)
+++ tuxmath/trunk/src/multiplayer.c	2008-08-15 18:12:47 UTC (rev 630)
@@ -72,17 +72,18 @@
         pscores[currentplayer] = 0xbeef;
         winners[--activeplayers] = currentplayer;
       }
-
-      while (pscores[currentplayer] == 0xbeef) //skip over eliminated players
+            
+      do
       {
         ++currentplayer;
         currentplayer %= params[PLAYERS];
         if (currentplayer == 0)
           ++round;
-      }
+      } 
+      while (pscores[currentplayer] == 0xbeef); //skip over eliminated players
+      
       if (activeplayers <= 1) //last man standing!
       {
-//        showWinners(winners, params[PLAYERS]);
         tmdprintf("%d wins\n", currentplayer);
         winners[0] = currentplayer;
         done = 1;
@@ -94,6 +95,7 @@
     int hiscore = 0;
     int currentwinner = -1;
 
+    //play through rounds
     for (round = 1; round <= params[ROUNDS]; ++round)
     {
       for (currentplayer = 0; currentplayer < params[PLAYERS]; ++currentplayer)
@@ -105,6 +107,8 @@
           pscores[currentplayer] += 500; //plus a possible bonus
       }
     }
+    
+    //sort out winners
     for (i = 0; i < params[PLAYERS]; ++i)
     {
       for (currentplayer = 0; currentplayer < params[PLAYERS]; ++currentplayer)
@@ -119,6 +123,7 @@
       }
     }
   }
+  
   tmdprintf("Game over; showing winners\n");
   showWinners(winners, params[PLAYERS]);
   cleanupMP();
@@ -126,11 +131,21 @@
 
 int mp_get_player_score(int playernum)
 {
+  if (playernum > params[PLAYERS])
+  {
+    tmdprintf("No player %d!\n", playernum);
+    return 0;
+  }
   return pscores[playernum];
 }
 
 const char* mp_get_player_name(int playernum)
 {
+  if (playernum > params[PLAYERS])
+  {
+    tmdprintf("No player %d!\n", playernum);
+    return 0;
+  }
   return pnames[playernum];
 }
 
@@ -183,7 +198,7 @@
   SDL_FillRect(screen, NULL, 0);
   draw_text(text, center);
   SDL_Flip(screen);
-  WaitForKeypress();
+  WaitForEvent(SDL_KEYDOWNMASK);
 }
 
 int initMP()




More information about the Tux4kids-commits mailing list