diff options
Diffstat (limited to 'apps/plugins/star.c')
-rw-r--r-- | apps/plugins/star.c | 141 |
1 files changed, 113 insertions, 28 deletions
diff --git a/apps/plugins/star.c b/apps/plugins/star.c index c2ce2e7d83..88cc283106 100644 --- a/apps/plugins/star.c +++ b/apps/plugins/star.c | |||
@@ -37,16 +37,9 @@ PLUGIN_HEADER | |||
37 | #define STAR_WIDTH 16 | 37 | #define STAR_WIDTH 16 |
38 | #define STAR_HEIGHT 9 | 38 | #define STAR_HEIGHT 9 |
39 | 39 | ||
40 | /* left and top margin */ | ||
41 | #define STAR_OFFSET_X 8 | ||
42 | #define STAR_OFFSET_Y 0 | ||
43 | |||
44 | /* number of level */ | 40 | /* number of level */ |
45 | #define STAR_LEVEL_COUNT 20 | 41 | #define STAR_LEVEL_COUNT 20 |
46 | 42 | ||
47 | /* size of a tile */ | ||
48 | #define STAR_TILE_SIZE 6 | ||
49 | |||
50 | /* values of object in the board */ | 43 | /* values of object in the board */ |
51 | #define STAR_VOID '.' | 44 | #define STAR_VOID '.' |
52 | #define STAR_WALL '*' | 45 | #define STAR_WALL '*' |
@@ -155,6 +148,38 @@ static int control; | |||
155 | /* the current board */ | 148 | /* the current board */ |
156 | static char board[STAR_HEIGHT][STAR_WIDTH]; | 149 | static char board[STAR_HEIGHT][STAR_WIDTH]; |
157 | 150 | ||
151 | #ifdef HAVE_LCD_COLOR | ||
152 | |||
153 | extern const fb_data star_tiles[]; | ||
154 | |||
155 | /* size of a tile */ | ||
156 | #if LCD_WIDTH >= 320 | ||
157 | # define STAR_TILE_SIZE 20 | ||
158 | #elif LCD_WIDTH >= 220 | ||
159 | # define STAR_TILE_SIZE 13 | ||
160 | #else | ||
161 | # define STAR_TILE_SIZE 10 | ||
162 | #endif | ||
163 | |||
164 | /* left and top margin */ | ||
165 | #define STAR_OFFSET_X ( ( LCD_WIDTH - STAR_WIDTH * STAR_TILE_SIZE ) / 2 ) | ||
166 | #define STAR_OFFSET_Y ( ( LCD_HEIGHT - ( STAR_HEIGHT + 1 ) * STAR_TILE_SIZE ) / 2 ) | ||
167 | |||
168 | #define wall 0 | ||
169 | #define space 1 | ||
170 | #define block 2 | ||
171 | #define star 3 | ||
172 | #define ball 4 | ||
173 | |||
174 | #else | ||
175 | |||
176 | /* left and top margin */ | ||
177 | #define STAR_OFFSET_X 8 | ||
178 | #define STAR_OFFSET_Y 0 | ||
179 | |||
180 | /* size of a tile */ | ||
181 | #define STAR_TILE_SIZE 6 | ||
182 | |||
158 | /* bitmap of the wall */ | 183 | /* bitmap of the wall */ |
159 | static unsigned char wall_bmp[STAR_TILE_SIZE] | 184 | static unsigned char wall_bmp[STAR_TILE_SIZE] |
160 | = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}; | 185 | = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55}; |
@@ -171,6 +196,8 @@ static unsigned char ball_bmp[STAR_TILE_SIZE] | |||
171 | static unsigned char block_bmp[STAR_TILE_SIZE] | 196 | static unsigned char block_bmp[STAR_TILE_SIZE] |
172 | = {0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00}; | 197 | = {0x00, 0x1e, 0x1e, 0x1e, 0x1e, 0x00}; |
173 | 198 | ||
199 | #endif | ||
200 | |||
174 | /* bitmap of the arrow animation */ | 201 | /* bitmap of the arrow animation */ |
175 | static unsigned char arrow_bmp[4][7] = | 202 | static unsigned char arrow_bmp[4][7] = |
176 | { | 203 | { |
@@ -523,13 +550,26 @@ static void star_transition_update(void) | |||
523 | */ | 550 | */ |
524 | static void star_display_board_info(void) | 551 | static void star_display_board_info(void) |
525 | { | 552 | { |
526 | int label_offset_y = label_offset_y = LCD_HEIGHT - char_height; | 553 | int label_offset_y = label_offset_y = LCD_HEIGHT - char_height - ( STAR_TILE_SIZE - char_height ) / 2 ; |
527 | char str_info[32]; | 554 | char str_info[32]; |
528 | 555 | ||
529 | rb->snprintf(str_info, sizeof(str_info), "L:%02d S:%02d C:", | 556 | rb->snprintf(str_info, sizeof(str_info), "L:%02d S:%02d C:", |
530 | current_level, star_count); | 557 | current_level, star_count); |
531 | rb->lcd_putsxy(0, label_offset_y, str_info); | 558 | rb->lcd_putsxy(0, label_offset_y, str_info); |
532 | 559 | ||
560 | #if HAVE_LCD_COLOR | ||
561 | if( control == STAR_CONTROL_BALL ) | ||
562 | rb->lcd_bitmap_part( star_tiles, 0, | ||
563 | ball*STAR_TILE_SIZE, STAR_TILE_SIZE, | ||
564 | 107, label_offset_y - ( STAR_TILE_SIZE - char_height ) / 2 + 1, | ||
565 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
566 | else | ||
567 | rb->lcd_bitmap_part( star_tiles, 0, | ||
568 | block*STAR_TILE_SIZE, STAR_TILE_SIZE, | ||
569 | 107, label_offset_y - ( STAR_TILE_SIZE - char_height ) / 2 + 1, | ||
570 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
571 | rb->lcd_update_rect(0, label_offset_y - ( STAR_TILE_SIZE - char_height ) / 2 + 1, LCD_WIDTH, STAR_TILE_SIZE ); | ||
572 | #else | ||
533 | if (control == STAR_CONTROL_BALL) | 573 | if (control == STAR_CONTROL_BALL) |
534 | rb->lcd_mono_bitmap (ball_bmp, 103, label_offset_y + 1, STAR_TILE_SIZE, | 574 | rb->lcd_mono_bitmap (ball_bmp, 103, label_offset_y + 1, STAR_TILE_SIZE, |
535 | STAR_TILE_SIZE); | 575 | STAR_TILE_SIZE); |
@@ -538,6 +578,8 @@ static void star_display_board_info(void) | |||
538 | STAR_TILE_SIZE); | 578 | STAR_TILE_SIZE); |
539 | 579 | ||
540 | rb->lcd_update_rect(0, label_offset_y, LCD_WIDTH, char_height); | 580 | rb->lcd_update_rect(0, label_offset_y, LCD_WIDTH, char_height); |
581 | #endif | ||
582 | |||
541 | } | 583 | } |
542 | 584 | ||
543 | 585 | ||
@@ -562,41 +604,46 @@ static int star_load_level(int current_level) | |||
562 | board[y][x] = *ptr_tab; | 604 | board[y][x] = *ptr_tab; |
563 | switch (*ptr_tab) | 605 | switch (*ptr_tab) |
564 | { | 606 | { |
607 | #if HAVE_LCD_COLOR | ||
608 | # define DRAW_TILE( a ) \ | ||
609 | rb->lcd_bitmap_part( star_tiles, 0, \ | ||
610 | a*STAR_TILE_SIZE, STAR_TILE_SIZE, \ | ||
611 | STAR_OFFSET_X + x * STAR_TILE_SIZE, \ | ||
612 | STAR_OFFSET_Y + y * STAR_TILE_SIZE, \ | ||
613 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
614 | #else | ||
615 | # define DRAW_TILE( a ) \ | ||
616 | rb->lcd_mono_bitmap ( a # bmp, \ | ||
617 | STAR_OFFSET_X + x * STAR_TILE_SIZE, \ | ||
618 | STAR_OFFSET_Y + y * STAR_TILE_SIZE, \ | ||
619 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
620 | #endif | ||
565 | case STAR_VOID: | 621 | case STAR_VOID: |
622 | #ifdef HAVE_LCD_COLOR | ||
623 | DRAW_TILE( space ); | ||
624 | #endif | ||
566 | break; | 625 | break; |
567 | 626 | ||
568 | case STAR_WALL: | 627 | case STAR_WALL: |
569 | rb->lcd_mono_bitmap (wall_bmp, | 628 | DRAW_TILE( wall ); |
570 | STAR_OFFSET_X + x * STAR_TILE_SIZE, | ||
571 | STAR_OFFSET_Y + y * STAR_TILE_SIZE, | ||
572 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
573 | break; | 629 | break; |
574 | 630 | ||
575 | case STAR_STAR: | 631 | case STAR_STAR: |
576 | rb->lcd_mono_bitmap (star_bmp, | 632 | DRAW_TILE( star ); |
577 | STAR_OFFSET_X + x * STAR_TILE_SIZE, | ||
578 | STAR_OFFSET_Y + y * STAR_TILE_SIZE, | ||
579 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
580 | star_count++; | 633 | star_count++; |
581 | break; | 634 | break; |
582 | 635 | ||
583 | case STAR_BALL: | 636 | case STAR_BALL: |
584 | ball_x = x; | 637 | ball_x = x; |
585 | ball_y = y; | 638 | ball_y = y; |
586 | rb->lcd_mono_bitmap (ball_bmp, | 639 | DRAW_TILE( ball ); |
587 | STAR_OFFSET_X + x * STAR_TILE_SIZE, | ||
588 | STAR_OFFSET_Y + y * STAR_TILE_SIZE, | ||
589 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
590 | break; | 640 | break; |
591 | 641 | ||
592 | 642 | ||
593 | case STAR_BLOCK: | 643 | case STAR_BLOCK: |
594 | block_x = x; | 644 | block_x = x; |
595 | block_y = y; | 645 | block_y = y; |
596 | rb->lcd_mono_bitmap (block_bmp, | 646 | DRAW_TILE( block ); |
597 | STAR_OFFSET_X + x * STAR_TILE_SIZE, | ||
598 | STAR_OFFSET_Y + y * STAR_TILE_SIZE, | ||
599 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
600 | break; | 647 | break; |
601 | } | 648 | } |
602 | ptr_tab++; | 649 | ptr_tab++; |
@@ -709,18 +756,35 @@ static int star_run_game(void) | |||
709 | || board[ball_y + move_y][ball_x + move_x] == STAR_STAR)) | 756 | || board[ball_y + move_y][ball_x + move_x] == STAR_STAR)) |
710 | 757 | ||
711 | { | 758 | { |
712 | for (i = 0 ; i < 7 ; i++) | 759 | for (i = 0 ; i <= STAR_TILE_SIZE ; i++) |
713 | { | 760 | { |
761 | #if HAVE_LCD_COLOR | ||
762 | rb->lcd_bitmap_part( | ||
763 | star_tiles, 0, space * STAR_TILE_SIZE, STAR_TILE_SIZE, | ||
764 | STAR_OFFSET_X + ball_x * STAR_TILE_SIZE, | ||
765 | STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE, | ||
766 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
767 | rb->lcd_bitmap_part( | ||
768 | star_tiles, 0, ball * STAR_TILE_SIZE, STAR_TILE_SIZE, | ||
769 | STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i, | ||
770 | STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i, | ||
771 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
772 | rb->lcd_update_rect( | ||
773 | STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * (i>0?i-1:0), | ||
774 | STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * (i>0?i-1:0), | ||
775 | STAR_TILE_SIZE+(i>0?0:1), STAR_TILE_SIZE+(i>0?0:1)); | ||
776 | #else | ||
714 | rb->lcd_mono_bitmap( | 777 | rb->lcd_mono_bitmap( |
715 | ball_bmp, | 778 | ball_bmp, |
716 | STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i, | 779 | STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i, |
717 | STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i, | 780 | STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i, |
718 | STAR_TILE_SIZE, STAR_TILE_SIZE); | 781 | STAR_TILE_SIZE, STAR_TILE_SIZE); |
719 | |||
720 | rb->lcd_update_rect( | 782 | rb->lcd_update_rect( |
721 | STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i, | 783 | STAR_OFFSET_X + ball_x * STAR_TILE_SIZE + move_x * i, |
722 | STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i, | 784 | STAR_OFFSET_Y + ball_y * STAR_TILE_SIZE + move_y * i, |
723 | STAR_TILE_SIZE, STAR_TILE_SIZE); | 785 | STAR_TILE_SIZE, STAR_TILE_SIZE); |
786 | #endif | ||
787 | |||
724 | rb->sleep(STAR_SLEEP); | 788 | rb->sleep(STAR_SLEEP); |
725 | } | 789 | } |
726 | ball_x += move_x; | 790 | ball_x += move_x; |
@@ -741,18 +805,34 @@ static int star_run_game(void) | |||
741 | board[block_y][block_x] = STAR_VOID; | 805 | board[block_y][block_x] = STAR_VOID; |
742 | while (board[block_y + move_y][block_x + move_x] == STAR_VOID) | 806 | while (board[block_y + move_y][block_x + move_x] == STAR_VOID) |
743 | { | 807 | { |
744 | for (i = 0 ; i < 7 ; i++) | 808 | for (i = 0 ; i <= STAR_TILE_SIZE ; i++) |
745 | { | 809 | { |
810 | #if HAVE_LCD_COLOR | ||
811 | rb->lcd_bitmap_part( | ||
812 | star_tiles, 0, space * STAR_TILE_SIZE, STAR_TILE_SIZE, | ||
813 | STAR_OFFSET_X + block_x * STAR_TILE_SIZE, | ||
814 | STAR_OFFSET_Y + block_y * STAR_TILE_SIZE, | ||
815 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
816 | rb->lcd_bitmap_part( | ||
817 | star_tiles, 0, block * STAR_TILE_SIZE, STAR_TILE_SIZE, | ||
818 | STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i, | ||
819 | STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i, | ||
820 | STAR_TILE_SIZE, STAR_TILE_SIZE); | ||
821 | rb->lcd_update_rect( | ||
822 | STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * (i>0?i-1:0), | ||
823 | STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * (i>0?i-1:0), | ||
824 | STAR_TILE_SIZE+(i>0?0:1), STAR_TILE_SIZE+(i>0?0:1)); | ||
825 | #else | ||
746 | rb->lcd_mono_bitmap( | 826 | rb->lcd_mono_bitmap( |
747 | block_bmp, | 827 | block_bmp, |
748 | STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i, | 828 | STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i, |
749 | STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i, | 829 | STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i, |
750 | STAR_TILE_SIZE, STAR_TILE_SIZE); | 830 | STAR_TILE_SIZE, STAR_TILE_SIZE); |
751 | |||
752 | rb->lcd_update_rect( | 831 | rb->lcd_update_rect( |
753 | STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i, | 832 | STAR_OFFSET_X + block_x * STAR_TILE_SIZE + move_x * i, |
754 | STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i, | 833 | STAR_OFFSET_Y + block_y * STAR_TILE_SIZE + move_y * i, |
755 | STAR_TILE_SIZE, STAR_TILE_SIZE); | 834 | STAR_TILE_SIZE, STAR_TILE_SIZE); |
835 | #endif | ||
756 | 836 | ||
757 | rb->sleep(STAR_SLEEP); | 837 | rb->sleep(STAR_SLEEP); |
758 | } | 838 | } |
@@ -912,6 +992,11 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) | |||
912 | if (char_width == -1) | 992 | if (char_width == -1) |
913 | rb->lcd_getstringsize("a", &char_width, &char_height); | 993 | rb->lcd_getstringsize("a", &char_width, &char_height); |
914 | 994 | ||
995 | #ifdef HAVE_LCD_COLOR | ||
996 | rb->lcd_set_background( LCD_BLACK ); | ||
997 | rb->lcd_set_foreground( LCD_WHITE ); | ||
998 | #endif | ||
999 | |||
915 | /* display choice menu */ | 1000 | /* display choice menu */ |
916 | return star_menu(); | 1001 | return star_menu(); |
917 | } | 1002 | } |