···28282929#define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168 iRiver: 240 */
3030#define SPEEDY LCD_HEIGHT * 2 /* Recorder: 128 iRiver: 256 */
3131+#define CPU_PLAYER_DIST ( (LCD_WIDTH/8 ) * 5 ) /* This is the width of the dead spot where the */
3232+#define DEM_PLAYER_DIST ( (LCD_WIDTH/8 ) * 3 ) /* cpu player doesnt care about the ball -- 3/8 of the screen */
31333234#define RES 100
3335···263265 int e_pad[2]; /* existing current Y positions of pads */
264266 int ballspeedx; /* */
265267 int ballspeedy; /* */
266266-267268 int score[2];
269269+ bool cpu_player[2]; /* Status of AI players */
268270};
269271270272void singlepad(int x, int y, int set)
···298300 the wall */
299301 if(pad) {
300302 /* right-side */
301301- if(p->ballx > LCD_WIDTH*RES)
303303+ if(p->ballx > ( LCD_WIDTH*RES ) - PAD_WIDTH )
302304 return true;
303305 }
304306 else {
305305- if(p->ballx < 0)
307307+ if(p->ballx < PAD_WIDTH)
306308 return true;
307309 }
308310 return false;
···346348347349void bounce(struct pong *p, int pad, int info)
348350{
349349- (void)pad; /* not used right now */
350351 p->ballspeedx = -p->ballspeedx;
351352353353+ if(pad==0) { /* Give ball a little push to keep it from getting stuck between wall and pad */
354354+ p->ballx += PAD_WIDTH;
355355+ }
356356+ else {
357357+ p->ballx -= PAD_WIDTH;
358358+ }
359359+352360 /* info is the hit-angle into the pad */
353361 if(p->ballspeedy > 0) {
354362 /* downwards */
···522530523531 key = rb->button_status(); /* ignore BUTTON_REPEAT */
524532525525- if(key & PONG_LEFT_DOWN) /* player left goes down */
526526- padmove(&p->w_pad[0], MOVE_STEP);
533533+ if(p->cpu_player[1] == true) {
534534+ if( (p->bally/RES > p->w_pad[0])
535535+ & (p->ballx/RES < DEM_PLAYER_DIST) ) /* player right goes down */
536536+ padmove(&p->w_pad[0], MOVE_STEP);
527537528528- if(key & PONG_LEFT_UP) /* player left goes up */
529529- padmove(&p->w_pad[0], -MOVE_STEP);
538538+ if( (p->bally/RES < p->w_pad[0])
539539+ & (p->ballx/RES < DEM_PLAYER_DIST) ) /* player right goes up */
540540+ padmove(&p->w_pad[0], -MOVE_STEP);
530541531531- if(key & PONG_RIGHT_DOWN) /* player right goes down */
532532- padmove(&p->w_pad[1], MOVE_STEP);
542542+ if( (key & PONG_LEFT_DOWN) || (key & PONG_LEFT_UP) ) {
543543+ /* if left player presses control keys stop cpu player */
544544+ p->cpu_player[1] = false;
545545+ p->score[0] = p->score[1] = 0; /* reset the score */
546546+ rb->lcd_clear_display(); /* get rid of the text */
547547+ }
548548+ }
549549+ else {
550550+ if(key & PONG_LEFT_DOWN) /* player left goes down */
551551+ padmove(&p->w_pad[0], MOVE_STEP);
552552+553553+ if(key & PONG_LEFT_UP) /* player left goes up */
554554+ padmove(&p->w_pad[0], -MOVE_STEP);
555555+ }
556556+557557+ if(p->cpu_player[2] == true) {
558558+ if( (p->bally/RES > p->w_pad[1])
559559+ & (p->ballx/RES > CPU_PLAYER_DIST) ) /* player right goes down */
560560+ padmove(&p->w_pad[1], MOVE_STEP);
561561+562562+ if( (p->bally/RES < p->w_pad[1])
563563+ & (p->ballx/RES > CPU_PLAYER_DIST) ) /* player right goes up */
564564+ padmove(&p->w_pad[1], -MOVE_STEP);
565565+566566+ if( (key & PONG_RIGHT_DOWN) || (key & PONG_RIGHT_UP) ) {
567567+ /* if right player presses control keys stop cpu player */
568568+ p->cpu_player[2] = false;
569569+ p->score[0] = p->score[1] = 0; /* reset the score */
570570+ rb->lcd_clear_display(); /* get rid of the text */
571571+ }
572572+ }
573573+ else {
574574+ if(key & PONG_RIGHT_DOWN) /* player right goes down */
575575+ padmove(&p->w_pad[1], MOVE_STEP);
533576534534- if(key & PONG_RIGHT_UP) /* player right goes up */
535535- padmove(&p->w_pad[1], -MOVE_STEP);
577577+ if(key & PONG_RIGHT_UP) /* player right goes up */
578578+ padmove(&p->w_pad[1], -MOVE_STEP);
579579+ }
536580537581 if(rb->default_event_handler(key) == SYS_USB_CONNECTED)
538582 return -1; /* exit game because of USB */
···550594 rb->lcd_putsxy( (LCD_WIDTH / 2) - (w / 2), 0, (unsigned char *)buffer);
551595}
552596597597+void blink_demo(void)
598598+{
599599+ static char buffer[30];
600600+ int w;
601601+602602+ rb->snprintf(buffer, sizeof(buffer), "Press Key To Play");
603603+ w = rb->lcd_getstringsize((unsigned char *)buffer, NULL, NULL);
604604+ if(LCD_WIDTH > ( (w/8)*7 ) ) /* make sure text isn't too long for screen */
605605+ rb->lcd_putsxy( (LCD_WIDTH / 2) - (w / 2), (LCD_HEIGHT / 2),
606606+ (unsigned char *)buffer);
607607+}
608608+553609/* this is the plugin entry point */
554610enum plugin_status plugin_start(const void* parameter)
555611{
556612 struct pong pong;
557613 int game = 1;
558614615615+ int blink_timer = 0;
616616+ int blink_rate = 20;
617617+ bool blink = true;
618618+559619 /* init the struct with some silly values to start with */
560620561621 pong.ballx = 20*RES;
···565625 pong.w_pad[0] = 7;
566626 pong.e_pad[1] = 0;
567627 pong.w_pad[1] = 40;
628628+ pong.cpu_player[1] = pong.cpu_player[2] = true; /* start every game in demo mode */
568629569630 pong.ballspeedx = SPEEDX;
570631 pong.ballspeedy = SPEEDY;
···586647 game = keys(&pong); /* short circuit */
587648 rb->lcd_clear_display();
588649 }
650650+651651+ if( (pong.cpu_player[1]==true) && (pong.cpu_player[2]==true) ) {
652652+ if(blink_timer<blink_rate) {
653653+ ++blink_timer;
654654+ }
655655+ else {
656656+ blink_timer=0;
657657+ blink = !blink;
658658+ }
659659+660660+ if(blink==true) {
661661+ blink_demo();
662662+ }
663663+ else {
664664+ rb->lcd_clear_display();
665665+ }
666666+ }
667667+589668 showscore(&pong);
590669 pad(&pong, 0); /* draw left pad */
591670 pad(&pong, 1); /* draw right pad */
+7-1
manual/plugins/pong.tex
···11\subsection{Pong}
22\screenshot{plugins/images/ss-pong}{Pong}{img:pong}
33-Pong is a simple two player ``tennis game''. Whenever a player misses the ball the other scores.
33+Pong is a simple one or two player ``tennis game''. Whenever a player misses the ball the other scores.
44+55+The game starts in demo mode, with the CPU controlling both sides.
66+77+As soon as a button to control one of the paddles is pressed, control of that paddle passes to the player,
88+so for a single player game, just press the appropriate buttons to control the side you want to play. For
99+a two player game, both players should just press the appropriate buttons for their side.
410511\begin{btnmap}
612 \opt{RECORDER_PAD}{\ButtonFOne}