http://ftp.ksu.edu.tw/FTP/FreeBSD/distfiles/xscreensaver-4.20.tar.gz
[xscreensaver] / hacks / pong.c
index eab2281122d3693c83021abedf5d5be9ec10c2b1..3820dc7b5a00ca9255f23b65c8ee97894022a057 100644 (file)
@@ -1,6 +1,13 @@
 /* pong, Copyright (c) 2003 Jeremy English <jenglish@myself.com>
  * A pong screen saver
  *
+ * Modified by Brian Sawicki <sawicki@imsa.edu> to fix a small bug.
+ * Before this fix after a certain point the paddles would be too
+ * small for the program to effectively hit the ball.  The score would
+ * then skyrocket as the paddles missed most every time. Added a max
+ * so that once a paddle gets 10 the entire game restarts.  Special
+ * thanks to Scott Zager for some help on this.
+ *
  * Modified by Trevor Blackwell <tlb@tlb.org> to use analogtv.[ch] display.
  * Also added gradual acceleration of the ball, shrinking of paddles, and
  * scorekeeping.
@@ -54,7 +61,6 @@ typedef struct _ball {
   int h;
 } Ball;
 
-static int delay;
 Paddle l_paddle;
 Paddle r_paddle;
 Ball ball;
@@ -88,6 +94,27 @@ hit_top_bottom(void)
     by=-by;
 }
 
+void
+new_game(void)
+{
+  /* Starts a Whole New Game*/
+  ball.x = PONG_W/2;
+  ball.y = PONG_H/2;
+  bx = m_unit;
+  by = m_unit;
+
+  l_paddle.wait = 1;
+  l_paddle.lock = 0;
+  r_paddle.wait = 0;
+  r_paddle.lock = 0;
+  paddle_rate = m_unit-1;
+  r_paddle.score = 0;
+  l_paddle.score = 0;
+
+  l_paddle.h = PONG_H/4;
+  r_paddle.h = PONG_H/4;
+}
+
 void
 start_game(void)
 {
@@ -125,6 +152,9 @@ hit_paddle(void)
       else
         {
           r_paddle.score++;
+          if (r_paddle.score >=10)
+                new_game();
+          else 
           start_game();
         }
     }
@@ -144,6 +174,9 @@ hit_paddle(void)
       else
         {
           l_paddle.score++;
+          if (l_paddle.score >= 10)
+                new_game();
+          else
           start_game();
         }
     }
@@ -255,9 +288,6 @@ init_pong (Display *dpy, Window window)
   }
 #endif
 
-  delay = get_integer_resource ("delay", "Integer");
-  if (delay < 0) delay = 0;
-
   /*Init the paddles*/
   l_paddle.x = 8;
   l_paddle.y = 100;
@@ -480,7 +510,6 @@ char *progclass = "pong";
 char *defaults [] = {
   ".background: black",
   ".foreground: white",
-  "*delay:     10000",
   "*speed:      6",
   ANALOGTV_DEFAULTS
   "*TVContrast:      150",
@@ -488,7 +517,6 @@ char *defaults [] = {
 };
 
 XrmOptionDescRec options [] = {
-  { "-delay",          ".delay",       XrmoptionSepArg, 0 },
   { "-percent",         ".percent",     XrmoptionSepArg, 0 },
   { "-speed",           ".speed",     XrmoptionSepArg, 0 },
   ANALOGTV_OPTIONS