diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-09-10 22:55:10 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-09-10 22:55:10 +0000 |
commit | 61aa70c4831d10f1ff7a5a2ab773b8723de08d13 (patch) | |
tree | eddcffd0f0fc3862596762ef60b42e627ba0e9f4 /apps | |
parent | 3afaec3ead7503e2904cb1b2b676bed2b3d09907 (diff) | |
download | rockbox-61aa70c4831d10f1ff7a5a2ab773b8723de08d13.tar.gz rockbox-61aa70c4831d10f1ff7a5a2ab773b8723de08d13.zip |
Code police and keep backlight on while in mazezam
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14667 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/maze.c | 5 | ||||
-rw-r--r-- | apps/plugins/mazezam.c | 157 |
2 files changed, 108 insertions, 54 deletions
diff --git a/apps/plugins/maze.c b/apps/plugins/maze.c index b5d4f08e9f..2948eb2aec 100644 --- a/apps/plugins/maze.c +++ b/apps/plugins/maze.c | |||
@@ -112,7 +112,7 @@ void coord_stack_push(struct coord_stack* stack, int x, int y) | |||
112 | } | 112 | } |
113 | 113 | ||
114 | void coord_stack_get(struct coord_stack* stack, int index, int* x, int* y) | 114 | void coord_stack_get(struct coord_stack* stack, int index, int* x, int* y) |
115 | { | 115 | { |
116 | *y = stack->data[index]; | 116 | *y = stack->data[index]; |
117 | *y &= 0xff; | 117 | *y &= 0xff; |
118 | *x = (stack->data[index])>>8; | 118 | *x = (stack->data[index])>>8; |
@@ -390,7 +390,8 @@ void maze_solve(struct maze* maze) | |||
390 | maze->solved = ~(maze->solved); | 390 | maze->solved = ~(maze->solved); |
391 | 391 | ||
392 | /* copy maze for solving */ | 392 | /* copy maze for solving */ |
393 | rb->memcpy(solved_maze, maze->maze, (MAZE_HEIGHT*MAZE_WIDTH*sizeof(maze->maze[0][0]))); | 393 | rb->memcpy(solved_maze, maze->maze, |
394 | (MAZE_HEIGHT*MAZE_WIDTH*sizeof(maze->maze[0][0]))); | ||
394 | 395 | ||
395 | 396 | ||
396 | /* remove some borders and walls on start and end point */ | 397 | /* remove some borders and walls on start and end point */ |
diff --git a/apps/plugins/mazezam.c b/apps/plugins/mazezam.c index e00049e3b9..48c564ab8a 100644 --- a/apps/plugins/mazezam.c +++ b/apps/plugins/mazezam.c | |||
@@ -20,6 +20,7 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "plugin.h" | 21 | #include "plugin.h" |
22 | #include "configfile.h" | 22 | #include "configfile.h" |
23 | #include "helper.h" | ||
23 | 24 | ||
24 | /* Include standard plugin macro */ | 25 | /* Include standard plugin macro */ |
25 | PLUGIN_HEADER | 26 | PLUGIN_HEADER |
@@ -225,7 +226,8 @@ static const struct textpage title_page = { | |||
225 | static const struct textpage help_page[] = { | 226 | static const struct textpage help_page[] = { |
226 | {4,{"Instructions","10 mazezams","bar your way","to freedom"}}, | 227 | {4,{"Instructions","10 mazezams","bar your way","to freedom"}}, |
227 | {4,{"Instructions","Push the rows","left and right","to escape"}}, | 228 | {4,{"Instructions","Push the rows","left and right","to escape"}}, |
228 | {4,{"Instructions","Press " MAZEZAM_RETRY_KEYNAME " to","retry a level","(lose 1 life)"}}, | 229 | {4,{"Instructions","Press " MAZEZAM_RETRY_KEYNAME " to","retry a level", |
230 | "(lose 1 life)"}}, | ||
229 | {4,{"Instructions","Press " MAZEZAM_QUIT_KEYNAME,"to quit","the game"}} | 231 | {4,{"Instructions","Press " MAZEZAM_QUIT_KEYNAME,"to quit","the game"}} |
230 | }; | 232 | }; |
231 | 233 | ||
@@ -367,7 +369,8 @@ struct resume_data { | |||
367 | /* Display a screen of text. line[0] is the heading. | 369 | /* Display a screen of text. line[0] is the heading. |
368 | * line[highlight] will be highlighted, unless highlight == 0 | 370 | * line[highlight] will be highlighted, unless highlight == 0 |
369 | */ | 371 | */ |
370 | static void display_text_page(struct textpage text, int highlight) { | 372 | static void display_text_page(struct textpage text, int highlight) |
373 | { | ||
371 | int w[text.num_lines], h[text.num_lines]; | 374 | int w[text.num_lines], h[text.num_lines]; |
372 | int hsum,i,vgap,vnext; | 375 | int hsum,i,vgap,vnext; |
373 | 376 | ||
@@ -390,13 +393,15 @@ static void display_text_page(struct textpage text, int highlight) { | |||
390 | rb->lcd_set_foreground(MAZEZAM_BORDER_GRAY); | 393 | rb->lcd_set_foreground(MAZEZAM_BORDER_GRAY); |
391 | #endif | 394 | #endif |
392 | rb->lcd_drawrect((LCD_WIDTH-w[0])/2-MAZEZAM_MENU_BORDER, | 395 | rb->lcd_drawrect((LCD_WIDTH-w[0])/2-MAZEZAM_MENU_BORDER, |
393 | vgap-MAZEZAM_MENU_BORDER, w[0] + 2*MAZEZAM_MENU_BORDER, | 396 | vgap-MAZEZAM_MENU_BORDER, w[0] + 2*MAZEZAM_MENU_BORDER, |
394 | h[0] + 2*MAZEZAM_MENU_BORDER); | 397 | h[0] + 2*MAZEZAM_MENU_BORDER); |
395 | rb->lcd_drawrect((LCD_WIDTH-w[0])/2-MAZEZAM_MENU_BORDER*2, | 398 | rb->lcd_drawrect((LCD_WIDTH-w[0])/2-MAZEZAM_MENU_BORDER*2, |
396 | vgap-MAZEZAM_MENU_BORDER*2, w[0] + 4*MAZEZAM_MENU_BORDER, | 399 | vgap-MAZEZAM_MENU_BORDER*2, w[0] + 4*MAZEZAM_MENU_BORDER, |
397 | h[0] + 4*MAZEZAM_MENU_BORDER); | 400 | h[0] + 4*MAZEZAM_MENU_BORDER); |
398 | rb->lcd_drawline(0,vgap + h[0]/2,(LCD_WIDTH-w[0])/2-MAZEZAM_MENU_BORDER*2,vgap + h[0]/2); | 401 | rb->lcd_drawline(0,vgap + h[0]/2,(LCD_WIDTH-w[0])/2-MAZEZAM_MENU_BORDER*2, |
399 | rb->lcd_drawline((LCD_WIDTH-w[0])/2+w[0]+MAZEZAM_MENU_BORDER*2,vgap + h[0]/2,LCD_WIDTH-1,vgap + h[0]/2); | 402 | vgap + h[0]/2); |
403 | rb->lcd_drawline((LCD_WIDTH-w[0])/2+w[0]+MAZEZAM_MENU_BORDER*2, | ||
404 | vgap + h[0]/2,LCD_WIDTH-1,vgap + h[0]/2); | ||
400 | #ifdef HAVE_LCD_COLOR | 405 | #ifdef HAVE_LCD_COLOR |
401 | rb->lcd_set_foreground(MAZEZAM_HEADING_COLOR); | 406 | rb->lcd_set_foreground(MAZEZAM_HEADING_COLOR); |
402 | #elif LCD_DEPTH > 1 | 407 | #elif LCD_DEPTH > 1 |
@@ -433,7 +438,8 @@ static void display_text_page(struct textpage text, int highlight) { | |||
433 | * replaced by a file read. Returns true if the level parsed correctly. | 438 | * replaced by a file read. Returns true if the level parsed correctly. |
434 | */ | 439 | */ |
435 | static bool parse_level(short level, struct chunk_data *cd, | 440 | static bool parse_level(short level, struct chunk_data *cd, |
436 | short *width, short *height, short *entrance, short *exit) { | 441 | short *width, short *height, short *entrance, short *exit) |
442 | { | ||
437 | int i,j; | 443 | int i,j; |
438 | char c,clast; | 444 | char c,clast; |
439 | 445 | ||
@@ -479,7 +485,8 @@ static void draw_level( | |||
479 | short entrance, | 485 | short entrance, |
480 | short exit, | 486 | short exit, |
481 | short x, /* player's x and y coords */ | 487 | short x, /* player's x and y coords */ |
482 | short y) { | 488 | short y) |
489 | { | ||
483 | /* The number of pixels the side of a square should be */ | 490 | /* The number of pixels the side of a square should be */ |
484 | short size = (LCD_WIDTH/(width+2)) < (LCD_HEIGHT/height) ? | 491 | short size = (LCD_WIDTH/(width+2)) < (LCD_HEIGHT/height) ? |
485 | (LCD_WIDTH/(width+2)) : (LCD_HEIGHT/height); | 492 | (LCD_WIDTH/(width+2)) : (LCD_HEIGHT/height); |
@@ -513,15 +520,20 @@ static void draw_level( | |||
513 | /* draw the upper wall */ | 520 | /* draw the upper wall */ |
514 | rb->lcd_fillrect(0,0,xOff,yOff+(size*entrance)); | 521 | rb->lcd_fillrect(0,0,xOff,yOff+(size*entrance)); |
515 | rb->lcd_fillrect(xOff,0,size*width,yOff); | 522 | rb->lcd_fillrect(xOff,0,size*width,yOff); |
516 | rb->lcd_fillrect(xOff+(size*width),0,LCD_WIDTH-xOff-(size*width),yOff+(size*exit)); | 523 | rb->lcd_fillrect(xOff+(size*width),0,LCD_WIDTH-xOff-(size*width), |
524 | yOff+(size*exit)); | ||
517 | 525 | ||
518 | /* draw the lower wall */ | 526 | /* draw the lower wall */ |
519 | rb->lcd_fillrect(0,yOff+(size*entrance)+size,xOff,LCD_HEIGHT-yOff-(size*entrance)-size); | 527 | rb->lcd_fillrect(0,yOff+(size*entrance)+size,xOff, |
520 | rb->lcd_fillrect(xOff,yOff+(size*height),size*width,LCD_HEIGHT-yOff-(size*height)); | 528 | LCD_HEIGHT-yOff-(size*entrance)-size); |
529 | rb->lcd_fillrect(xOff,yOff+(size*height),size*width, | ||
530 | LCD_HEIGHT-yOff-(size*height)); | ||
521 | /* Note: the exit is made one pixel thinner than necessary as a visual | 531 | /* Note: the exit is made one pixel thinner than necessary as a visual |
522 | * clue that chunks cannot be pushed into it | 532 | * clue that chunks cannot be pushed into it |
523 | */ | 533 | */ |
524 | rb->lcd_fillrect(xOff+(size*width),yOff+(size*exit)+size-1,LCD_WIDTH-xOff+(size*width),LCD_HEIGHT-yOff-(size*exit)-size+1); | 534 | rb->lcd_fillrect(xOff+(size*width),yOff+(size*exit)+size-1, |
535 | LCD_WIDTH-xOff+(size*width), | ||
536 | LCD_HEIGHT-yOff-(size*exit)-size+1); | ||
525 | 537 | ||
526 | /* draw the chunks */ | 538 | /* draw the chunks */ |
527 | for (i = 0; i<height; i++) { | 539 | for (i = 0; i<height; i++) { |
@@ -529,35 +541,47 @@ static void draw_level( | |||
529 | /* adding width to i should have a fixed, but randomising effect on | 541 | /* adding width to i should have a fixed, but randomising effect on |
530 | * the choice of the colours of the top line of chunks | 542 | * the choice of the colours of the top line of chunks |
531 | */ | 543 | */ |
532 | rb->lcd_set_foreground(chunk_colors[(i+width) % MAZEZAM_NUM_CHUNK_COLORS]); | 544 | rb->lcd_set_foreground(chunk_colors[(i+width) % |
545 | MAZEZAM_NUM_CHUNK_COLORS]); | ||
533 | #endif | 546 | #endif |
534 | for (j = 0; j<cd->l_num[i]; j++) { | 547 | for (j = 0; j<cd->l_num[i]; j++) { |
535 | #ifdef HAVE_LCD_COLOR | 548 | #ifdef HAVE_LCD_COLOR |
536 | rb->lcd_fillrect(xOff+size*shift[i]+size*cd->c_inset[i][j],yOff+size*i, | 549 | rb->lcd_fillrect(xOff+size*shift[i]+size*cd->c_inset[i][j], |
537 | cd->c_width[i][j]*size,size); | 550 | yOff+size*i, cd->c_width[i][j]*size,size); |
538 | #elif LCD_DEPTH > 1 | 551 | #elif LCD_DEPTH > 1 |
539 | rb->lcd_set_foreground(MAZEZAM_CHUNK_EDGE_GRAY); | 552 | rb->lcd_set_foreground(MAZEZAM_CHUNK_EDGE_GRAY); |
540 | rb->lcd_drawrect(xOff+size*shift[i]+size*cd->c_inset[i][j],yOff+size*i, | 553 | rb->lcd_drawrect(xOff+size*shift[i]+size*cd->c_inset[i][j], |
541 | cd->c_width[i][j]*size,size); | 554 | yOff+size*i, cd->c_width[i][j]*size,size); |
542 | 555 | ||
543 | /* draw shade */ | 556 | /* draw shade */ |
544 | rb->lcd_set_foreground(chunk_gray_shade[(i+width) % MAZEZAM_NUM_CHUNK_GRAYS]); | 557 | rb->lcd_set_foreground(chunk_gray_shade[(i+width) % |
545 | rb->lcd_drawline(xOff+size*shift[i]+size*cd->c_inset[i][j]+1,yOff+size*i+size-2, | 558 | MAZEZAM_NUM_CHUNK_GRAYS]); |
546 | xOff+size*shift[i]+size*cd->c_inset[i][j]+cd->c_width[i][j]*size-3,yOff+size*i+size-2); | 559 | rb->lcd_drawline(xOff+size*shift[i]+size*cd->c_inset[i][j]+1, |
547 | rb->lcd_drawline(xOff+size*shift[i]+size*cd->c_inset[i][j]+cd->c_width[i][j]*size-2,yOff+size*i, | 560 | yOff+size*i+size-2, |
548 | xOff+size*shift[i]+size*cd->c_inset[i][j]+cd->c_width[i][j]*size-2,yOff+size*i+size-2); | 561 | xOff+size*shift[i]+size*cd->c_inset[i][j]+ |
562 | cd->c_width[i][j]*size-3, | ||
563 | yOff+size*i+size-2); | ||
564 | rb->lcd_drawline(xOff+size*shift[i]+size*cd->c_inset[i][j]+ | ||
565 | cd->c_width[i][j]*size-2, | ||
566 | yOff+size*i, | ||
567 | xOff+size*shift[i]+size*cd->c_inset[i][j]+ | ||
568 | cd->c_width[i][j]*size-2, | ||
569 | yOff+size*i+size-2); | ||
549 | 570 | ||
550 | /* draw fill */ | 571 | /* draw fill */ |
551 | rb->lcd_set_foreground(chunk_gray[(i+width) % MAZEZAM_NUM_CHUNK_GRAYS]); | 572 | rb->lcd_set_foreground(chunk_gray[(i+width) % |
573 | MAZEZAM_NUM_CHUNK_GRAYS]); | ||
552 | for (k = yOff+size*i+2; k < yOff+size*i+size-2; k += 2) | 574 | for (k = yOff+size*i+2; k < yOff+size*i+size-2; k += 2) |
553 | rb->lcd_drawline(xOff+size*shift[i]+size*cd->c_inset[i][j]+2,k, | 575 | rb->lcd_drawline(xOff+size*shift[i]+size*cd->c_inset[i][j]+2,k, |
554 | xOff+size*shift[i]+size*cd->c_inset[i][j]+cd->c_width[i][j]*size-3,k); | 576 | xOff+size*shift[i]+size*cd->c_inset[i][j]+ |
577 | cd->c_width[i][j]*size-3,k); | ||
555 | #else | 578 | #else |
556 | rb->lcd_drawrect(xOff+size*shift[i]+size*cd->c_inset[i][j],yOff+size*i, | 579 | rb->lcd_drawrect(xOff+size*shift[i]+size*cd->c_inset[i][j], |
557 | cd->c_width[i][j]*size,size); | 580 | yOff+size*i, cd->c_width[i][j]*size,size); |
558 | for (k = xOff+size*shift[i]+size*cd->c_inset[i][j]+2; | 581 | for (k = xOff+size*shift[i]+size*cd->c_inset[i][j]+2; |
559 | k < xOff+size*shift[i]+size*cd->c_inset[i][j]+cd->c_width[i][j]*size; | 582 | k < xOff+size*shift[i]+size*cd->c_inset[i][j]+ |
560 | k += 2 + (i & 1)) | 583 | cd->c_width[i][j]*size; |
584 | k += 2 + (i & 1)) | ||
561 | for (l = yOff+size*i+2; l < yOff+size*i+size; l += 2 + (i & 1)) | 585 | for (l = yOff+size*i+2; l < yOff+size*i+size; l += 2 + (i & 1)) |
562 | rb->lcd_drawpixel(k, l); | 586 | rb->lcd_drawpixel(k, l); |
563 | #endif | 587 | #endif |
@@ -598,7 +622,8 @@ static void draw_level( | |||
598 | } | 622 | } |
599 | 623 | ||
600 | /* Manage the congratulations screen */ | 624 | /* Manage the congratulations screen */ |
601 | static enum text_state welldone_screen(void) { | 625 | static enum text_state welldone_screen(void) |
626 | { | ||
602 | int button = BUTTON_NONE; | 627 | int button = BUTTON_NONE; |
603 | enum text_state state = TEXT_STATE_LOOPING; | 628 | enum text_state state = TEXT_STATE_LOOPING; |
604 | 629 | ||
@@ -630,7 +655,8 @@ static enum text_state welldone_screen(void) { | |||
630 | } | 655 | } |
631 | 656 | ||
632 | /* Manage the quit confimation screen */ | 657 | /* Manage the quit confimation screen */ |
633 | static enum text_state quitconfirm_loop(void) { | 658 | static enum text_state quitconfirm_loop(void) |
659 | { | ||
634 | int button = BUTTON_NONE; | 660 | int button = BUTTON_NONE; |
635 | enum text_state state = TEXT_STATE_LOOPING; | 661 | enum text_state state = TEXT_STATE_LOOPING; |
636 | short select = 2; | 662 | short select = 2; |
@@ -678,7 +704,8 @@ static enum text_state quitconfirm_loop(void) { | |||
678 | } | 704 | } |
679 | 705 | ||
680 | /* Manage the playing of a level */ | 706 | /* Manage the playing of a level */ |
681 | static enum level_state level_loop(short level, short lives) { | 707 | static enum level_state level_loop(short level, short lives) |
708 | { | ||
682 | struct chunk_data cd; | 709 | struct chunk_data cd; |
683 | short shift[MAZEZAM_MAX_LINES]; /* amount each line has been shifted */ | 710 | short shift[MAZEZAM_MAX_LINES]; /* amount each line has been shifted */ |
684 | short width; | 711 | short width; |
@@ -708,7 +735,8 @@ static enum level_state level_loop(short level, short lives) { | |||
708 | */ | 735 | */ |
709 | rb->lcd_remote_clear_display(); | 736 | rb->lcd_remote_clear_display(); |
710 | #endif | 737 | #endif |
711 | rb->splash(MAZEZAM_LEVEL_LIVES_DELAY, MAZEZAM_LEVEL_LIVES_TEXT, level+1, lives); | 738 | rb->splash(MAZEZAM_LEVEL_LIVES_DELAY, MAZEZAM_LEVEL_LIVES_TEXT, |
739 | level+1, lives); | ||
712 | 740 | ||
713 | /* ensure keys pressed during the splash screen are ignored */ | 741 | /* ensure keys pressed during the splash screen are ignored */ |
714 | rb->button_clear_queue(); | 742 | rb->button_clear_queue(); |
@@ -724,8 +752,10 @@ static enum level_state level_loop(short level, short lives) { | |||
724 | case MAZEZAM_UP | BUTTON_REPEAT: | 752 | case MAZEZAM_UP | BUTTON_REPEAT: |
725 | if ((y > 0) && (x >= 0) && (x < width)) { | 753 | if ((y > 0) && (x >= 0) && (x < width)) { |
726 | for (i = 0; i < cd.l_num[y-1]; i++) | 754 | for (i = 0; i < cd.l_num[y-1]; i++) |
727 | blocked = blocked || ((x>=shift[y-1]+cd.c_inset[y-1][i]) | 755 | blocked = blocked || |
728 | && (x<shift[y-1]+cd.c_inset[y-1][i]+cd.c_width[y-1][i])); | 756 | ((x>=shift[y-1]+cd.c_inset[y-1][i]) && |
757 | (x<shift[y-1]+cd.c_inset[y-1][i]+ | ||
758 | cd.c_width[y-1][i])); | ||
729 | if (!blocked) y -= 1; | 759 | if (!blocked) y -= 1; |
730 | } | 760 | } |
731 | break; | 761 | break; |
@@ -734,8 +764,10 @@ static enum level_state level_loop(short level, short lives) { | |||
734 | case MAZEZAM_DOWN | BUTTON_REPEAT: | 764 | case MAZEZAM_DOWN | BUTTON_REPEAT: |
735 | if ((y < height-1) && (x >= 0) && (x < width)) { | 765 | if ((y < height-1) && (x >= 0) && (x < width)) { |
736 | for (i = 0; i < cd.l_num[y+1]; i++) | 766 | for (i = 0; i < cd.l_num[y+1]; i++) |
737 | blocked = blocked || ((x>=shift[y+1]+cd.c_inset[y+1][i]) | 767 | blocked = blocked || |
738 | && (x<shift[y+1]+cd.c_inset[y+1][i]+cd.c_width[y+1][i])); | 768 | ((x>=shift[y+1]+cd.c_inset[y+1][i]) && |
769 | (x<shift[y+1]+cd.c_inset[y+1][i]+ | ||
770 | cd.c_width[y+1][i])); | ||
739 | if (!blocked) y += 1; | 771 | if (!blocked) y += 1; |
740 | } | 772 | } |
741 | break; | 773 | break; |
@@ -744,7 +776,9 @@ static enum level_state level_loop(short level, short lives) { | |||
744 | case MAZEZAM_LEFT | BUTTON_REPEAT: | 776 | case MAZEZAM_LEFT | BUTTON_REPEAT: |
745 | if (x > 0) { | 777 | if (x > 0) { |
746 | for (i = 0; i < cd.l_num[y]; i++) | 778 | for (i = 0; i < cd.l_num[y]; i++) |
747 | blocked = blocked || (x == shift[y]+cd.c_inset[y][i]+cd.c_width[y][i]); | 779 | blocked = blocked || |
780 | (x == shift[y]+cd.c_inset[y][i]+ | ||
781 | cd.c_width[y][i]); | ||
748 | if (!blocked) x -= 1; | 782 | if (!blocked) x -= 1; |
749 | else if (shift[y] + cd.c_inset[y][0] > 0) { | 783 | else if (shift[y] + cd.c_inset[y][0] > 0) { |
750 | x -= 1; | 784 | x -= 1; |
@@ -759,7 +793,8 @@ static enum level_state level_loop(short level, short lives) { | |||
759 | for (i = 0; i < cd.l_num[y]; i++) | 793 | for (i = 0; i < cd.l_num[y]; i++) |
760 | blocked = blocked || (x+1 == shift[y]+cd.c_inset[y][i]); | 794 | blocked = blocked || (x+1 == shift[y]+cd.c_inset[y][i]); |
761 | if (!blocked) x += 1; | 795 | if (!blocked) x += 1; |
762 | else if (shift[y] + cd.c_inset[y][cd.l_num[y]-1] + cd.c_width[y][cd.l_num[y]-1] < width) { | 796 | else if (shift[y] + cd.c_inset[y][cd.l_num[y]-1] + |
797 | cd.c_width[y][cd.l_num[y]-1] < width) { | ||
763 | x += 1; | 798 | x += 1; |
764 | shift[y] += 1; | 799 | shift[y] += 1; |
765 | } | 800 | } |
@@ -798,7 +833,8 @@ static enum level_state level_loop(short level, short lives) { | |||
798 | } | 833 | } |
799 | 834 | ||
800 | /* The loop which manages a full game of MazezaM */ | 835 | /* The loop which manages a full game of MazezaM */ |
801 | static enum game_state game_loop(struct resume_data *r) { | 836 | static enum game_state game_loop(struct resume_data *r) |
837 | { | ||
802 | enum game_state state = GAME_STATE_LOOPING; | 838 | enum game_state state = GAME_STATE_LOOPING; |
803 | int level = r->level; | 839 | int level = r->level; |
804 | int lives = MAZEZAM_START_LIVES; | 840 | int lives = MAZEZAM_START_LIVES; |
@@ -880,7 +916,8 @@ static enum game_state game_loop(struct resume_data *r) { | |||
880 | } | 916 | } |
881 | 917 | ||
882 | /* Manage the instruction screen */ | 918 | /* Manage the instruction screen */ |
883 | static enum text_state instruction_loop(void) { | 919 | static enum text_state instruction_loop(void) |
920 | { | ||
884 | int button; | 921 | int button; |
885 | enum text_state state = TEXT_STATE_LOOPING; | 922 | enum text_state state = TEXT_STATE_LOOPING; |
886 | int page = 0; | 923 | int page = 0; |
@@ -922,7 +959,8 @@ static enum text_state instruction_loop(void) { | |||
922 | /* Manage the text screen that offers the user the option of | 959 | /* Manage the text screen that offers the user the option of |
923 | * resuming or starting a new game | 960 | * resuming or starting a new game |
924 | */ | 961 | */ |
925 | static enum text_state resume_game_loop (struct resume_data *r) { | 962 | static enum text_state resume_game_loop (struct resume_data *r) |
963 | { | ||
926 | int button = BUTTON_NONE; | 964 | int button = BUTTON_NONE; |
927 | enum text_state state = TEXT_STATE_LOOPING; | 965 | enum text_state state = TEXT_STATE_LOOPING; |
928 | short select = 0; | 966 | short select = 0; |
@@ -979,12 +1017,15 @@ static enum text_state resume_game_loop (struct resume_data *r) { | |||
979 | /* Load the resume data from the config file. The data is | 1017 | /* Load the resume data from the config file. The data is |
980 | * stored in both r and old. | 1018 | * stored in both r and old. |
981 | */ | 1019 | */ |
982 | static void resume_load_data (struct resume_data *r, struct resume_data *old) { | 1020 | static void resume_load_data (struct resume_data *r, struct resume_data *old) |
1021 | { | ||
983 | struct configdata config[] = { | 1022 | struct configdata config[] = { |
984 | {TYPE_INT,0,MAZEZAM_NUM_LEVELS-1,&(r->level),MAZEZAM_CONFIG_LEVELS_NAME,NULL,NULL} | 1023 | {TYPE_INT,0,MAZEZAM_NUM_LEVELS-1,&(r->level), |
1024 | MAZEZAM_CONFIG_LEVELS_NAME,NULL,NULL} | ||
985 | }; | 1025 | }; |
986 | 1026 | ||
987 | if (configfile_load(MAZEZAM_CONFIG_FILENAME,config,MAZEZAM_CONFIG_NUM_ITEMS,MAZEZAM_CONFIG_VERSION) < 0) | 1027 | if (configfile_load(MAZEZAM_CONFIG_FILENAME,config,MAZEZAM_CONFIG_NUM_ITEMS, |
1028 | MAZEZAM_CONFIG_VERSION) < 0) | ||
988 | r->level = 0; | 1029 | r->level = 0; |
989 | /* an extra precaution */ | 1030 | /* an extra precaution */ |
990 | else if ((r->level < 0) || (MAZEZAM_NUM_LEVELS <= r->level)) | 1031 | else if ((r->level < 0) || (MAZEZAM_NUM_LEVELS <= r->level)) |
@@ -994,20 +1035,24 @@ static void resume_load_data (struct resume_data *r, struct resume_data *old) { | |||
994 | } | 1035 | } |
995 | 1036 | ||
996 | /* Save the resume data in the config file, but only if necessary */ | 1037 | /* Save the resume data in the config file, but only if necessary */ |
997 | static void resume_save_data (struct resume_data *r, struct resume_data *old) { | 1038 | static void resume_save_data (struct resume_data *r, struct resume_data *old) |
1039 | { | ||
998 | struct configdata config[] = { | 1040 | struct configdata config[] = { |
999 | {TYPE_INT,0,MAZEZAM_NUM_LEVELS-1,&(r->level),MAZEZAM_CONFIG_LEVELS_NAME,NULL,NULL} | 1041 | {TYPE_INT,0,MAZEZAM_NUM_LEVELS-1,&(r->level), |
1042 | MAZEZAM_CONFIG_LEVELS_NAME,NULL,NULL} | ||
1000 | }; | 1043 | }; |
1001 | 1044 | ||
1002 | /* To reduce disk usage, only write the file if the resume data has | 1045 | /* To reduce disk usage, only write the file if the resume data has |
1003 | * changed. | 1046 | * changed. |
1004 | */ | 1047 | */ |
1005 | if (old->level != r->level) | 1048 | if (old->level != r->level) |
1006 | configfile_save(MAZEZAM_CONFIG_FILENAME,config,MAZEZAM_CONFIG_NUM_ITEMS,MAZEZAM_CONFIG_MINVERSION); | 1049 | configfile_save(MAZEZAM_CONFIG_FILENAME,config,MAZEZAM_CONFIG_NUM_ITEMS, |
1050 | MAZEZAM_CONFIG_MINVERSION); | ||
1007 | } | 1051 | } |
1008 | 1052 | ||
1009 | /* The loop which manages the welcome screen and menu */ | 1053 | /* The loop which manages the welcome screen and menu */ |
1010 | static enum text_state welcome_loop(void) { | 1054 | static enum text_state welcome_loop(void) |
1055 | { | ||
1011 | int button; | 1056 | int button; |
1012 | short select = 0; | 1057 | short select = 0; |
1013 | enum text_state state = TEXT_STATE_LOOPING; | 1058 | enum text_state state = TEXT_STATE_LOOPING; |
@@ -1026,7 +1071,8 @@ static enum text_state welcome_loop(void) { | |||
1026 | break; | 1071 | break; |
1027 | 1072 | ||
1028 | case MAZEZAM_UP: | 1073 | case MAZEZAM_UP: |
1029 | select = (select + (title_page.num_lines - 2)) % (title_page.num_lines - 1); | 1074 | select = (select + (title_page.num_lines - 2)) % |
1075 | (title_page.num_lines - 1); | ||
1030 | break; | 1076 | break; |
1031 | 1077 | ||
1032 | case MAZEZAM_DOWN: | 1078 | case MAZEZAM_DOWN: |
@@ -1106,13 +1152,17 @@ static enum text_state welcome_loop(void) { | |||
1106 | } | 1152 | } |
1107 | 1153 | ||
1108 | /* Plugin entry point */ | 1154 | /* Plugin entry point */ |
1109 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { | 1155 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter) |
1156 | { | ||
1110 | enum plugin_status state; | 1157 | enum plugin_status state; |
1111 | 1158 | ||
1112 | /* Usual plugin stuff */ | 1159 | /* Usual plugin stuff */ |
1113 | (void)parameter; | 1160 | (void)parameter; |
1114 | rb = api; | 1161 | rb = api; |
1115 | 1162 | ||
1163 | /* Turn off backlight timeout */ | ||
1164 | backlight_force_on(rb); /* backlight control in lib/helper.c */ | ||
1165 | |||
1116 | #ifdef HAVE_LCD_COLOR | 1166 | #ifdef HAVE_LCD_COLOR |
1117 | rb->lcd_set_background(MAZEZAM_BG_COLOR); | 1167 | rb->lcd_set_background(MAZEZAM_BG_COLOR); |
1118 | rb->lcd_set_backdrop(NULL); | 1168 | rb->lcd_set_backdrop(NULL); |
@@ -1138,5 +1188,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { | |||
1138 | break; | 1188 | break; |
1139 | } | 1189 | } |
1140 | 1190 | ||
1191 | /* Turn on backlight timeout (revert to settings) */ | ||
1192 | backlight_use_settings(rb); /* backlight control in lib/helper.c */ | ||
1193 | |||
1141 | return state; | 1194 | return state; |
1142 | } | 1195 | } |