diff options
author | Shachar Liberman <lshachar@hotmail.com> | 2006-08-07 17:08:48 +0000 |
---|---|---|
committer | Shachar Liberman <lshachar@hotmail.com> | 2006-08-07 17:08:48 +0000 |
commit | 8921b34e4b81f427d19b5c9f263eb893040c2d43 (patch) | |
tree | 1a5c67f7529552a5d8514c3d7f0bcd984610e1c9 | |
parent | d55503d80b155415b34e4bf36543c1f40d1b881f (diff) | |
download | rockbox-8921b34e4b81f427d19b5c9f263eb893040c2d43.tar.gz rockbox-8921b34e4b81f427d19b5c9f263eb893040c2d43.zip |
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
-rw-r--r-- | apps/plugins/pong.c | 64 |
1 files changed, 52 insertions, 12 deletions
diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c index dfa2a22fd4..ef7f2f672e 100644 --- a/apps/plugins/pong.c +++ b/apps/plugins/pong.c | |||
@@ -25,7 +25,7 @@ PLUGIN_HEADER | |||
25 | #define PAD_HEIGHT LCD_HEIGHT / 6 /* Recorder: 10 iRiver: 21 */ | 25 | #define PAD_HEIGHT LCD_HEIGHT / 6 /* Recorder: 10 iRiver: 21 */ |
26 | #define PAD_WIDTH LCD_WIDTH / 50 /* Recorder: 2 iRiver: 2 */ | 26 | #define PAD_WIDTH LCD_WIDTH / 50 /* Recorder: 2 iRiver: 2 */ |
27 | 27 | ||
28 | #define BALL_HEIGTH LCD_HEIGHT / 32 /* Recorder: 2 iRiver: 4 */ | 28 | #define BALL_HEIGHT LCD_HEIGHT / 32 /* Recorder: 2 iRiver: 4 */ |
29 | #define BALL_WIDTH LCD_HEIGHT / 32 /* We want a square ball */ | 29 | #define BALL_WIDTH LCD_HEIGHT / 32 /* We want a square ball */ |
30 | 30 | ||
31 | #define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168 iRiver: 240 */ | 31 | #define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168 iRiver: 240 */ |
@@ -38,6 +38,7 @@ PLUGIN_HEADER | |||
38 | /* variable button definitions */ | 38 | /* variable button definitions */ |
39 | #if CONFIG_KEYPAD == RECORDER_PAD | 39 | #if CONFIG_KEYPAD == RECORDER_PAD |
40 | #define PONG_QUIT BUTTON_OFF | 40 | #define PONG_QUIT BUTTON_OFF |
41 | #define PONG_PAUSE BUTTON_ON | ||
41 | #define PONG_LEFT_UP BUTTON_F1 | 42 | #define PONG_LEFT_UP BUTTON_F1 |
42 | #define PONG_LEFT_DOWN BUTTON_LEFT | 43 | #define PONG_LEFT_DOWN BUTTON_LEFT |
43 | #define PONG_RIGHT_UP BUTTON_F3 | 44 | #define PONG_RIGHT_UP BUTTON_F3 |
@@ -45,13 +46,13 @@ PLUGIN_HEADER | |||
45 | 46 | ||
46 | #elif CONFIG_KEYPAD == ONDIO_PAD | 47 | #elif CONFIG_KEYPAD == ONDIO_PAD |
47 | #define PONG_QUIT BUTTON_OFF | 48 | #define PONG_QUIT BUTTON_OFF |
49 | #define PONG_PAUSE BUTTON_RIGHT | ||
48 | #define PONG_LEFT_UP BUTTON_LEFT | 50 | #define PONG_LEFT_UP BUTTON_LEFT |
49 | #define PONG_LEFT_DOWN BUTTON_MENU | 51 | #define PONG_LEFT_DOWN BUTTON_MENU |
50 | #define PONG_RIGHT_UP BUTTON_UP | 52 | #define PONG_RIGHT_UP BUTTON_UP |
51 | #define PONG_RIGHT_DOWN BUTTON_DOWN | 53 | #define PONG_RIGHT_DOWN BUTTON_DOWN |
52 | 54 | ||
53 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ | 55 | #elif CONFIG_KEYPAD == IRIVER_H100_PAD |
54 | (CONFIG_KEYPAD == IRIVER_H300_PAD) | ||
55 | #define PONG_QUIT BUTTON_OFF | 56 | #define PONG_QUIT BUTTON_OFF |
56 | #define PONG_LEFT_UP BUTTON_UP | 57 | #define PONG_LEFT_UP BUTTON_UP |
57 | #define PONG_LEFT_DOWN BUTTON_DOWN | 58 | #define PONG_LEFT_DOWN BUTTON_DOWN |
@@ -59,6 +60,14 @@ PLUGIN_HEADER | |||
59 | #define PONG_RIGHT_DOWN BUTTON_MODE | 60 | #define PONG_RIGHT_DOWN BUTTON_MODE |
60 | #define PONG_RC_QUIT BUTTON_RC_STOP | 61 | #define PONG_RC_QUIT BUTTON_RC_STOP |
61 | 62 | ||
63 | #elif CONFIG_KEYPAD == IRIVER_H300_PAD | ||
64 | #define PONG_QUIT BUTTON_OFF | ||
65 | #define PONG_LEFT_UP BUTTON_UP | ||
66 | #define PONG_LEFT_DOWN BUTTON_DOWN | ||
67 | #define PONG_RIGHT_UP BUTTON_REC | ||
68 | #define PONG_RIGHT_DOWN BUTTON_MODE | ||
69 | #define PONG_RC_QUIT BUTTON_RC_STOP | ||
70 | |||
62 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ | 71 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ |
63 | (CONFIG_KEYPAD == IPOD_3G_PAD) | 72 | (CONFIG_KEYPAD == IPOD_3G_PAD) |
64 | #define PONG_QUIT BUTTON_SELECT | 73 | #define PONG_QUIT BUTTON_SELECT |
@@ -76,6 +85,7 @@ PLUGIN_HEADER | |||
76 | 85 | ||
77 | #elif (CONFIG_KEYPAD == GIGABEAT_PAD) | 86 | #elif (CONFIG_KEYPAD == GIGABEAT_PAD) |
78 | #define PONG_QUIT BUTTON_A | 87 | #define PONG_QUIT BUTTON_A |
88 | #define PONG_PAUSE BUTTON_MENU | ||
79 | #define PONG_LEFT_UP BUTTON_UP | 89 | #define PONG_LEFT_UP BUTTON_UP |
80 | #define PONG_LEFT_DOWN BUTTON_DOWN | 90 | #define PONG_LEFT_DOWN BUTTON_DOWN |
81 | #define PONG_RIGHT_UP BUTTON_POWER | 91 | #define PONG_RIGHT_UP BUTTON_POWER |
@@ -154,7 +164,7 @@ bool padcollide(struct pong *p, int pad, int *info) | |||
154 | int y = p->bally/RES; | 164 | int y = p->bally/RES; |
155 | 165 | ||
156 | if((y < (p->e_pad[pad]+PAD_HEIGHT)) && | 166 | if((y < (p->e_pad[pad]+PAD_HEIGHT)) && |
157 | (y + BALL_HEIGTH > p->e_pad[pad])) { | 167 | (y + BALL_HEIGHT > p->e_pad[pad])) { |
158 | /* Y seems likely right */ | 168 | /* Y seems likely right */ |
159 | 169 | ||
160 | /* store the delta between ball-middle MINUS pad-middle, so | 170 | /* store the delta between ball-middle MINUS pad-middle, so |
@@ -166,15 +176,15 @@ bool padcollide(struct pong *p, int pad, int *info) | |||
166 | max number is +- PAD_HEIGHT/2 | 176 | max number is +- PAD_HEIGHT/2 |
167 | */ | 177 | */ |
168 | 178 | ||
169 | *info = (y+BALL_HEIGTH/2) - (p->e_pad[pad] + PAD_HEIGHT/2); | 179 | *info = (y+BALL_HEIGHT/2) - (p->e_pad[pad] + PAD_HEIGHT/2); |
170 | 180 | ||
171 | if(pad) { | 181 | if(pad) { |
172 | /* right-side */ | 182 | /* right-side */ |
173 | if((x + BALL_WIDTH) > (LCD_WIDTH - PAD_WIDTH)) | 183 | if((x + BALL_WIDTH) >= (LCD_WIDTH - PAD_WIDTH)) |
174 | return true; /* phump */ | 184 | return true; /* phump */ |
175 | } | 185 | } |
176 | else { | 186 | else { |
177 | if(x <= 0) | 187 | if(x <= PAD_WIDTH) |
178 | return true; | 188 | return true; |
179 | } | 189 | } |
180 | } | 190 | } |
@@ -225,8 +235,12 @@ void score(struct pong *p, int pad) | |||
225 | 235 | ||
226 | /* then move the X-speed of the ball and give it a random Y position */ | 236 | /* then move the X-speed of the ball and give it a random Y position */ |
227 | p->ballspeedx = -p->ballspeedx; | 237 | p->ballspeedx = -p->ballspeedx; |
228 | p->bally = rb->rand()%(LCD_HEIGHT-BALL_HEIGTH); | 238 | p->bally = rb->rand()%(LCD_HEIGHT*RES - BALL_HEIGHT); |
229 | 239 | ||
240 | /* avoid hitting the pad with the new ball */ | ||
241 | p->ballx = (p->ballx < 0) ? | ||
242 | (RES * PAD_WIDTH) : (RES * (LCD_WIDTH - PAD_WIDTH - BALL_WIDTH)); | ||
243 | |||
230 | /* restore Y-speed to default */ | 244 | /* restore Y-speed to default */ |
231 | p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY; | 245 | p->ballspeedy = (p->ballspeedy > 0) ? SPEEDY : -SPEEDY; |
232 | 246 | ||
@@ -254,10 +268,10 @@ void ball(struct pong *p) | |||
254 | newy = p->bally/RES; | 268 | newy = p->bally/RES; |
255 | 269 | ||
256 | /* detect if ball hits a wall */ | 270 | /* detect if ball hits a wall */ |
257 | if(newy + BALL_HEIGTH > LCD_HEIGHT) { | 271 | if(newy + BALL_HEIGHT > LCD_HEIGHT) { |
258 | /* hit floor, bounce */ | 272 | /* hit floor, bounce */ |
259 | p->ballspeedy = -p->ballspeedy; | 273 | p->ballspeedy = -p->ballspeedy; |
260 | newy = LCD_HEIGHT - BALL_HEIGTH; | 274 | newy = LCD_HEIGHT - BALL_HEIGHT; |
261 | p->bally = newy * RES; | 275 | p->bally = newy * RES; |
262 | } | 276 | } |
263 | else if(newy < 0) { | 277 | else if(newy < 0) { |
@@ -277,13 +291,16 @@ void ball(struct pong *p) | |||
277 | else if(wallcollide(p, 1)) | 291 | else if(wallcollide(p, 1)) |
278 | score(p, 0); | 292 | score(p, 0); |
279 | 293 | ||
294 | newx = p->ballx/RES; | ||
295 | newy = p->bally/RES; | ||
296 | |||
280 | /* clear old position */ | 297 | /* clear old position */ |
281 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); | 298 | rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); |
282 | rb->lcd_fillrect(x, y, BALL_WIDTH, BALL_HEIGTH); | 299 | rb->lcd_fillrect(x, y, BALL_WIDTH, BALL_HEIGHT); |
283 | rb->lcd_set_drawmode(DRMODE_SOLID); | 300 | rb->lcd_set_drawmode(DRMODE_SOLID); |
284 | 301 | ||
285 | /* draw the new ball position */ | 302 | /* draw the new ball position */ |
286 | rb->lcd_fillrect(newx, newy, BALL_WIDTH, BALL_HEIGTH); | 303 | rb->lcd_fillrect(newx, newy, BALL_WIDTH, BALL_HEIGHT); |
287 | } | 304 | } |
288 | 305 | ||
289 | void padmove(int *pos, int dir) | 306 | void padmove(int *pos, int dir) |
@@ -298,6 +315,9 @@ void padmove(int *pos, int dir) | |||
298 | int keys(struct pong *p) | 315 | int keys(struct pong *p) |
299 | { | 316 | { |
300 | int key; | 317 | int key; |
318 | #ifdef PONG_PAUSE | ||
319 | static bool pause = false; | ||
320 | #endif | ||
301 | 321 | ||
302 | int time = 4; /* number of ticks this function will loop reading keys */ | 322 | int time = 4; /* number of ticks this function will loop reading keys */ |
303 | int start = *rb->current_tick; | 323 | int start = *rb->current_tick; |
@@ -306,6 +326,11 @@ int keys(struct pong *p) | |||
306 | while(end > *rb->current_tick) { | 326 | while(end > *rb->current_tick) { |
307 | key = rb->button_get_w_tmo(end - *rb->current_tick); | 327 | key = rb->button_get_w_tmo(end - *rb->current_tick); |
308 | 328 | ||
329 | #ifdef HAS_BUTTON_HOLD | ||
330 | if (rb->button_hold()) | ||
331 | return 2; /* Pause game */ | ||
332 | #endif | ||
333 | |||
309 | if(key & PONG_QUIT | 334 | if(key & PONG_QUIT |
310 | #ifdef PONG_RC_QUIT | 335 | #ifdef PONG_RC_QUIT |
311 | || key & PONG_RC_QUIT | 336 | || key & PONG_RC_QUIT |
@@ -313,6 +338,15 @@ int keys(struct pong *p) | |||
313 | ) | 338 | ) |
314 | return 0; /* exit game NOW */ | 339 | return 0; /* exit game NOW */ |
315 | 340 | ||
341 | #ifdef PONG_PAUSE | ||
342 | if(key == PONG_PAUSE) | ||
343 | pause = !pause; | ||
344 | if(pause) | ||
345 | return 2; /* Pause game */ | ||
346 | #endif | ||
347 | |||
348 | key = rb->button_status(); /* ignore BUTTON_REPEAT */ | ||
349 | |||
316 | if(key & PONG_LEFT_DOWN) /* player left goes down */ | 350 | if(key & PONG_LEFT_DOWN) /* player left goes down */ |
317 | padmove(&p->w_pad[0], MOVE_STEP); | 351 | padmove(&p->w_pad[0], MOVE_STEP); |
318 | 352 | ||
@@ -373,6 +407,12 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
373 | 407 | ||
374 | /* go go go */ | 408 | /* go go go */ |
375 | while(game > 0) { | 409 | while(game > 0) { |
410 | if (game == 2) { /* Game Paused */ | ||
411 | rb->splash(0, true, "PAUSED"); | ||
412 | while(game == 2) | ||
413 | game = keys(&pong); /* short circuit */ | ||
414 | rb->lcd_clear_display(); | ||
415 | } | ||
376 | showscore(&pong); | 416 | showscore(&pong); |
377 | pad(&pong, 0); /* draw left pad */ | 417 | pad(&pong, 0); /* draw left pad */ |
378 | pad(&pong, 1); /* draw right pad */ | 418 | pad(&pong, 1); /* draw right pad */ |