[Tux4kids-commits] r8 - in tuxmath/trunk: data/images/status docs src

dbruce at alioth.debian.org dbruce at alioth.debian.org
Thu Mar 8 20:57:32 CET 2007


Author: dbruce
Date: 2006-03-01 17:19:00 +0000 (Wed, 01 Mar 2006)
New Revision: 8

Added:
   tuxmath/trunk/data/images/status/keypad.png
   tuxmath/trunk/data/images/status/keypad_no_neg.png
   tuxmath/trunk/data/images/status/led_neg_sign.png
Removed:
   tuxmath/trunk/data/images/status/keypad.png
Modified:
   tuxmath/trunk/docs/CHANGES.txt
   tuxmath/trunk/docs/README.txt
   tuxmath/trunk/src/credits.c
   tuxmath/trunk/src/game.c
   tuxmath/trunk/src/images.h
   tuxmath/trunk/src/options.c
   tuxmath/trunk/src/setup.c
   tuxmath/trunk/src/setup.h
   tuxmath/trunk/src/title.c
   tuxmath/trunk/src/tuxmath.c
Log:
Adds negative number support


Deleted: tuxmath/trunk/data/images/status/keypad.png
===================================================================
(Binary files differ)

Added: tuxmath/trunk/data/images/status/keypad.png
===================================================================
(Binary files differ)


Property changes on: tuxmath/trunk/data/images/status/keypad.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: tuxmath/trunk/data/images/status/keypad_no_neg.png
===================================================================
(Binary files differ)


Property changes on: tuxmath/trunk/data/images/status/keypad_no_neg.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: tuxmath/trunk/data/images/status/led_neg_sign.png
===================================================================
(Binary files differ)


Property changes on: tuxmath/trunk/data/images/status/led_neg_sign.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: tuxmath/trunk/docs/CHANGES.txt
===================================================================
--- tuxmath/trunk/docs/CHANGES.txt	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/docs/CHANGES.txt	2006-03-01 17:19:00 UTC (rev 8)
@@ -1,7 +1,27 @@
 CHANGES.txt for "tuxmath"
 
-March 7, 2005
+2006.Mar.1 (https://svn.tux4kids.net/tuxmath/ - revision 6)
+  Game:
+    * Added support for negative subtraction answers.
+      Updated led drawing to include negative sign.
+      Updated on-screen keypad to include '+' and '-'. 
+      David Bruce <dbruce at tampabay.rr.com>
 
+2006.Feb.18 (https://svn.tux4kids.net/tuxmath/ - revision 5)
+  Options:
+    * Added mouse support to Options screen
+      David Bruce <dbruce at tampabay.rr.com>
+
+2006.Feb.14 (https://svn.tux4kids.net/tuxmath/ - revision 4)
+  Options:
+    * Added speed control to Options screen
+      Yves Combe <yves at ycombe.net>
+
+2006.Feb.7 (https://svn.tux4kids.net/tuxmath/ - revision 3)
+  Options:
+    * Fixed minor deadlock bug if all operations deselected
+      David Bruce <dbruce at tampabay.rr.com>
+
 2005.Mar.7
   Interface:
     * Added sound effects to Options screen.

Modified: tuxmath/trunk/docs/README.txt
===================================================================
--- tuxmath/trunk/docs/README.txt	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/docs/README.txt	2006-03-01 17:19:00 UTC (rev 8)
@@ -81,7 +81,13 @@
                          auto-play the game.  The only user interaction
                          can be for quitting or pausing.
 
+      --allownegatives   Allows subtraction answers to be less than zero.
+      -n                 When selected, the led numbers at the top of the
+                         screen will include a fourth digit for the '-' sign.
+                         Also, if --keypad is selected, the '-' and '+' may
+                         be grayed-out depending if negatives are allowed.
 
+
     These command-line options display useful information, but the program
     does not attempt to start up in interactive mode.
 
@@ -103,11 +109,11 @@
 ------------------
   Title Screen
   ------------
-    On this screen, you can choose to play the game, change the gameplay
-    options, view the credits, or quit.
+    On this screen, you can choose to play the game, go to the Options
+    Screen, view the credits, or quit.
 
     Use the [UP] and [DOWN] arrow keys to select what you wish to do,
-    and then press [ENTER / RETURN].  Or, use the mouse to click the
+    and then press [ENTER / RETURN / SPACEBAR].  Or, use the mouse to click the
     menu item.
 
     Pressing [ESCAPE] will quit the program.
@@ -115,9 +121,20 @@
 
   Options Screen
   --------------
-    [ UNDER CONSTRUCTION ]
+    On this screen, you can select some of the gameplay options or return to 
+    the Title Screen.  Currently, the four math operations can be enabled
+    or disenabled, as well as the speed setting and ranges of numbers to use. 
 
+    Use the [UP] and [DOWN] arrow keys to select what you wish to do,
+    and then press [ENTER / RETURN /SPACEBAR].  Or, use the mouse to click the
+    menu item.
 
+    Mouse support has been added.
+
+    Pressing [ESCAPE] will return to the Title Screen.  Currently, there is no
+    method of doing this with the mouse.
+
+
   Credits Screen
   --------------
     This screen displays the credits.  You can press [ESCAPE] to return

Modified: tuxmath/trunk/src/credits.c
===================================================================
--- tuxmath/trunk/src/credits.c	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/credits.c	2006-03-01 17:19:00 UTC (rev 8)
@@ -381,7 +381,7 @@
       
       
       /* Handle any incoming events: */
-      
+      /* TODO allow player to return to Title with mouse click */
       while (SDL_PollEvent(&event) > 0)
 	{
 	  if (event.type == SDL_QUIT)

Modified: tuxmath/trunk/src/game.c
===================================================================
--- tuxmath/trunk/src/game.c	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/game.c	2006-03-01 17:19:00 UTC (rev 8)
@@ -85,8 +85,10 @@
 static SDL_Surface * bkgd;
 static int last_bkgd;
 
+static int neg_answer_picked;
+static int tux_pressing, done, paused, doing_answer;
+static int level_start_wait;
 
-
 /* Local function prototypes: */
 
 static void reset_level(void);
@@ -100,16 +102,19 @@
 static int pick_operand(int min);
 static int in_range(int n);
 
-
-
+static void draw_led_nums(void);
+static void game_mouse_event(SDL_Event the_event);
+static void game_key_event(SDLKey pressed_key);
 /* --- MAIN GAME FUNCTION!!! --- */
 
+/* FIXME consider breaking this large function up into more managable pieces */
+/* e.g. initialize(), handle_events(), update_data(), draw(), etc            */ 
 int game(void)
 {
-  int i, j, num, img, done, quit, frame, lowest, lowest_y, kx, ky,
-    tux_img, old_tux_img, tux_pressing, tux_anim, tux_anim_frame,
-    tux_same_counter, level_start_wait, num_cities_alive, doing_answer,
-    num_comets_alive, paused, demo_countdown, picked_comet, answer_digit,
+  int i, j, num, img, quit, frame, lowest, lowest_y,
+    tux_img, old_tux_img, tux_anim, tux_anim_frame,
+    tux_same_counter, num_cities_alive,
+    num_comets_alive, demo_countdown, picked_comet, answer_digit,
     gameover;
   SDL_Event event;
   Uint32 last_time, now_time;
@@ -118,7 +123,6 @@
   char str[64];
   char* comet_str;
 
-
   /* Clear window: */
   
   SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
@@ -138,8 +142,8 @@
   gameover = 0;
   demo_countdown = 1000;
   level_start_wait = LEVEL_START_WAIT_START;
-
-  
+  neg_answer_picked = 0;
+ 
   /* (Create and position cities) */
   
   for (i = 0; i < NUM_CITIES; i++)
@@ -210,131 +214,17 @@
 	  if (event.type == SDL_QUIT)
 	    {
 	      /* Window close event - quit! */
-	      
 	      quit = 1;
 	      done = 1;
 	    }
 	  else if (event.type == SDL_KEYDOWN)
 	    {
 	      key = event.key.keysym.sym;
-	      
-	      
-	      if (key == SDLK_ESCAPE)
-		{
-		  /* Escape key - quit! */
-		  
-		  done = 1;
-		}
-	      else if (key == SDLK_TAB ||
-		       key == SDLK_p)
-		{
-		  /* [TAB] or [P]: Pause! */
-		  
-		  paused = 1;
-		}
-	      
-	      
-	      if (level_start_wait > 0 || demo_mode)
-		{
-		  /* Eat other keys until level start wait has passed,
-		     or if game is in demo mode: */
-		  
-		  key = SDLK_UNKNOWN;
-		}
-	      
-	      
-	      if (key >= SDLK_0 && key <= SDLK_9)
-		{
-		  /* [0]-[9]: Add a new digit: */
-		  
-		  digits[0] = digits[1];
-		  digits[1] = digits[2];
-		  digits[2] = key - SDLK_0;
-		  
-		  tux_pressing = 1;
-		}
-	      else if (key >= SDLK_KP0 && key <= SDLK_KP9)
-		{
-		  /* Keypad [0]-[9]: Add a new digit: */
-		  
-		  digits[0] = digits[1];
-		  digits[1] = digits[2];
-		  digits[2] = key - SDLK_KP0;
-		  
-		  tux_pressing = 1;
-		}
-	      else if (key == SDLK_BACKSPACE ||
-		       key == SDLK_CLEAR ||
-		       key == SDLK_DELETE)
-		{
-		  /* [BKSP]: Clear digits! */
-		  
-		  digits[0] = 0;
-		  digits[1] = 0;
-		  digits[2] = 0;
-		  
-		  tux_pressing = 1;
-		}
-	      else if (key == SDLK_RETURN ||
-		       key == SDLK_KP_ENTER ||
-		       key == SDLK_SPACE)
-		{
-		  /* [ENTER]: Accept digits! */
-		 
-		  doing_answer = 1;
-		}
+	      game_key_event(key);
 	    }
 	  else if (event.type == SDL_MOUSEBUTTONDOWN)
 	    {
-              if (level_start_wait == 0 && !demo_mode && use_keypad)
-	      {
-	        if (event.button.x >=
-	            (screen->w / 2) - (images[IMG_KEYPAD]->w / 2) &&
-                    event.button.x <=
-		    (screen->w / 2) + (images[IMG_KEYPAD]->w / 2) &&
-		    event.button.y >= 
-		    (screen->h / 2) - (images[IMG_KEYPAD]->h / 2) &&
-		    event.button.y <=
-		    (screen->h / 2) + (images[IMG_KEYPAD]->h / 2))
-	        {
-		  kx = (event.button.x -
-		        ((screen->w / 2) - (images[IMG_KEYPAD]->w / 2)));
-		  ky = (event.button.y -
-		        ((screen->h / 2) - (images[IMG_KEYPAD]->h / 2)));
-
-		  tux_pressing = 1;
-
-
-		  if (ky >= (images[IMG_KEYPAD]->h / 4) * 3)
-		  {
-	            /* Bottom row is special (has Enter key) */
-			  
-	            if (kx >= (images[IMG_KEYPAD]->w / 3))
-		    {
-		      /* "Enter" key */
-
-		      doing_answer = 1;
-
-		      tux_pressing = 0;
-		    }
-                    else
-		    {
-		      /* "0" key */
-			    
-		      digits[0] = digits[1];
-		      digits[1] = digits[2];
-		      digits[2] = 0;
-		    }
-		  }
-		  else
-		  {
-	            digits[0] = digits[1];
-		    digits[1] = digits[2];
-		    digits[2] = (((kx / (images[IMG_KEYPAD]->w / 3)) + 1) +
-				 6 - ((ky / (images[IMG_KEYPAD]->h / 4) * 3)));
-		  }
-	        }
-	      }
+              game_mouse_event(event);
 	    }
 	}
 
@@ -342,7 +232,8 @@
 
       if (demo_mode)
       {
-        /* Demo mdoe! */
+        /* Demo mode! */
+        /* FIXME update this to handle negatives correctly */
 
         if (picked_comet == -1 && (rand() % 10) < 3)
         {
@@ -418,8 +309,12 @@
 	num = (digits[0] * 100 +
 	       digits[1] * 10 +
 	       digits[2]);
+	/* negative answer support DSB */
+        if (neg_answer_picked)
+	{
+	  num = -num;
+	}	
 	
-	
 	/*  Pick the lowest comet which has the right answer: */
 	
 	lowest_y = 0;
@@ -511,6 +406,7 @@
 	digits[0] = 0;
 	digits[1] = 0;
 	digits[2] = 0;
+        neg_answer_picked = 0;
       }
 
       
@@ -883,15 +779,27 @@
 
 
       /* Draw numeric keypad: */
-
+      /* TODO should have keypad with grayed-out '+' and '-' when no negatives allowed */
       if (use_keypad)
       {
-        dest.x = (screen->w - images[IMG_KEYPAD]->w) / 2;
-        dest.y = (screen->h - images[IMG_KEYPAD]->h) / 2;
-        dest.w = images[IMG_KEYPAD]->w;
-        dest.h = images[IMG_KEYPAD]->h;
-
-        SDL_BlitSurface(images[IMG_KEYPAD], NULL, screen, &dest);
+        if (allow_neg_answer)
+        /* draw regular keypad */
+        { 
+          dest.x = (screen->w - images[IMG_KEYPAD]->w) / 2;
+          dest.y = (screen->h - images[IMG_KEYPAD]->h) / 2;
+          dest.w = images[IMG_KEYPAD]->w;
+          dest.h = images[IMG_KEYPAD]->h;
+          SDL_BlitSurface(images[IMG_KEYPAD], NULL, screen, &dest);
+        }
+        else
+        /* draw keypad with with grayed-out '+' and '-' */
+        { 
+          dest.x = (screen->w - images[IMG_KEYPAD_NO_NEG]->w) / 2;
+          dest.y = (screen->h - images[IMG_KEYPAD_NO_NEG]->h) / 2;
+          dest.w = images[IMG_KEYPAD_NO_NEG]->w;
+          dest.h = images[IMG_KEYPAD_NO_NEG]->h;
+          SDL_BlitSurface(images[IMG_KEYPAD_NO_NEG], NULL, screen, &dest);
+        } 
       }
 
 
@@ -906,10 +814,14 @@
 
       draw_console_image(tux_img);
 
+      /* LED code moved into separate function by DSB */
+      draw_led_nums();
 
+
       /* Draw LED digits at the top of the screen: */
-      
-      for (i = 0; i < 3; i++)
+      /* TODO add negative sign DSB */ 
+/* 
+     for (i = 0; i < 3; i++)
 	{
 	  src.x = digits[i] * ((images[IMG_LEDNUMS]->w) / 10);
 	  src.y = 0;
@@ -924,8 +836,8 @@
 	  
 	  SDL_BlitSurface(images[IMG_LEDNUMS], &src, screen, &dest);
 	}
+*/
 
-
       /* Draw "Game Over" */
 
       if (gameover > 0)
@@ -1017,8 +929,8 @@
   digits[0] = 0;
   digits[1] = 0;
   digits[2] = 0;
+  neg_answer_picked = 0;
 
-
   /* Load random background image: */
 
   do
@@ -1129,6 +1041,7 @@
 	  }
 	  while (comets[found].answer > max_answer);
 	}
+
       else if (comets[found].oper == OPER_SUB)
 	{
 	  /* Subtraction: */
@@ -1136,21 +1049,22 @@
 	  do
 	  {
 	    comets[found].eq1 = pick_operand(0);
-
-
-	    /* (No negative answers) */
-	    /* [ WILL PROBABLY ALLOW FOR NEG. ANS. ] */
-	  
-	    do
-	    {
-	      comets[found].eq2 = pick_operand(0);
-	    }
-	    while (comets[found].eq2 > comets[found].eq1);
-
+	    comets[found].eq2 = pick_operand(0);
+	    /* try again until answer not negative  */
+	    /* unless neg_answer_allowed DSB */
+	    if (!allow_neg_answer)
+            {
+	      do
+	      {
+	        comets[found].eq2 = pick_operand(0);
+	      }
+	      while (comets[found].eq2 > comets[found].eq1);
+            }
 	    comets[found].answer = comets[found].eq1 - comets[found].eq2;
 	  }
 	  while (comets[found].answer > max_answer);
 	}
+
       else if (comets[found].oper == OPER_MULT)
 	{
 	  /* Multiplication: */
@@ -1159,6 +1073,7 @@
 	  comets[found].eq2 = pick_operand(0);
 	  comets[found].answer = comets[found].eq1 * comets[found].eq2;
 	}
+
       else if (comets[found].oper == OPER_DIV)
 	{
 	  /* Division: */
@@ -1494,8 +1409,282 @@
 
   SDL_BlitSurface(images[i], NULL, screen, &dest);
 }
+/* Draw LED digits at the top of the screen: */
+/* Modified by DSB to display minus sign */
 
+void draw_led_nums(void)
+{
+  int i;
+  SDL_Rect src, dest;
 
+  /* begin drawing so as to center display depending on whether minus */
+  /* sign needed (4 digit slots) or not (3 digit slots) DSB */
+  if (allow_neg_answer)
+    dest.x = ((screen->w - ((images[IMG_LEDNUMS]->w) / 10) * 4) / 2);
+  else
+    dest.x = ((screen->w - ((images[IMG_LEDNUMS]->w) / 10) * 3) / 2);
+
+  for (i = -1; i < 3; i++)  /* -1 is special case to allow minus sign */
+                              /* with minimal modification of existing code DSB */
+  { 
+    if (-1 == i)
+    {
+      if (allow_neg_answer)
+      {
+        if (neg_answer_picked)
+          src.x =  (images[IMG_LED_NEG_SIGN]->w) / 2;
+        else
+          src.x = 0;
+
+        src.y = 0;
+        src.w = (images[IMG_LED_NEG_SIGN]->w) / 2;
+        src.h = images[IMG_LED_NEG_SIGN]->h;
+	  
+        dest.y = 4;
+        dest.w = src.w;
+        dest.h = src.h;
+	  
+        SDL_BlitSurface(images[IMG_LED_NEG_SIGN], &src, screen, &dest);
+        /* move "cursor" */
+        dest.x += src.w;
+      }
+    }
+    else
+    {
+      src.x = digits[i] * ((images[IMG_LEDNUMS]->w) / 10);
+      src.y = 0;
+      src.w = (images[IMG_LEDNUMS]->w) / 10;
+      src.h = images[IMG_LEDNUMS]->h;
+	  
+      /* dest.x already set */
+      dest.y = 4;
+      dest.w = src.w;
+      dest.h = src.h;
+	  
+      SDL_BlitSurface(images[IMG_LEDNUMS], &src, screen, &dest);
+      /* move "cursor" */
+      dest.x += src.w;
+    }
+  }
+}
+
+/* Translates mouse events into keyboard events when on-screen keypad used */
+/* FIXME this code uses IMG_KEYPAD to figure out the mouse events even     */
+/* if IMG_KEYPAD_NO_NEG is actually on the screen. This relies on the two  */
+/* graphics having the same shape and key layout. If this changes in the   */
+/* future, this function will need to be rewritten                         */
+
+void game_mouse_event(SDL_Event the_event)
+{
+  int x, y, row, column;
+  SDLKey keypad_key = SDLK_UNKNOWN;
+
+  /* get out unless we really are using keypad */
+  if ( level_start_wait 
+    || demo_mode
+    || !use_keypad)
+  {
+    return;
+  }
+  /* make sure keypad image is valid and has non-zero dimensions: */
+  if (!images[IMG_KEYPAD])
+  {
+    return;
+  }
+  if (!(images[IMG_KEYPAD]->w)
+    ||!(images[IMG_KEYPAD]->h))
+  {
+    return;
+  }
+
+  /* only proceed if click falls within keypad: */
+  if (!((the_event.button.x >=
+        (screen->w / 2) - (images[IMG_KEYPAD]->w / 2) &&
+        the_event.button.x <=
+        (screen->w / 2) + (images[IMG_KEYPAD]->w / 2) &&
+        the_event.button.y >= 
+        (screen->h / 2) - (images[IMG_KEYPAD]->h / 2) &&
+        the_event.button.y <=
+        (screen->h / 2) + (images[IMG_KEYPAD]->h / 2))))
+  /* click outside of keypad - do nothing */
+  {
+    return;
+  }
+  
+  else /* click was within keypad */ 
+  {
+    x = (the_event.button.x - ((screen->w / 2) - (images[IMG_KEYPAD]->w / 2)));
+    y = (the_event.button.y - ((screen->h / 2) - (images[IMG_KEYPAD]->h / 2)));
+ 
+  /* Now determine what onscreen key was pressed */
+  /*                                             */
+  /* The on-screen keypad has a 4 x 4 layout:    */
+  /*                                             */
+  /*    *********************************        */
+  /*    *       *       *       *       *        */
+  /*    *   7   *   8   *   9   *   -   *        */
+  /*    *       *       *       *       *        */
+  /*    *********************************        */
+  /*    *       *       *       *       *        */
+  /*    *   4   *   5   *   6   *       *        */
+  /*    *       *       *       *       *        */
+  /*    *************************   +   *        */
+  /*    *       *       *       *       *        */
+  /*    *   1   *   2   *   3   *       *        */
+  /*    *       *       *       *       *        */
+  /*    *********************************        */
+  /*    *       *                       *        */
+  /*    *   0   *         Enter         *        */
+  /*    *       *                       *        */
+  /*    *********************************        */
+  /*                                             */
+  /*  The following code simply figures out the  */
+  /*  row and column based on x and y and looks  */
+  /*  up the SDlKey accordingly.                 */
+
+    column = x/((images[IMG_KEYPAD]->w)/4);
+    row    = y/((images[IMG_KEYPAD]->h)/4);
+
+    /* make sure row and column are sane */
+    if (column < 0
+     || column > 3
+     || row    < 0
+     || row    > 3)
+    {
+      printf("\nIllegal row or column value!\n");
+      return;
+    }
+
+    /* simple but tedious - I am sure this could be done more elegantly */
+
+    if (0 == row)
+    {
+      if (0 == column)
+        keypad_key = SDLK_7;
+      if (1 == column)
+        keypad_key = SDLK_8;
+      if (2 == column)
+        keypad_key = SDLK_9;
+      if (3 == column)
+        keypad_key = SDLK_MINUS;
+    } 
+    if (1 == row)
+    {
+      if (0 == column)
+        keypad_key = SDLK_4;
+      if (1 == column)
+        keypad_key = SDLK_5;
+      if (2 == column)
+        keypad_key = SDLK_6;
+      if (3 == column)
+        keypad_key = SDLK_PLUS;
+    }     
+    if (2 == row)
+    {
+      if (0 == column)
+        keypad_key = SDLK_1;
+      if (1 == column)
+        keypad_key = SDLK_2;
+      if (2 == column)
+        keypad_key = SDLK_3;
+      if (3 == column)
+        keypad_key = SDLK_PLUS;
+    } 
+    if (3 == row)
+    {
+      if (0 == column)
+        keypad_key = SDLK_0;
+      if (1 == column)
+        keypad_key = SDLK_RETURN;
+      if (2 == column)
+        keypad_key = SDLK_RETURN;
+      if (3 == column)
+        keypad_key = SDLK_RETURN;
+    }     
+
+    if (keypad_key == SDLK_UNKNOWN)
+    {
+      return;
+    }
+
+    /* now can proceed as if keyboard was used */
+    game_key_event(keypad_key);
+  }
+}
+
+/* called by either key presses or mouse clicks on */
+/* on-screen keypad */
+void game_key_event(SDLKey pressed_key)
+{
+  if (pressed_key == SDLK_ESCAPE)
+  {
+    /* Escape key - quit! */
+   done = 1;
+  }
+  else if (pressed_key == SDLK_TAB
+        || pressed_key == SDLK_p)
+  {
+  /* [TAB] or [P]: Pause! */
+    paused = 1;
+  }
+      
+  if (level_start_wait > 0 || demo_mode)
+  {
+    /* Eat other keys until level start wait has passed,
+    or if game is in demo mode: */
+    pressed_key = SDLK_UNKNOWN;
+  }
+	      
+  if (pressed_key >= SDLK_0 && pressed_key <= SDLK_9)
+  {
+    /* [0]-[9]: Add a new digit: */
+    digits[0] = digits[1];
+    digits[1] = digits[2];
+    digits[2] = pressed_key - SDLK_0;
+    tux_pressing = 1;
+  }
+  else if (pressed_key >= SDLK_KP0 && pressed_key <= SDLK_KP9)
+  {
+    /* Keypad [0]-[9]: Add a new digit: */
+    digits[0] = digits[1];
+    digits[1] = digits[2];
+    digits[2] = pressed_key - SDLK_KP0;
+    tux_pressing = 1;
+  }
+  /* support for negative answer input DSB */
+  else if ((pressed_key == SDLK_MINUS || pressed_key == SDLK_KP_MINUS)
+        && allow_neg_answer)  /* do nothing unless neg answers allowed */
+  {
+    /* allow player to make answer negative: */
+    neg_answer_picked = 1;
+    tux_pressing = 1;
+  }
+  else if ((pressed_key == SDLK_PLUS || pressed_key == SDLK_KP_PLUS)
+         && allow_neg_answer)  /* do nothing unless neg answers allowed */
+  {
+    /* allow player to make answer positive: */
+    neg_answer_picked = 0;
+    tux_pressing = 1;
+  }
+  else if (pressed_key == SDLK_BACKSPACE ||
+           pressed_key == SDLK_CLEAR ||
+	   pressed_key == SDLK_DELETE)
+  {
+    /* [BKSP]: Clear digits! */
+    digits[0] = 0;
+    digits[1] = 0;
+    digits[2] = 0;
+    tux_pressing = 1;
+  }
+  else if (pressed_key == SDLK_RETURN ||
+           pressed_key == SDLK_KP_ENTER ||
+	   pressed_key == SDLK_SPACE)
+  {
+    /* [ENTER]: Accept digits! */
+    doing_answer = 1;
+  }
+}
+
 /* Increment score: */
 
 void add_score(int inc)

Modified: tuxmath/trunk/src/images.h
===================================================================
--- tuxmath/trunk/src/images.h	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/images.h	2006-03-01 17:19:00 UTC (rev 8)
@@ -90,10 +90,12 @@
   COMET_EXPL_START = IMG_COMETEX1,
   IMG_NUMS,
   IMG_LEDNUMS,
+  IMG_LED_NEG_SIGN,
   IMG_PAUSED,
   IMG_DEMO,
   IMG_DEMO_SMALL,
   IMG_KEYPAD,
+  IMG_KEYPAD_NO_NEG,
   IMG_CONSOLE,
   IMG_TUX_CONSOLE1,
   IMG_TUX_CONSOLE2,

Modified: tuxmath/trunk/src/options.c
===================================================================
--- tuxmath/trunk/src/options.c	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/options.c	2006-03-01 17:19:00 UTC (rev 8)
@@ -154,6 +154,7 @@
 
 	  else if (event.type == SDL_MOUSEBUTTONDOWN)
             {
+              /* FIXME Options screen should have "OK" button to accept choices with mouse DSB */
               /* figure out opt based on mouse coordinates */
               if (/* event.button.x >= left && */ /* don't see any reason to filter on x values here*/
 	          /* event.button.x <= left + width && */  
@@ -214,14 +215,14 @@
 		    playsound(SND_POP);
 		  }
 		}
+	      else if (key == SDLK_RETURN ||
+		       key == SDLK_KP_ENTER ||
+		       key == SDLK_SPACE)
+              {
               /* code moved into function taking opt as argument so the same code can be   */
               /* used to handle mouse events DSB */
-	      else if (key == SDLK_RETURN)
-              {
                 update_selected_option(opt);
               }
-/*	      else if (key == SDLK_RETURN) */
-
 	    }
 	}
       

Modified: tuxmath/trunk/src/setup.c
===================================================================
--- tuxmath/trunk/src/setup.c	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/setup.c	2006-03-01 17:19:00 UTC (rev 8)
@@ -104,10 +104,12 @@
   DATA_PREFIX "/images/comets/cometex1.png",
   DATA_PREFIX "/images/status/nums.png",
   DATA_PREFIX "/images/status/lednums.png",
+  DATA_PREFIX "/images/status/led_neg_sign.png",
   DATA_PREFIX "/images/status/paused.png",
   DATA_PREFIX "/images/status/demo.png",
   DATA_PREFIX "/images/status/demo-small.png",
   DATA_PREFIX "/images/status/keypad.png",
+  DATA_PREFIX "/images/status/keypad_no_neg.png",
   DATA_PREFIX "/images/tux/console.png",
   DATA_PREFIX "/images/tux/tux-console1.png",
   DATA_PREFIX "/images/tux/tux-console2.png",
@@ -156,7 +158,8 @@
 Mix_Chunk * sounds[NUM_SOUNDS];
 Mix_Music * musics[NUM_MUSICS];
 #endif
-int use_sound, fullscreen, use_bkgd, demo_mode, oper_override, use_keypad;
+int use_sound, fullscreen, use_bkgd, demo_mode,
+    oper_override, use_keypad, allow_neg_answer;
 float speed;
 int opers[NUM_OPERS], range_enabled[NUM_Q_RANGES];
 int max_answer;
@@ -175,6 +178,7 @@
   int i, j, found, total_files;
   SDL_Rect dest;
 
+  screen = NULL;
 
   /* Set default options: */
 
@@ -186,18 +190,19 @@
   speed = 1.0;
   oper_override = 0;
   max_answer = 144;
+  allow_neg_answer = 0;
 
+
   for (i = 0; i < NUM_OPERS; i++)
   {
     opers[i] = 1;
   }
 
   for (i = 0; i < NUM_Q_RANGES; i++)
-  {
+  { 
     range_enabled[i] = 1;
   }
 
-
   /* FIXME: Program should load options from disk */
 
 
@@ -240,15 +245,16 @@
 	"When you lose all of your cities, the game ends.\n\n");
 
       printf("Run the game with:\n"
-        "--nosound      - to disable sound/music\n"
-	"--nobackground - to disable background photos (for slower systems)\n"
-	"--fullscreen   - to run in fullscreen, if possible (vs. windowed)\n"
-        "--keypad       - to enable the on-sceen numeric keypad\n"
-	"--demo         - to run the program as a cycling demonstration\n"
-	"--speed S      - set initial speed of the game\n"
-	"                 (S may be fractional, default is 1.0)\n"
-	"--operator OP  - to automatically play with particular operators\n"
-	"                 OP may be one of:\n");
+        "--nosound        - to disable sound/music\n"
+	"--nobackground   - to disable background photos (for slower systems)\n"
+	"--fullscreen     - to run in fullscreen, if possible (vs. windowed)\n"
+        "--keypad         - to enable the on-sceen numeric keypad\n"
+	"--demo           - to run the program as a cycling demonstration\n"
+	"--speed S        - set initial speed of the game\n"
+	"                   (S may be fractional, default is 1.0)\n"
+        "--allownegatives - to allow answers to be less than zero\n"
+	"--operator OP    - to automatically play with particular operators\n"
+	"                   OP may be one of:\n");
 
       for (j = 0; j < NUM_OPERS; j++)
         printf("                   \"%s\"\n", oper_opts[j]);
@@ -320,6 +326,11 @@
     {
       use_keypad = 1;
     }
+    else if (strcmp(argv[i], "--allownegatives") == 0 ||
+             strcmp(argv[i], "-n") == 0)
+    {
+      allow_neg_answer = 1;
+    }
     else if (strcmp(argv[i], "--speed") == 0 ||
 	     strcmp(argv[i], "-s") == 0)
     {
@@ -386,7 +397,7 @@
 
   
   /* Init SDL Video: */
-  
+
   if (SDL_Init(SDL_INIT_VIDEO) < 0)
     {
       fprintf(stderr,
@@ -396,10 +407,10 @@
       exit(1);
     }
   
-  
   /* Init SDL Audio: */
 
 #ifndef NOSOUND
+
   if (use_sound)
     { 
       if (SDL_Init(SDL_INIT_AUDIO) < 0)
@@ -424,9 +435,10 @@
           use_sound = 0;
         }
     }
+
 #endif
   
- 
+
   if (fullscreen)
   {
     screen = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN | SDL_HWSURFACE);
@@ -442,7 +454,9 @@
   }
 
   if (!fullscreen)
+  {
     screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE);
+  }
 
   if (screen == NULL)
   {
@@ -452,8 +466,9 @@
 	    "%s\n\n", SDL_GetError());
     exit(1);
   }
-  
+
   seticon();
+
   SDL_WM_SetCaption("Tux, of Math Command", "TuxMath");
 
 
@@ -464,7 +479,6 @@
   
 
   /* Load images: */
-
   for (i = 0; i < NUM_IMAGES; i++)
   {
     images[i] = IMG_Load(image_filenames[i]);
@@ -520,7 +534,6 @@
     SDL_Flip(screen);
   }
 
-
 #ifndef NOSOUND
   if (use_sound)
   {
@@ -645,7 +658,6 @@
   else
     f = stderr;
 
-
   fprintf(f,
    "\nUsage: %s {--help | --usage | --copyright}\n"
    "       %s [--fullscreen] [--nosound] [--nobackground] [--demo] [--keypad]\n"

Modified: tuxmath/trunk/src/setup.h
===================================================================
--- tuxmath/trunk/src/setup.h	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/setup.h	2006-03-01 17:19:00 UTC (rev 8)
@@ -34,7 +34,7 @@
 extern Mix_Music * musics[];
 #endif
 extern int use_sound, fullscreen, use_bkgd, demo_mode, oper_override,
-  use_keypad;
+  use_keypad, allow_neg_answer;
 extern float speed;
 extern int opers[NUM_OPERS], range_enabled[NUM_Q_RANGES];
 extern int max_answer;

Modified: tuxmath/trunk/src/title.c
===================================================================
--- tuxmath/trunk/src/title.c	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/title.c	2006-03-01 17:19:00 UTC (rev 8)
@@ -150,7 +150,7 @@
       
       
       /* Handle any incoming events: */
-      
+       
       while (SDL_PollEvent(&event) > 0)
 	{
 	  if (event.type == SDL_QUIT)
@@ -189,7 +189,7 @@
 		  if (cmd < 0)
 		    cmd = 0;
 		}
-	      else if (key == SDLK_RETURN)
+	      else if (key == SDLK_RETURN || SDLK_KP_ENTER)
 		{
 		  done = 1;
 		}
@@ -211,6 +211,7 @@
 	    }
 	  }
 	}
+           
       
       
       /* Erase Tux (cursor) */
@@ -219,9 +220,7 @@
 	{
 	  blinking = 0;
 	  
-	  
 	  dest.x = left + 4;
-	  // dest.x = 32;
 	  dest.y = (images[IMG_TITLE]->h + 8 + 
 		    (old_cmd * images[IMG_TUX_HELMET1]->h));
 	  dest.w = images[IMG_TUX_HELMET1]->w;
@@ -247,7 +246,6 @@
       
       /* Draw Tux (cursor) */
       
-      // dest.x = 32;
       dest.x = left + 4;
       dest.y = images[IMG_TITLE]->h + 8 + (cmd * images[IMG_TUX_HELMET1]->h);
       dest.w = images[IMG_TUX_HELMET1]->w;

Modified: tuxmath/trunk/src/tuxmath.c
===================================================================
--- tuxmath/trunk/src/tuxmath.c	2006-02-18 18:19:33 UTC (rev 7)
+++ tuxmath/trunk/src/tuxmath.c	2006-03-01 17:19:00 UTC (rev 8)
@@ -29,7 +29,6 @@
 {
   int cmd, done;
 
-
   setup(argc, argv);
   
   done = 0;




More information about the Tux4kids-commits mailing list