forked from len0rd/rockbox
Move two steps on each move up/down. (Attempt to make it more playable after
user input, maybe I should try it myself on target soon) Replaced hard-coded LCD sizes with the proper defines. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4797 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
ae74060e57
commit
8ea434834c
1 changed files with 15 additions and 13 deletions
|
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#define RES 100
|
#define RES 100
|
||||||
|
|
||||||
|
#define MOVE_STEP 2 /* move pad this many steps up/down each move */
|
||||||
|
|
||||||
static struct plugin_api* rb;
|
static struct plugin_api* rb;
|
||||||
|
|
||||||
struct pong {
|
struct pong {
|
||||||
|
|
@ -54,7 +56,7 @@ void singlepad(int x, int y, int set)
|
||||||
|
|
||||||
void pad(struct pong *p, int pad)
|
void pad(struct pong *p, int pad)
|
||||||
{
|
{
|
||||||
static int xpos[2]={0, 112-PAD_WIDTH};
|
static int xpos[2]={0, LCD_WIDTH-PAD_WIDTH};
|
||||||
|
|
||||||
/* clear existing pad */
|
/* clear existing pad */
|
||||||
singlepad(xpos[pad], p->e_pad[pad], 0);
|
singlepad(xpos[pad], p->e_pad[pad], 0);
|
||||||
|
|
@ -72,7 +74,7 @@ bool wallcollide(struct pong *p, int pad)
|
||||||
the wall */
|
the wall */
|
||||||
if(pad) {
|
if(pad) {
|
||||||
/* right-side */
|
/* right-side */
|
||||||
if(p->ballx > 112*RES)
|
if(p->ballx > LCD_WIDTH*RES)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -107,7 +109,7 @@ bool padcollide(struct pong *p, int pad, int *info)
|
||||||
|
|
||||||
if(pad) {
|
if(pad) {
|
||||||
/* right-side */
|
/* right-side */
|
||||||
if((x + BALL_WIDTH) > (112 - PAD_WIDTH))
|
if((x + BALL_WIDTH) > (LCD_WIDTH - PAD_WIDTH))
|
||||||
return true; /* phump */
|
return true; /* phump */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -162,7 +164,7 @@ 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()%(64-BALL_HEIGTH);
|
p->bally = rb->rand()%(LCD_HEIGHT-BALL_HEIGTH);
|
||||||
|
|
||||||
/* restore Y-speed to default */
|
/* restore Y-speed to default */
|
||||||
p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY;
|
p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY;
|
||||||
|
|
@ -191,10 +193,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 > 64) {
|
if(newy + BALL_HEIGTH > LCD_HEIGHT) {
|
||||||
/* hit floor, bounce */
|
/* hit floor, bounce */
|
||||||
p->ballspeedy = -p->ballspeedy;
|
p->ballspeedy = -p->ballspeedy;
|
||||||
newy = 64 - BALL_HEIGTH;
|
newy = LCD_HEIGHT - BALL_HEIGTH;
|
||||||
p->bally = newy * RES;
|
p->bally = newy * RES;
|
||||||
}
|
}
|
||||||
else if(newy < 0) {
|
else if(newy < 0) {
|
||||||
|
|
@ -224,8 +226,8 @@ void ball(struct pong *p)
|
||||||
void padmove(int *pos, int dir)
|
void padmove(int *pos, int dir)
|
||||||
{
|
{
|
||||||
*pos += dir;
|
*pos += dir;
|
||||||
if(*pos > (64-PAD_HEIGHT))
|
if(*pos > (LCD_HEIGHT-PAD_HEIGHT))
|
||||||
*pos = (64-PAD_HEIGHT);
|
*pos = (LCD_HEIGHT-PAD_HEIGHT);
|
||||||
else if(*pos < 0)
|
else if(*pos < 0)
|
||||||
*pos = 0;
|
*pos = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -245,16 +247,16 @@ bool keys(struct pong *p)
|
||||||
return false; /* exit game NOW */
|
return false; /* exit game NOW */
|
||||||
|
|
||||||
if(key & BUTTON_LEFT) /* player left goes down */
|
if(key & BUTTON_LEFT) /* player left goes down */
|
||||||
padmove(&p->w_pad[0], 1);
|
padmove(&p->w_pad[0], MOVE_STEP);
|
||||||
|
|
||||||
if(key & BUTTON_F1) /* player left goes up */
|
if(key & BUTTON_F1) /* player left goes up */
|
||||||
padmove(&p->w_pad[0], -1);
|
padmove(&p->w_pad[0], - MOVE_STEP);
|
||||||
|
|
||||||
if(key & BUTTON_RIGHT) /* player right goes down */
|
if(key & BUTTON_RIGHT) /* player right goes down */
|
||||||
padmove(&p->w_pad[1], 1);
|
padmove(&p->w_pad[1], MOVE_STEP);
|
||||||
|
|
||||||
if(key & BUTTON_F3) /* player right goes up */
|
if(key & BUTTON_F3) /* player right goes up */
|
||||||
padmove(&p->w_pad[1], -1);
|
padmove(&p->w_pad[1], -MOVE_STEP);
|
||||||
}
|
}
|
||||||
return true; /* return false to exit game */
|
return true; /* return false to exit game */
|
||||||
}
|
}
|
||||||
|
|
@ -263,7 +265,7 @@ void showscore(struct pong *p)
|
||||||
{
|
{
|
||||||
static char buffer[20];
|
static char buffer[20];
|
||||||
|
|
||||||
rb->snprintf(buffer, 20, "%d - %d", p->score[0], p->score[1]);
|
rb->snprintf(buffer, sizeof(buffer), "%d - %d", p->score[0], p->score[1]);
|
||||||
rb->lcd_puts(4, 0, buffer);
|
rb->lcd_puts(4, 0, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue