1
0
Fork 0
forked from len0rd/rockbox

Pong! * adapt to FS#4761 * add pause button for non-holdswitch players *

better gameplay (no wait for BUTTON_REPEAT) * a few bugfixes * H300 new keypad
(should credit & close 2822)


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10472 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Shachar Liberman 2006-08-07 17:08:48 +00:00
parent d55503d80b
commit 8921b34e4b

View file

@ -25,7 +25,7 @@ PLUGIN_HEADER
#define PAD_HEIGHT LCD_HEIGHT / 6 /* Recorder: 10 iRiver: 21 */ #define PAD_HEIGHT LCD_HEIGHT / 6 /* Recorder: 10 iRiver: 21 */
#define PAD_WIDTH LCD_WIDTH / 50 /* Recorder: 2 iRiver: 2 */ #define PAD_WIDTH LCD_WIDTH / 50 /* Recorder: 2 iRiver: 2 */
#define BALL_HEIGTH LCD_HEIGHT / 32 /* Recorder: 2 iRiver: 4 */ #define BALL_HEIGHT LCD_HEIGHT / 32 /* Recorder: 2 iRiver: 4 */
#define BALL_WIDTH LCD_HEIGHT / 32 /* We want a square ball */ #define BALL_WIDTH LCD_HEIGHT / 32 /* We want a square ball */
#define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168 iRiver: 240 */ #define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168 iRiver: 240 */
@ -38,6 +38,7 @@ PLUGIN_HEADER
/* variable button definitions */ /* variable button definitions */
#if CONFIG_KEYPAD == RECORDER_PAD #if CONFIG_KEYPAD == RECORDER_PAD
#define PONG_QUIT BUTTON_OFF #define PONG_QUIT BUTTON_OFF
#define PONG_PAUSE BUTTON_ON
#define PONG_LEFT_UP BUTTON_F1 #define PONG_LEFT_UP BUTTON_F1
#define PONG_LEFT_DOWN BUTTON_LEFT #define PONG_LEFT_DOWN BUTTON_LEFT
#define PONG_RIGHT_UP BUTTON_F3 #define PONG_RIGHT_UP BUTTON_F3
@ -45,13 +46,13 @@ PLUGIN_HEADER
#elif CONFIG_KEYPAD == ONDIO_PAD #elif CONFIG_KEYPAD == ONDIO_PAD
#define PONG_QUIT BUTTON_OFF #define PONG_QUIT BUTTON_OFF
#define PONG_PAUSE BUTTON_RIGHT
#define PONG_LEFT_UP BUTTON_LEFT #define PONG_LEFT_UP BUTTON_LEFT
#define PONG_LEFT_DOWN BUTTON_MENU #define PONG_LEFT_DOWN BUTTON_MENU
#define PONG_RIGHT_UP BUTTON_UP #define PONG_RIGHT_UP BUTTON_UP
#define PONG_RIGHT_DOWN BUTTON_DOWN #define PONG_RIGHT_DOWN BUTTON_DOWN
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ #elif CONFIG_KEYPAD == IRIVER_H100_PAD
(CONFIG_KEYPAD == IRIVER_H300_PAD)
#define PONG_QUIT BUTTON_OFF #define PONG_QUIT BUTTON_OFF
#define PONG_LEFT_UP BUTTON_UP #define PONG_LEFT_UP BUTTON_UP
#define PONG_LEFT_DOWN BUTTON_DOWN #define PONG_LEFT_DOWN BUTTON_DOWN
@ -59,6 +60,14 @@ PLUGIN_HEADER
#define PONG_RIGHT_DOWN BUTTON_MODE #define PONG_RIGHT_DOWN BUTTON_MODE
#define PONG_RC_QUIT BUTTON_RC_STOP #define PONG_RC_QUIT BUTTON_RC_STOP
#elif CONFIG_KEYPAD == IRIVER_H300_PAD
#define PONG_QUIT BUTTON_OFF
#define PONG_LEFT_UP BUTTON_UP
#define PONG_LEFT_DOWN BUTTON_DOWN
#define PONG_RIGHT_UP BUTTON_REC
#define PONG_RIGHT_DOWN BUTTON_MODE
#define PONG_RC_QUIT BUTTON_RC_STOP
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
(CONFIG_KEYPAD == IPOD_3G_PAD) (CONFIG_KEYPAD == IPOD_3G_PAD)
#define PONG_QUIT BUTTON_SELECT #define PONG_QUIT BUTTON_SELECT
@ -76,6 +85,7 @@ PLUGIN_HEADER
#elif (CONFIG_KEYPAD == GIGABEAT_PAD) #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
#define PONG_QUIT BUTTON_A #define PONG_QUIT BUTTON_A
#define PONG_PAUSE BUTTON_MENU
#define PONG_LEFT_UP BUTTON_UP #define PONG_LEFT_UP BUTTON_UP
#define PONG_LEFT_DOWN BUTTON_DOWN #define PONG_LEFT_DOWN BUTTON_DOWN
#define PONG_RIGHT_UP BUTTON_POWER #define PONG_RIGHT_UP BUTTON_POWER
@ -154,7 +164,7 @@ bool padcollide(struct pong *p, int pad, int *info)
int y = p->bally/RES; int y = p->bally/RES;
if((y < (p->e_pad[pad]+PAD_HEIGHT)) && if((y < (p->e_pad[pad]+PAD_HEIGHT)) &&
(y + BALL_HEIGTH > p->e_pad[pad])) { (y + BALL_HEIGHT > p->e_pad[pad])) {
/* Y seems likely right */ /* Y seems likely right */
/* store the delta between ball-middle MINUS pad-middle, so /* store the delta between ball-middle MINUS pad-middle, so
@ -166,15 +176,15 @@ bool padcollide(struct pong *p, int pad, int *info)
max number is +- PAD_HEIGHT/2 max number is +- PAD_HEIGHT/2
*/ */
*info = (y+BALL_HEIGTH/2) - (p->e_pad[pad] + PAD_HEIGHT/2); *info = (y+BALL_HEIGHT/2) - (p->e_pad[pad] + PAD_HEIGHT/2);
if(pad) { if(pad) {
/* right-side */ /* right-side */
if((x + BALL_WIDTH) > (LCD_WIDTH - PAD_WIDTH)) if((x + BALL_WIDTH) >= (LCD_WIDTH - PAD_WIDTH))
return true; /* phump */ return true; /* phump */
} }
else { else {
if(x <= 0) if(x <= PAD_WIDTH)
return true; return true;
} }
} }
@ -225,8 +235,12 @@ void score(struct pong *p, int pad)
/* then move the X-speed of the ball and give it a random Y position */ /* then move the X-speed of the ball and give it a random Y position */
p->ballspeedx = -p->ballspeedx; p->ballspeedx = -p->ballspeedx;
p->bally = rb->rand()%(LCD_HEIGHT-BALL_HEIGTH); p->bally = rb->rand()%(LCD_HEIGHT*RES - BALL_HEIGHT);
/* avoid hitting the pad with the new ball */
p->ballx = (p->ballx < 0) ?
(RES * PAD_WIDTH) : (RES * (LCD_WIDTH - PAD_WIDTH - BALL_WIDTH));
/* restore Y-speed to default */ /* restore Y-speed to default */
p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY; p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY;
@ -254,10 +268,10 @@ void ball(struct pong *p)
newy = p->bally/RES; newy = p->bally/RES;
/* detect if ball hits a wall */ /* detect if ball hits a wall */
if(newy + BALL_HEIGTH > LCD_HEIGHT) { if(newy + BALL_HEIGHT > LCD_HEIGHT) {
/* hit floor, bounce */ /* hit floor, bounce */
p->ballspeedy = -p->ballspeedy; p->ballspeedy = -p->ballspeedy;
newy = LCD_HEIGHT - BALL_HEIGTH; newy = LCD_HEIGHT - BALL_HEIGHT;
p->bally = newy * RES; p->bally = newy * RES;
} }
else if(newy < 0) { else if(newy < 0) {
@ -277,13 +291,16 @@ void ball(struct pong *p)
else if(wallcollide(p, 1)) else if(wallcollide(p, 1))
score(p, 0); score(p, 0);
newx = p->ballx/RES;
newy = p->bally/RES;
/* clear old position */ /* clear old position */
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(x, y, BALL_WIDTH, BALL_HEIGTH); rb->lcd_fillrect(x, y, BALL_WIDTH, BALL_HEIGHT);
rb->lcd_set_drawmode(DRMODE_SOLID); rb->lcd_set_drawmode(DRMODE_SOLID);
/* draw the new ball position */ /* draw the new ball position */
rb->lcd_fillrect(newx, newy, BALL_WIDTH, BALL_HEIGTH); rb->lcd_fillrect(newx, newy, BALL_WIDTH, BALL_HEIGHT);
} }
void padmove(int *pos, int dir) void padmove(int *pos, int dir)
@ -298,6 +315,9 @@ void padmove(int *pos, int dir)
int keys(struct pong *p) int keys(struct pong *p)
{ {
int key; int key;
#ifdef PONG_PAUSE
static bool pause = false;
#endif
int time = 4; /* number of ticks this function will loop reading keys */ int time = 4; /* number of ticks this function will loop reading keys */
int start = *rb->current_tick; int start = *rb->current_tick;
@ -306,6 +326,11 @@ int keys(struct pong *p)
while(end > *rb->current_tick) { while(end > *rb->current_tick) {
key = rb->button_get_w_tmo(end - *rb->current_tick); key = rb->button_get_w_tmo(end - *rb->current_tick);
#ifdef HAS_BUTTON_HOLD
if (rb->button_hold())
return 2; /* Pause game */
#endif
if(key & PONG_QUIT if(key & PONG_QUIT
#ifdef PONG_RC_QUIT #ifdef PONG_RC_QUIT
|| key & PONG_RC_QUIT || key & PONG_RC_QUIT
@ -313,6 +338,15 @@ int keys(struct pong *p)
) )
return 0; /* exit game NOW */ return 0; /* exit game NOW */
#ifdef PONG_PAUSE
if(key == PONG_PAUSE)
pause = !pause;
if(pause)
return 2; /* Pause game */
#endif
key = rb->button_status(); /* ignore BUTTON_REPEAT */
if(key & PONG_LEFT_DOWN) /* player left goes down */ if(key & PONG_LEFT_DOWN) /* player left goes down */
padmove(&p->w_pad[0], MOVE_STEP); padmove(&p->w_pad[0], MOVE_STEP);
@ -373,6 +407,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
/* go go go */ /* go go go */
while(game > 0) { while(game > 0) {
if (game == 2) { /* Game Paused */
rb->splash(0, true, "PAUSED");
while(game == 2)
game = keys(&pong); /* short circuit */
rb->lcd_clear_display();
}
showscore(&pong); showscore(&pong);
pad(&pong, 0); /* draw left pad */ pad(&pong, 0); /* draw left pad */
pad(&pong, 1); /* draw right pad */ pad(&pong, 1); /* draw right pad */