diff options
author | Jens Arnold <amiconn@rockbox.org> | 2004-10-18 21:45:00 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2004-10-18 21:45:00 +0000 |
commit | e35a658ded457698aca2401b699e743a3011cfce (patch) | |
tree | cb89b7785ef2c72f7a293fe165a4d3b76e38227f /apps/plugins/pong.c | |
parent | d24766675db5faddb67810ca67b37491d49c2313 (diff) | |
download | rockbox-e35a658ded457698aca2401b699e743a3011cfce.tar.gz rockbox-e35a658ded457698aca2401b699e743a3011cfce.zip |
Plugin rework 2: (all) Compile-time keyboard configuration, for Ondio adaption. (all) Now using the default event handler, standard placement is now in switch() default case. (minesweeper,pong,snake,snake2) added USB handling. (mandelbrot,mosaique) Fixed return value. (minesweeper) fast moving with button repeat. (oscillograph) Fixed cleanup in USB case.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5304 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pong.c')
-rw-r--r-- | apps/plugins/pong.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/apps/plugins/pong.c b/apps/plugins/pong.c index 705b13b0fa..c7547d6de4 100644 --- a/apps/plugins/pong.c +++ b/apps/plugins/pong.c | |||
@@ -33,6 +33,23 @@ | |||
33 | 33 | ||
34 | #define MOVE_STEP 2 /* move pad this many steps up/down each move */ | 34 | #define MOVE_STEP 2 /* move pad this many steps up/down each move */ |
35 | 35 | ||
36 | /* variable button definitions */ | ||
37 | #if CONFIG_KEYPAD == RECORDER_PAD | ||
38 | #define PONG_QUIT BUTTON_OFF | ||
39 | #define PONG_LEFT_UP BUTTON_F1 | ||
40 | #define PONG_LEFT_DOWN BUTTON_LEFT | ||
41 | #define PONG_RIGHT_UP BUTTON_F3 | ||
42 | #define PONG_RIGHT_DOWN BUTTON_RIGHT | ||
43 | |||
44 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
45 | #define PONG_QUIT BUTTON_OFF | ||
46 | #define PONG_LEFT_UP BUTTON_LEFT | ||
47 | #define PONG_LEFT_DOWN BUTTON_MENU | ||
48 | #define PONG_RIGHT_UP BUTTON_UP | ||
49 | #define PONG_RIGHT_DOWN BUTTON_DOWN | ||
50 | |||
51 | #endif | ||
52 | |||
36 | static struct plugin_api* rb; | 53 | static struct plugin_api* rb; |
37 | 54 | ||
38 | struct pong { | 55 | struct pong { |
@@ -232,7 +249,7 @@ void padmove(int *pos, int dir) | |||
232 | *pos = 0; | 249 | *pos = 0; |
233 | } | 250 | } |
234 | 251 | ||
235 | bool keys(struct pong *p) | 252 | int keys(struct pong *p) |
236 | { | 253 | { |
237 | int key; | 254 | int key; |
238 | 255 | ||
@@ -243,22 +260,25 @@ bool keys(struct pong *p) | |||
243 | while(end > *rb->current_tick) { | 260 | while(end > *rb->current_tick) { |
244 | key = rb->button_get_w_tmo(end - *rb->current_tick); | 261 | key = rb->button_get_w_tmo(end - *rb->current_tick); |
245 | 262 | ||
246 | if(key & BUTTON_OFF) | 263 | if(key & PONG_QUIT) |
247 | return false; /* exit game NOW */ | 264 | return 0; /* exit game NOW */ |
248 | 265 | ||
249 | if(key & BUTTON_LEFT) /* player left goes down */ | 266 | if(key & PONG_LEFT_DOWN) /* player left goes down */ |
250 | padmove(&p->w_pad[0], MOVE_STEP); | 267 | padmove(&p->w_pad[0], MOVE_STEP); |
251 | 268 | ||
252 | if(key & BUTTON_F1) /* player left goes up */ | 269 | if(key & PONG_LEFT_UP) /* player left goes up */ |
253 | padmove(&p->w_pad[0], - MOVE_STEP); | 270 | padmove(&p->w_pad[0], -MOVE_STEP); |
254 | 271 | ||
255 | if(key & BUTTON_RIGHT) /* player right goes down */ | 272 | if(key & PONG_RIGHT_DOWN) /* player right goes down */ |
256 | padmove(&p->w_pad[1], MOVE_STEP); | 273 | padmove(&p->w_pad[1], MOVE_STEP); |
257 | 274 | ||
258 | if(key & BUTTON_F3) /* player right goes up */ | 275 | if(key & PONG_RIGHT_UP) /* player right goes up */ |
259 | padmove(&p->w_pad[1], -MOVE_STEP); | 276 | padmove(&p->w_pad[1], -MOVE_STEP); |
277 | |||
278 | if(rb->default_event_handler(key) == SYS_USB_CONNECTED) | ||
279 | return -1; /* exit game because of USB */ | ||
260 | } | 280 | } |
261 | return true; /* return false to exit game */ | 281 | return 1; /* return 0 to exit game */ |
262 | } | 282 | } |
263 | 283 | ||
264 | void showscore(struct pong *p) | 284 | void showscore(struct pong *p) |
@@ -273,7 +293,7 @@ void showscore(struct pong *p) | |||
273 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | 293 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
274 | { | 294 | { |
275 | struct pong pong; | 295 | struct pong pong; |
276 | bool game = true; | 296 | int game = 1; |
277 | 297 | ||
278 | /* init the struct with some silly values to start with */ | 298 | /* init the struct with some silly values to start with */ |
279 | 299 | ||
@@ -302,7 +322,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
302 | rb->lcd_clear_display(); | 322 | rb->lcd_clear_display(); |
303 | 323 | ||
304 | /* go go go */ | 324 | /* go go go */ |
305 | while(game) { | 325 | while(game > 0) { |
306 | showscore(&pong); | 326 | showscore(&pong); |
307 | pad(&pong, 0); /* draw left pad */ | 327 | pad(&pong, 0); /* draw left pad */ |
308 | pad(&pong, 1); /* draw right pad */ | 328 | pad(&pong, 1); /* draw right pad */ |
@@ -313,7 +333,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
313 | game = keys(&pong); /* deal with keys */ | 333 | game = keys(&pong); /* deal with keys */ |
314 | } | 334 | } |
315 | 335 | ||
316 | return PLUGIN_OK; | 336 | return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; |
317 | } | 337 | } |
318 | 338 | ||
319 | #endif /* HAVE_LCD_BITMAP */ | 339 | #endif /* HAVE_LCD_BITMAP */ |