diff options
author | Teruaki Kawashima <teru@rockbox.org> | 2009-08-18 13:40:08 +0000 |
---|---|---|
committer | Teruaki Kawashima <teru@rockbox.org> | 2009-08-18 13:40:08 +0000 |
commit | 08bf107214ac3b8150752da7d0c4317759ea6c71 (patch) | |
tree | b2531cc2cea9180d59e6cb2937bffad165d34209 | |
parent | 5c20ddfcd9afa1980570de77606c921c04f04316 (diff) | |
download | rockbox-08bf107214ac3b8150752da7d0c4317759ea6c71.tar.gz rockbox-08bf107214ac3b8150752da7d0c4317759ea6c71.zip |
snake: Clear backdrop before displaying highscores and restore background, foreground and backdrop after displaying highscores.
go back to menu when game is over. r22206 failed to do it.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22408 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/plugins/snake.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/apps/plugins/snake.c b/apps/plugins/snake.c index 9491d56014..e2e34e3f06 100644 --- a/apps/plugins/snake.c +++ b/apps/plugins/snake.c | |||
@@ -220,7 +220,7 @@ PLUGIN_HEADER | |||
220 | 220 | ||
221 | static int board[BOARD_WIDTH][BOARD_HEIGHT],snakelength; | 221 | static int board[BOARD_WIDTH][BOARD_HEIGHT],snakelength; |
222 | static int score,level=1; | 222 | static int score,level=1; |
223 | static int dir,dead=0; | 223 | static int dir,dead=0,quit=0; |
224 | static bool apple; | 224 | static bool apple; |
225 | 225 | ||
226 | static struct highscore highscores[NUM_SCORES]; | 226 | static struct highscore highscores[NUM_SCORES]; |
@@ -247,6 +247,12 @@ void die (void) | |||
247 | 247 | ||
248 | void colission (short x, short y) | 248 | void colission (short x, short y) |
249 | { | 249 | { |
250 | if (x==BOARD_WIDTH || x<0 || y==BOARD_HEIGHT || y<0) | ||
251 | { | ||
252 | die(); | ||
253 | return; | ||
254 | } | ||
255 | |||
250 | switch (board[x][y]) { | 256 | switch (board[x][y]) { |
251 | case 0: | 257 | case 0: |
252 | break; | 258 | break; |
@@ -259,8 +265,6 @@ void colission (short x, short y) | |||
259 | die(); | 265 | die(); |
260 | break; | 266 | break; |
261 | } | 267 | } |
262 | if (x==BOARD_WIDTH || x<0 || y==BOARD_HEIGHT || y<0) | ||
263 | die(); | ||
264 | } | 268 | } |
265 | 269 | ||
266 | void move_head (short x, short y) | 270 | void move_head (short x, short y) |
@@ -362,6 +366,7 @@ void game_pause (void) { | |||
362 | #endif | 366 | #endif |
363 | case SNAKE_QUIT: | 367 | case SNAKE_QUIT: |
364 | dead=1; | 368 | dead=1; |
369 | quit=1; | ||
365 | return; | 370 | return; |
366 | case SNAKE_PLAYPAUSE: | 371 | case SNAKE_PLAYPAUSE: |
367 | redraw(); | 372 | redraw(); |
@@ -369,7 +374,8 @@ void game_pause (void) { | |||
369 | return; | 374 | return; |
370 | default: | 375 | default: |
371 | if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { | 376 | if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { |
372 | dead=2; | 377 | dead = 1; |
378 | quit = 2; | ||
373 | return; | 379 | return; |
374 | } | 380 | } |
375 | break; | 381 | break; |
@@ -422,14 +428,14 @@ void game (void) { | |||
422 | case SNAKE_RC_QUIT: | 428 | case SNAKE_RC_QUIT: |
423 | #endif | 429 | #endif |
424 | case SNAKE_QUIT: | 430 | case SNAKE_QUIT: |
425 | dead=1; | 431 | quit = 1; |
426 | return; | 432 | return; |
427 | case SNAKE_PLAYPAUSE: | 433 | case SNAKE_PLAYPAUSE: |
428 | game_pause(); | 434 | game_pause(); |
429 | break; | 435 | break; |
430 | default: | 436 | default: |
431 | if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { | 437 | if (rb->default_event_handler(button)==SYS_USB_CONNECTED) { |
432 | dead=2; | 438 | quit = 2; |
433 | return; | 439 | return; |
434 | } | 440 | } |
435 | break; | 441 | break; |
@@ -453,6 +459,10 @@ void game_init(void) { | |||
453 | score=0; | 459 | score=0; |
454 | board[11][7]=1; | 460 | board[11][7]=1; |
455 | 461 | ||
462 | #if LCD_DEPTH > 1 | ||
463 | fb_data *backdrop = rb->lcd_get_backdrop(); | ||
464 | #endif | ||
465 | |||
456 | MENUITEM_STRINGLIST(menu, "Snake Menu", NULL, | 466 | MENUITEM_STRINGLIST(menu, "Snake Menu", NULL, |
457 | "Start New Game", "Starting Level", | 467 | "Start New Game", "Starting Level", |
458 | "High Scores", | 468 | "High Scores", |
@@ -473,7 +483,19 @@ void game_init(void) { | |||
473 | break; | 483 | break; |
474 | 484 | ||
475 | case 2: | 485 | case 2: |
486 | #if LCD_DEPTH > 1 | ||
487 | rb->lcd_set_backdrop(NULL); | ||
488 | #endif | ||
476 | highscore_show(NUM_SCORES, highscores, NUM_SCORES, true); | 489 | highscore_show(NUM_SCORES, highscores, NUM_SCORES, true); |
490 | |||
491 | rb->lcd_setfont(FONT_UI); | ||
492 | #if LCD_DEPTH > 1 | ||
493 | rb->lcd_set_backdrop(backdrop); | ||
494 | #ifdef HAVE_LCD_COLOR | ||
495 | rb->lcd_set_background(rb->global_settings->bg_color); | ||
496 | rb->lcd_set_foreground(rb->global_settings->fg_color); | ||
497 | #endif | ||
498 | #endif | ||
477 | break; | 499 | break; |
478 | 500 | ||
479 | case 3: | 501 | case 3: |
@@ -481,12 +503,12 @@ void game_init(void) { | |||
481 | break; | 503 | break; |
482 | 504 | ||
483 | case MENU_ATTACHED_USB: | 505 | case MENU_ATTACHED_USB: |
484 | dead = 2; | 506 | quit = 2; |
485 | menu_quit = true; | 507 | menu_quit = true; |
486 | break; | 508 | break; |
487 | 509 | ||
488 | default: | 510 | default: |
489 | dead=1; /* quit program */ | 511 | quit = 1; /* quit program */ |
490 | menu_quit = true; | 512 | menu_quit = true; |
491 | break; | 513 | break; |
492 | 514 | ||
@@ -499,16 +521,16 @@ enum plugin_status plugin_start(const void* parameter) | |||
499 | (void)(parameter); | 521 | (void)(parameter); |
500 | 522 | ||
501 | highscore_load(SCORE_FILE, highscores, NUM_SCORES); | 523 | highscore_load(SCORE_FILE, highscores, NUM_SCORES); |
502 | while(dead == 0) | 524 | while(!quit) |
503 | { | 525 | { |
504 | game_init(); | 526 | game_init(); |
505 | if(dead) | 527 | if(quit) |
506 | break; | 528 | break; |
507 | rb->lcd_clear_display(); | 529 | rb->lcd_clear_display(); |
508 | game(); | 530 | game(); |
509 | } | 531 | } |
510 | highscore_save(SCORE_FILE, highscores, NUM_SCORES); | 532 | highscore_save(SCORE_FILE, highscores, NUM_SCORES); |
511 | return (dead==1)?PLUGIN_OK:PLUGIN_USB_CONNECTED; | 533 | return (quit==1)?PLUGIN_OK:PLUGIN_USB_CONNECTED; |
512 | } | 534 | } |
513 | 535 | ||
514 | #endif | 536 | #endif |