Index: apps/plugins/pong.c
===================================================================
RCS file: /cvsroot/rockbox/apps/plugins/pong.c,v
retrieving revision 1.21
diff -u -r1.21 pong.c
--- apps/plugins/pong.c	26 Oct 2006 13:38:00 -0000	1.21
+++ apps/plugins/pong.c	8 Nov 2006 22:51:16 -0000
@@ -30,6 +30,8 @@
 
 #define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168  iRiver: 240 */
 #define SPEEDY LCD_HEIGHT * 2        /* Recorder: 128  iRiver: 256 */
+#define CPU_PLAYER_DIST ( (LCD_WIDTH/8 ) * 5 ) /*        This is the width of the dead spot where the         */
+#define DEM_PLAYER_DIST ( (LCD_WIDTH/8 ) * 3 ) /* cpu player doesnt care about the ball -- 3/8 of the screen  */
 
 #define RES 100
 
@@ -117,6 +119,7 @@
     int e_pad[2]; /* existing current Y positions of pads */
     int ballspeedx; /*  */
     int ballspeedy; /*  */
+    bool cpu_player[2];
 
     int score[2];
 };
@@ -153,11 +156,11 @@
        the wall */
     if(pad) {
         /* right-side */
-        if(p->ballx > LCD_WIDTH*RES)
+        if(p->ballx > ( LCD_WIDTH*RES ) - PAD_WIDTH )
             return true;
     }
     else {
-        if(p->ballx < 0)
+        if(p->ballx < PAD_WIDTH)
             return true;
     }
     return false;
@@ -201,8 +204,14 @@
 
 void bounce(struct pong *p, int pad, int info)
 {
-    (void)pad; /* not used right now */
+
     p->ballspeedx = -p->ballspeedx;
+    
+    if(pad==0){      /* Give ball a little push to keep it from getting stuck between wall and pad */
+    	p->ballx += PAD_WIDTH;
+    }else{
+    	p->ballx -= PAD_WIDTH;
+    }
 
     /* info is the hit-angle into the pad */
     if(p->ballspeedy > 0) {
@@ -269,6 +278,7 @@
     int info;
 
     /* movement */
+  
     p->ballx += p->ballspeedx;
     p->bally += p->ballspeedy;
 
@@ -354,18 +364,55 @@
 #endif
 
         key = rb->button_status(); /* ignore BUTTON_REPEAT */
-
-        if(key & PONG_LEFT_DOWN) /* player left goes down */
+				
+				if(p->cpu_player[1] == true){
+					
+				if( (p->bally/RES > p->w_pad[0]) & (p->ballx/RES < DEM_PLAYER_DIST) ) /* player right goes down */
             padmove(&p->w_pad[0], MOVE_STEP);
 
-        if(key & PONG_LEFT_UP)   /* player left goes up */
+        if( (p->bally/RES < p->w_pad[0]) & (p->ballx/RES < DEM_PLAYER_DIST) )   /* player right goes up */
             padmove(&p->w_pad[0], -MOVE_STEP);
+					
+				if( (key & PONG_LEFT_DOWN) || (key & PONG_LEFT_UP) ){	/* if left player presses control keys stop cpu player */
+						p->cpu_player[1] = false;
+						p->score[0] = p->score[1] = 0; /* reset the score */
+						rb->lcd_clear_display(); /* get rid of the text */
+					};
+					
+				}else{	
+										
+					if(key & PONG_LEFT_DOWN) /* player left goes down */
+        	    padmove(&p->w_pad[0], MOVE_STEP);
+
+        	if(key & PONG_LEFT_UP)   /* player left goes up */
+            	padmove(&p->w_pad[0], -MOVE_STEP);	
+            	
+				}		
+       
+
+				if(p->cpu_player[2] == true){
+					
+					if( (p->bally/RES > p->w_pad[1]) & (p->ballx/RES > CPU_PLAYER_DIST) ) /* player right goes down */
+            	padmove(&p->w_pad[1], MOVE_STEP);
+
+        	if( (p->bally/RES < p->w_pad[1]) & (p->ballx/RES > CPU_PLAYER_DIST) )   /* player right goes up */
+            	padmove(&p->w_pad[1], -MOVE_STEP);
+					
+					if( (key & PONG_RIGHT_DOWN) || (key & PONG_RIGHT_UP) ){	/* if right player presses control keys stop cpu player */
+							p->cpu_player[2] = false;
+							p->score[0] = p->score[1] = 0; /* reset the score */
+							rb->lcd_clear_display(); /* get rid of the text */
+						};
+					
+				}else{
+				
+        	if(key & PONG_RIGHT_DOWN) /* player right goes down */
+            	padmove(&p->w_pad[1], MOVE_STEP);
 
-        if(key & PONG_RIGHT_DOWN) /* player right goes down */
-            padmove(&p->w_pad[1], MOVE_STEP);
-
-        if(key & PONG_RIGHT_UP)   /* player right goes up */
-            padmove(&p->w_pad[1], -MOVE_STEP);
+        	if(key & PONG_RIGHT_UP)   /* player right goes up */
+            	padmove(&p->w_pad[1], -MOVE_STEP);
+        
+        };
         
         if(rb->default_event_handler(key) == SYS_USB_CONNECTED)
             return -1; /* exit game because of USB */
@@ -383,11 +430,26 @@
     rb->lcd_putsxy( (LCD_WIDTH / 2) - (w / 2), 0, (unsigned char *)buffer);
 }
 
+void blink_demo()
+{
+    static char buffer[30];
+    int w;
+    
+    rb->snprintf(buffer, sizeof(buffer), "Press Key To Play");
+    w = rb->lcd_getstringsize((unsigned char *)buffer, NULL, NULL);    
+    if(LCD_WIDTH > ( (w/8)*7 ) ) /* make sure text isn't too long for screen */
+   		rb->lcd_putsxy( (LCD_WIDTH / 2) - (w / 2), (LCD_HEIGHT / 2), (unsigned char *)buffer);
+}
+
 /* this is the plugin entry point */
 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
 {
     struct pong pong;
     int game = 1;
+    
+    int b_timer = 0;
+    int b_rate = 20;
+    bool blink = true;
 
     /* init the struct with some silly values to start with */
 
@@ -398,6 +460,7 @@
     pong.w_pad[0] = 7;
     pong.e_pad[1] = 0;
     pong.w_pad[1] = 40;
+    pong.cpu_player[1] = pong.cpu_player[2] = true;  /* start every game in demo mode */
 
     pong.ballspeedx = SPEEDX;
     pong.ballspeedy = SPEEDY;
@@ -410,9 +473,14 @@
   
     rb = api; /* use the "standard" rb pointer */
 
+#ifdef HAVE_LCD_COLOR
+   			rb->lcd_set_background(LCD_RGBPACK(0, 0, 0));
+    		rb->lcd_set_foreground(LCD_RGBPACK(128, 255, 0));
+#endif
+
     /* Clear screen */
     rb->lcd_clear_display();
-
+    
     /* go go go */
     while(game > 0) {
         if (game == 2) { /* Game Paused */
@@ -421,6 +489,31 @@
                 game = keys(&pong); /* short circuit */
             rb->lcd_clear_display();
         }
+        
+        if( (pong.cpu_player[1]==true) && (pong.cpu_player[2]==true) ){
+        	
+        		if(b_timer<b_rate){
+        			++b_timer;
+        		}else{
+        			b_timer=0;
+        			
+        			if(blink==true){  /* I'm sure there's a better way to flip a bool.. */
+        				blink=false;
+        			}else{
+        				blink=true;
+        			}
+        				
+        			
+        		}
+        		
+        		if(blink==true){
+        			blink_demo();
+        		}else{
+        			rb->lcd_clear_display();
+        		}
+        	
+        	}
+        
         showscore(&pong);
         pad(&pong, 0); /* draw left pad */
         pad(&pong, 1); /* draw right pad */
