diff options
-rw-r--r-- | apps/plugins/pong.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c index 882c1cda99..705b13b0fa 100644 --- a/apps/plugins/pong.c +++ b/apps/plugins/pong.c | |||
@@ -31,6 +31,8 @@ | |||
31 | 31 | ||
32 | #define RES 100 | 32 | #define RES 100 |
33 | 33 | ||
34 | #define MOVE_STEP 2 /* move pad this many steps up/down each move */ | ||
35 | |||
34 | static struct plugin_api* rb; | 36 | static struct plugin_api* rb; |
35 | 37 | ||
36 | struct pong { | 38 | struct pong { |
@@ -54,7 +56,7 @@ void singlepad(int x, int y, int set) | |||
54 | 56 | ||
55 | void pad(struct pong *p, int pad) | 57 | void pad(struct pong *p, int pad) |
56 | { | 58 | { |
57 | static int xpos[2]={0, 112-PAD_WIDTH}; | 59 | static int xpos[2]={0, LCD_WIDTH-PAD_WIDTH}; |
58 | 60 | ||
59 | /* clear existing pad */ | 61 | /* clear existing pad */ |
60 | singlepad(xpos[pad], p->e_pad[pad], 0); | 62 | singlepad(xpos[pad], p->e_pad[pad], 0); |
@@ -72,7 +74,7 @@ bool wallcollide(struct pong *p, int pad) | |||
72 | the wall */ | 74 | the wall */ |
73 | if(pad) { | 75 | if(pad) { |
74 | /* right-side */ | 76 | /* right-side */ |
75 | if(p->ballx > 112*RES) | 77 | if(p->ballx > LCD_WIDTH*RES) |
76 | return true; | 78 | return true; |
77 | } | 79 | } |
78 | else { | 80 | else { |
@@ -107,7 +109,7 @@ bool padcollide(struct pong *p, int pad, int *info) | |||
107 | 109 | ||
108 | if(pad) { | 110 | if(pad) { |
109 | /* right-side */ | 111 | /* right-side */ |
110 | if((x + BALL_WIDTH) > (112 - PAD_WIDTH)) | 112 | if((x + BALL_WIDTH) > (LCD_WIDTH - PAD_WIDTH)) |
111 | return true; /* phump */ | 113 | return true; /* phump */ |
112 | } | 114 | } |
113 | else { | 115 | else { |
@@ -162,7 +164,7 @@ void score(struct pong *p, int pad) | |||
162 | 164 | ||
163 | /* then move the X-speed of the ball and give it a random Y position */ | 165 | /* then move the X-speed of the ball and give it a random Y position */ |
164 | p->ballspeedx = -p->ballspeedx; | 166 | p->ballspeedx = -p->ballspeedx; |
165 | p->bally = rb->rand()%(64-BALL_HEIGTH); | 167 | p->bally = rb->rand()%(LCD_HEIGHT-BALL_HEIGTH); |
166 | 168 | ||
167 | /* restore Y-speed to default */ | 169 | /* restore Y-speed to default */ |
168 | p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY; | 170 | p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY; |
@@ -191,10 +193,10 @@ void ball(struct pong *p) | |||
191 | newy = p->bally/RES; | 193 | newy = p->bally/RES; |
192 | 194 | ||
193 | /* detect if ball hits a wall */ | 195 | /* detect if ball hits a wall */ |
194 | if(newy + BALL_HEIGTH > 64) { | 196 | if(newy + BALL_HEIGTH > LCD_HEIGHT) { |
195 | /* hit floor, bounce */ | 197 | /* hit floor, bounce */ |
196 | p->ballspeedy = -p->ballspeedy; | 198 | p->ballspeedy = -p->ballspeedy; |
197 | newy = 64 - BALL_HEIGTH; | 199 | newy = LCD_HEIGHT - BALL_HEIGTH; |
198 | p->bally = newy * RES; | 200 | p->bally = newy * RES; |
199 | } | 201 | } |
200 | else if(newy < 0) { | 202 | else if(newy < 0) { |
@@ -224,8 +226,8 @@ void ball(struct pong *p) | |||
224 | void padmove(int *pos, int dir) | 226 | void padmove(int *pos, int dir) |
225 | { | 227 | { |
226 | *pos += dir; | 228 | *pos += dir; |
227 | if(*pos > (64-PAD_HEIGHT)) | 229 | if(*pos > (LCD_HEIGHT-PAD_HEIGHT)) |
228 | *pos = (64-PAD_HEIGHT); | 230 | *pos = (LCD_HEIGHT-PAD_HEIGHT); |
229 | else if(*pos < 0) | 231 | else if(*pos < 0) |
230 | *pos = 0; | 232 | *pos = 0; |
231 | } | 233 | } |
@@ -245,16 +247,16 @@ bool keys(struct pong *p) | |||
245 | return false; /* exit game NOW */ | 247 | return false; /* exit game NOW */ |
246 | 248 | ||
247 | if(key & BUTTON_LEFT) /* player left goes down */ | 249 | if(key & BUTTON_LEFT) /* player left goes down */ |
248 | padmove(&p->w_pad[0], 1); | 250 | padmove(&p->w_pad[0], MOVE_STEP); |
249 | 251 | ||
250 | if(key & BUTTON_F1) /* player left goes up */ | 252 | if(key & BUTTON_F1) /* player left goes up */ |
251 | padmove(&p->w_pad[0], -1); | 253 | padmove(&p->w_pad[0], - MOVE_STEP); |
252 | 254 | ||
253 | if(key & BUTTON_RIGHT) /* player right goes down */ | 255 | if(key & BUTTON_RIGHT) /* player right goes down */ |
254 | padmove(&p->w_pad[1], 1); | 256 | padmove(&p->w_pad[1], MOVE_STEP); |
255 | 257 | ||
256 | if(key & BUTTON_F3) /* player right goes up */ | 258 | if(key & BUTTON_F3) /* player right goes up */ |
257 | padmove(&p->w_pad[1], -1); | 259 | padmove(&p->w_pad[1], -MOVE_STEP); |
258 | } | 260 | } |
259 | return true; /* return false to exit game */ | 261 | return true; /* return false to exit game */ |
260 | } | 262 | } |
@@ -263,7 +265,7 @@ void showscore(struct pong *p) | |||
263 | { | 265 | { |
264 | static char buffer[20]; | 266 | static char buffer[20]; |
265 | 267 | ||
266 | rb->snprintf(buffer, 20, "%d - %d", p->score[0], p->score[1]); | 268 | rb->snprintf(buffer, sizeof(buffer), "%d - %d", p->score[0], p->score[1]); |
267 | rb->lcd_puts(4, 0, buffer); | 269 | rb->lcd_puts(4, 0, buffer); |
268 | } | 270 | } |
269 | 271 | ||