2004-06-16 21:54:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Daniel Stenberg
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2004-06-16 21:56:46 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2005-02-16 01:18:14 +00:00
|
|
|
#define PAD_HEIGHT LCD_HEIGHT / 6 /* Recorder: 10 iRiver: 21 */
|
|
|
|
#define PAD_WIDTH LCD_WIDTH / 50 /* Recorder: 2 iRiver: 2 */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#define BALL_HEIGHT LCD_HEIGHT / 32 /* Recorder: 2 iRiver: 4 */
|
2005-02-16 01:18:14 +00:00
|
|
|
#define BALL_WIDTH LCD_HEIGHT / 32 /* We want a square ball */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2005-02-16 01:18:14 +00:00
|
|
|
#define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168 iRiver: 240 */
|
|
|
|
#define SPEEDY LCD_HEIGHT * 2 /* Recorder: 128 iRiver: 256 */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
#define RES 100
|
|
|
|
|
2005-02-16 01:18:14 +00:00
|
|
|
#define MOVE_STEP LCD_HEIGHT / 32 /* move pad this many steps up/down each move */
|
2004-06-23 06:59:16 +00:00
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
/* variable button definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define PONG_QUIT BUTTON_OFF
|
2006-08-07 17:08:48 +00:00
|
|
|
#define PONG_PAUSE BUTTON_ON
|
2004-10-18 21:45:00 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_F1
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_LEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_F3
|
2007-01-14 13:48:09 +00:00
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
|
|
|
|
#define PONG_QUIT BUTTON_OFF
|
|
|
|
#define PONG_PAUSE BUTTON_ON
|
|
|
|
#define PONG_LEFT_UP BUTTON_F1
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_LEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_F3
|
2004-10-18 21:45:00 +00:00
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
#define PONG_QUIT BUTTON_OFF
|
2006-08-07 17:08:48 +00:00
|
|
|
#define PONG_PAUSE BUTTON_RIGHT
|
2004-10-18 21:45:00 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_LEFT
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_MENU
|
|
|
|
#define PONG_RIGHT_UP BUTTON_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_DOWN
|
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H100_PAD
|
2005-02-04 12:41:09 +00:00
|
|
|
#define PONG_QUIT BUTTON_OFF
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_ON
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_MODE
|
2006-06-30 16:43:47 +00:00
|
|
|
#define PONG_RC_QUIT BUTTON_RC_STOP
|
2005-02-04 12:41:09 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#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
|
|
|
|
|
2006-02-24 20:54:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD)
|
2005-12-14 01:31:37 +00:00
|
|
|
#define PONG_QUIT BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_MENU
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_LEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_RIGHT
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_PLAY
|
|
|
|
|
2006-01-18 11:09:06 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_REC
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_PLAY
|
|
|
|
|
2006-02-24 15:42:52 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_A
|
2006-08-07 17:08:48 +00:00
|
|
|
#define PONG_PAUSE BUTTON_MENU
|
2006-02-24 15:42:52 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_POWER
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_MENU
|
|
|
|
|
2006-10-26 13:38:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_LEFT
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_LEFT_UP BUTTON_SCROLL_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_SCROLL_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_REW
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_FF
|
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
#endif
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
static struct plugin_api* rb;
|
|
|
|
|
|
|
|
struct pong {
|
|
|
|
int ballx; /* current X*RES position of the ball */
|
|
|
|
int bally; /* current Y*RES position of the ball */
|
|
|
|
int w_pad[2]; /* wanted current Y positions of pads */
|
|
|
|
int e_pad[2]; /* existing current Y positions of pads */
|
|
|
|
int ballspeedx; /* */
|
|
|
|
int ballspeedy; /* */
|
|
|
|
|
|
|
|
int score[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
void singlepad(int x, int y, int set)
|
|
|
|
{
|
2005-06-24 22:33:21 +00:00
|
|
|
if(set) {
|
2004-06-16 21:54:53 +00:00
|
|
|
rb->lcd_fillrect(x, y, PAD_WIDTH, PAD_HEIGHT);
|
2005-06-24 22:33:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
|
|
|
rb->lcd_fillrect(x, y, PAD_WIDTH, PAD_HEIGHT);
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
}
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pad(struct pong *p, int pad)
|
|
|
|
{
|
2004-06-23 06:59:16 +00:00
|
|
|
static int xpos[2]={0, LCD_WIDTH-PAD_WIDTH};
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* clear existing pad */
|
|
|
|
singlepad(xpos[pad], p->e_pad[pad], 0);
|
|
|
|
|
|
|
|
/* draw wanted pad */
|
|
|
|
singlepad(xpos[pad], p->w_pad[pad], 1);
|
|
|
|
|
|
|
|
/* existing is now the wanted */
|
|
|
|
p->e_pad[pad] = p->w_pad[pad];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wallcollide(struct pong *p, int pad)
|
|
|
|
{
|
|
|
|
/* we have already checked for pad-collision, just check if this hits
|
|
|
|
the wall */
|
|
|
|
if(pad) {
|
|
|
|
/* right-side */
|
2004-06-23 06:59:16 +00:00
|
|
|
if(p->ballx > LCD_WIDTH*RES)
|
2004-06-16 21:54:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(p->ballx < 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns true if the ball has hit a pad, and then the info variable
|
|
|
|
will have extra angle info */
|
|
|
|
|
|
|
|
bool padcollide(struct pong *p, int pad, int *info)
|
|
|
|
{
|
|
|
|
int x = p->ballx/RES;
|
|
|
|
int y = p->bally/RES;
|
|
|
|
|
|
|
|
if((y < (p->e_pad[pad]+PAD_HEIGHT)) &&
|
2006-08-07 17:08:48 +00:00
|
|
|
(y + BALL_HEIGHT > p->e_pad[pad])) {
|
2004-06-16 21:54:53 +00:00
|
|
|
/* Y seems likely right */
|
|
|
|
|
|
|
|
/* store the delta between ball-middle MINUS pad-middle, so
|
|
|
|
it returns:
|
|
|
|
0 when the ball hits exactly the middle of the pad
|
|
|
|
positive numbers when the ball is below the middle of the pad
|
|
|
|
negative numbers when the ball is above the middle of the pad
|
|
|
|
|
|
|
|
max number is +- PAD_HEIGHT/2
|
|
|
|
*/
|
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
*info = (y+BALL_HEIGHT/2) - (p->e_pad[pad] + PAD_HEIGHT/2);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
if(pad) {
|
|
|
|
/* right-side */
|
2006-08-07 17:08:48 +00:00
|
|
|
if((x + BALL_WIDTH) >= (LCD_WIDTH - PAD_WIDTH))
|
2004-06-16 21:54:53 +00:00
|
|
|
return true; /* phump */
|
|
|
|
}
|
|
|
|
else {
|
2006-08-07 17:08:48 +00:00
|
|
|
if(x <= PAD_WIDTH)
|
2004-06-16 21:54:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false; /* nah */
|
|
|
|
}
|
|
|
|
|
|
|
|
void bounce(struct pong *p, int pad, int info)
|
|
|
|
{
|
|
|
|
(void)pad; /* not used right now */
|
|
|
|
p->ballspeedx = -p->ballspeedx;
|
|
|
|
|
|
|
|
/* info is the hit-angle into the pad */
|
|
|
|
if(p->ballspeedy > 0) {
|
|
|
|
/* downwards */
|
|
|
|
if(info > 0) {
|
|
|
|
/* below the middle of the pad */
|
|
|
|
p->ballspeedy += info * RES/3;
|
|
|
|
}
|
|
|
|
else if(info < 0) {
|
|
|
|
/* above the middle */
|
|
|
|
p->ballspeedy = info * RES/2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* upwards */
|
|
|
|
if(info > 0) {
|
|
|
|
/* below the middle of the pad */
|
|
|
|
p->ballspeedy = info * RES/2;
|
|
|
|
}
|
|
|
|
else if(info < 0) {
|
|
|
|
/* above the middle */
|
|
|
|
p->ballspeedy -= info * RES/3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p->ballspeedy += rb->rand()%21-10;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "INFO: %d YSPEED: %d\n", info, p->ballspeedy);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void score(struct pong *p, int pad)
|
|
|
|
{
|
|
|
|
rb->splash(HZ/4, true, "%s scores!", pad?"right":"left");
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
p->score[pad]++;
|
|
|
|
|
|
|
|
/* then move the X-speed of the ball and give it a random Y position */
|
|
|
|
p->ballspeedx = -p->ballspeedx;
|
2006-08-07 17:08:48 +00:00
|
|
|
p->bally = rb->rand()%(LCD_HEIGHT*RES - BALL_HEIGHT);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
/* avoid hitting the pad with the new ball */
|
|
|
|
p->ballx = (p->ballx < 0) ?
|
|
|
|
(RES * PAD_WIDTH) : (RES * (LCD_WIDTH - PAD_WIDTH - BALL_WIDTH));
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
/* restore Y-speed to default */
|
|
|
|
p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY;
|
|
|
|
|
|
|
|
/* set the existing pad positions to something weird to force pad
|
|
|
|
updates */
|
|
|
|
p->e_pad[0] = -1;
|
|
|
|
p->e_pad[1] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ball(struct pong *p)
|
|
|
|
{
|
|
|
|
int x = p->ballx/RES;
|
|
|
|
int y = p->bally/RES;
|
|
|
|
|
|
|
|
int newx;
|
|
|
|
int newy;
|
|
|
|
|
|
|
|
int info;
|
|
|
|
|
|
|
|
/* movement */
|
|
|
|
p->ballx += p->ballspeedx;
|
|
|
|
p->bally += p->ballspeedy;
|
|
|
|
|
|
|
|
newx = p->ballx/RES;
|
|
|
|
newy = p->bally/RES;
|
|
|
|
|
|
|
|
/* detect if ball hits a wall */
|
2006-08-07 17:08:48 +00:00
|
|
|
if(newy + BALL_HEIGHT > LCD_HEIGHT) {
|
2004-06-16 21:54:53 +00:00
|
|
|
/* hit floor, bounce */
|
|
|
|
p->ballspeedy = -p->ballspeedy;
|
2006-08-07 17:08:48 +00:00
|
|
|
newy = LCD_HEIGHT - BALL_HEIGHT;
|
2004-06-16 21:54:53 +00:00
|
|
|
p->bally = newy * RES;
|
|
|
|
}
|
|
|
|
else if(newy < 0) {
|
|
|
|
/* hit ceiling, bounce */
|
|
|
|
p->ballspeedy = -p->ballspeedy;
|
|
|
|
p->bally = 0;
|
|
|
|
newy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* detect if ball hit pads */
|
|
|
|
if(padcollide(p, 0, &info))
|
|
|
|
bounce(p, 0, info);
|
|
|
|
else if(padcollide(p, 1, &info))
|
|
|
|
bounce(p, 1, info);
|
|
|
|
else if(wallcollide(p, 0))
|
|
|
|
score(p, 1);
|
|
|
|
else if(wallcollide(p, 1))
|
|
|
|
score(p, 0);
|
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
newx = p->ballx/RES;
|
|
|
|
newy = p->bally/RES;
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
/* clear old position */
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
2006-08-07 17:08:48 +00:00
|
|
|
rb->lcd_fillrect(x, y, BALL_WIDTH, BALL_HEIGHT);
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* draw the new ball position */
|
2006-08-07 17:08:48 +00:00
|
|
|
rb->lcd_fillrect(newx, newy, BALL_WIDTH, BALL_HEIGHT);
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void padmove(int *pos, int dir)
|
|
|
|
{
|
|
|
|
*pos += dir;
|
2004-06-23 06:59:16 +00:00
|
|
|
if(*pos > (LCD_HEIGHT-PAD_HEIGHT))
|
|
|
|
*pos = (LCD_HEIGHT-PAD_HEIGHT);
|
2004-06-16 21:54:53 +00:00
|
|
|
else if(*pos < 0)
|
|
|
|
*pos = 0;
|
|
|
|
}
|
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
int keys(struct pong *p)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
|
|
|
int key;
|
2006-08-07 17:08:48 +00:00
|
|
|
#ifdef PONG_PAUSE
|
|
|
|
static bool pause = false;
|
|
|
|
#endif
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
int time = 4; /* number of ticks this function will loop reading keys */
|
|
|
|
int start = *rb->current_tick;
|
|
|
|
int end = start + time;
|
|
|
|
|
|
|
|
while(end > *rb->current_tick) {
|
|
|
|
key = rb->button_get_w_tmo(end - *rb->current_tick);
|
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
if (rb->button_hold())
|
|
|
|
return 2; /* Pause game */
|
|
|
|
#endif
|
|
|
|
|
2006-06-30 16:43:47 +00:00
|
|
|
if(key & PONG_QUIT
|
|
|
|
#ifdef PONG_RC_QUIT
|
|
|
|
|| key & PONG_RC_QUIT
|
|
|
|
#endif
|
|
|
|
)
|
2004-10-18 21:45:00 +00:00
|
|
|
return 0; /* exit game NOW */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#ifdef PONG_PAUSE
|
|
|
|
if(key == PONG_PAUSE)
|
|
|
|
pause = !pause;
|
|
|
|
if(pause)
|
|
|
|
return 2; /* Pause game */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
key = rb->button_status(); /* ignore BUTTON_REPEAT */
|
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
if(key & PONG_LEFT_DOWN) /* player left goes down */
|
2004-06-23 06:59:16 +00:00
|
|
|
padmove(&p->w_pad[0], MOVE_STEP);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
if(key & PONG_LEFT_UP) /* player left goes up */
|
|
|
|
padmove(&p->w_pad[0], -MOVE_STEP);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
if(key & PONG_RIGHT_DOWN) /* player right goes down */
|
2004-06-23 06:59:16 +00:00
|
|
|
padmove(&p->w_pad[1], MOVE_STEP);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
if(key & PONG_RIGHT_UP) /* player right goes up */
|
2004-06-23 06:59:16 +00:00
|
|
|
padmove(&p->w_pad[1], -MOVE_STEP);
|
2004-10-18 21:45:00 +00:00
|
|
|
|
|
|
|
if(rb->default_event_handler(key) == SYS_USB_CONNECTED)
|
|
|
|
return -1; /* exit game because of USB */
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
2004-10-18 21:45:00 +00:00
|
|
|
return 1; /* return 0 to exit game */
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void showscore(struct pong *p)
|
|
|
|
{
|
|
|
|
static char buffer[20];
|
2005-02-16 01:18:14 +00:00
|
|
|
int w;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2004-06-23 06:59:16 +00:00
|
|
|
rb->snprintf(buffer, sizeof(buffer), "%d - %d", p->score[0], p->score[1]);
|
2005-12-02 08:08:54 +00:00
|
|
|
w = rb->lcd_getstringsize((unsigned char *)buffer, NULL, NULL);
|
|
|
|
rb->lcd_putsxy( (LCD_WIDTH / 2) - (w / 2), 0, (unsigned char *)buffer);
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* this is the plugin entry point */
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
|
|
|
struct pong pong;
|
2004-10-18 21:45:00 +00:00
|
|
|
int game = 1;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* init the struct with some silly values to start with */
|
|
|
|
|
|
|
|
pong.ballx = 20*RES;
|
|
|
|
pong.bally = 20*RES;
|
|
|
|
|
|
|
|
pong.e_pad[0] = 0;
|
|
|
|
pong.w_pad[0] = 7;
|
|
|
|
pong.e_pad[1] = 0;
|
|
|
|
pong.w_pad[1] = 40;
|
|
|
|
|
|
|
|
pong.ballspeedx = SPEEDX;
|
|
|
|
pong.ballspeedy = SPEEDY;
|
|
|
|
|
|
|
|
pong.score[0] = pong.score[1] = 0; /* lets start at 0 - 0 ;-) */
|
|
|
|
|
|
|
|
/* if you don't use the parameter, you can do like
|
|
|
|
this to avoid the compiler warning about it */
|
|
|
|
(void)parameter;
|
2006-01-15 18:20:18 +00:00
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
rb = api; /* use the "standard" rb pointer */
|
|
|
|
|
|
|
|
/* Clear screen */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
/* go go go */
|
2004-10-18 21:45:00 +00:00
|
|
|
while(game > 0) {
|
2006-08-07 17:08:48 +00:00
|
|
|
if (game == 2) { /* Game Paused */
|
|
|
|
rb->splash(0, true, "PAUSED");
|
|
|
|
while(game == 2)
|
|
|
|
game = keys(&pong); /* short circuit */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
}
|
2004-06-16 21:54:53 +00:00
|
|
|
showscore(&pong);
|
|
|
|
pad(&pong, 0); /* draw left pad */
|
|
|
|
pad(&pong, 1); /* draw right pad */
|
|
|
|
ball(&pong); /* move and draw ball */
|
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
|
|
|
|
game = keys(&pong); /* deal with keys */
|
|
|
|
}
|
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
2004-06-16 21:56:46 +00:00
|
|
|
|
|
|
|
#endif /* HAVE_LCD_BITMAP */
|