diff options
-rw-r--r-- | apps/plugins/SOURCES | 2 | ||||
-rw-r--r-- | apps/plugins/bitmaps/native/SOURCES | 2 | ||||
-rw-r--r-- | apps/plugins/lib/highscore.c | 33 | ||||
-rw-r--r-- | apps/plugins/lib/highscore.h | 1 | ||||
-rw-r--r-- | apps/plugins/rockblox.c | 64 |
5 files changed, 97 insertions, 5 deletions
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 413e5217c3..8865a5b24c 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES | |||
@@ -9,7 +9,7 @@ logo.c | |||
9 | mosaique.c | 9 | mosaique.c |
10 | properties.c | 10 | properties.c |
11 | random_folder_advance_config.c | 11 | random_folder_advance_config.c |
12 | #if (LCD_WIDTH != 240) && ((LCD_WIDTH != 128) || (LCD_HEIGHT != 64)) && !defined(SANSA_E200) | 12 | #if !defined(SANSA_E200) |
13 | rockblox.c | 13 | rockblox.c |
14 | #endif | 14 | #endif |
15 | rockbox_flash.c | 15 | rockbox_flash.c |
diff --git a/apps/plugins/bitmaps/native/SOURCES b/apps/plugins/bitmaps/native/SOURCES index be8f2b6889..0521f72d4a 100644 --- a/apps/plugins/bitmaps/native/SOURCES +++ b/apps/plugins/bitmaps/native/SOURCES | |||
@@ -312,6 +312,8 @@ brickmania_break.176x132x16.bmp | |||
312 | /* Rockblox */ | 312 | /* Rockblox */ |
313 | #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240) && (LCD_DEPTH == 16) | 313 | #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240) && (LCD_DEPTH == 16) |
314 | rockblox_background.320x240x16.bmp | 314 | rockblox_background.320x240x16.bmp |
315 | #elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320) && (LCD_DEPTH == 16) | ||
316 | rockblox_background.240x320x16.bmp | ||
315 | #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16) | 317 | #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16) |
316 | rockblox_background.220x176x16.bmp | 318 | rockblox_background.220x176x16.bmp |
317 | #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) && (LCD_DEPTH == 16) | 319 | #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) && (LCD_DEPTH == 16) |
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c index 9fbcdf25a3..df7a71bcdf 100644 --- a/apps/plugins/lib/highscore.c +++ b/apps/plugins/lib/highscore.c | |||
@@ -61,11 +61,12 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores) | |||
61 | char *ptr; | 61 | char *ptr; |
62 | 62 | ||
63 | fd = rb->open(filename, O_RDONLY); | 63 | fd = rb->open(filename, O_RDONLY); |
64 | |||
65 | rb->memset(scores, 0, sizeof(struct highscore)*(num_scores+1)); | ||
66 | |||
64 | if(fd < 0) | 67 | if(fd < 0) |
65 | return -1; | 68 | return -1; |
66 | 69 | ||
67 | rb->memset(scores, 0, sizeof(struct highscore)*num_scores); | ||
68 | |||
69 | i = -1; | 70 | i = -1; |
70 | while(rb->read_line(fd, buf, sizeof(buf)-1) && i < num_scores) | 71 | while(rb->read_line(fd, buf, sizeof(buf)-1) && i < num_scores) |
71 | { | 72 | { |
@@ -97,3 +98,31 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores) | |||
97 | } | 98 | } |
98 | return 0; | 99 | return 0; |
99 | } | 100 | } |
101 | |||
102 | int highscore_update(int score, int level, struct highscore *scores, int num_scores) | ||
103 | { | ||
104 | int i, j; | ||
105 | int new = 0; | ||
106 | |||
107 | /* look through the scores and see if this one is in the top ones */ | ||
108 | for(i = num_scores-1;i >= 0; i--) | ||
109 | { | ||
110 | if ((score > scores[i].score)) | ||
111 | { | ||
112 | /* Move the rest down one... */ | ||
113 | if (i > 0) | ||
114 | { | ||
115 | for (j=1; j<=i; j++) | ||
116 | { | ||
117 | rb->memcpy((void *)&scores[j-1], (void *)&scores[j], sizeof(struct highscore)); | ||
118 | } | ||
119 | } | ||
120 | scores[i].score = score; | ||
121 | scores[i].level = level; | ||
122 | /* Need to sort out entering a name... maybe old three letter arcade style */ | ||
123 | new = 1; | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | return new; | ||
128 | } | ||
diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h index ff192137f3..ba7da241f1 100644 --- a/apps/plugins/lib/highscore.h +++ b/apps/plugins/lib/highscore.h | |||
@@ -29,5 +29,6 @@ struct highscore | |||
29 | void highscore_init(struct plugin_api* newrb); | 29 | void highscore_init(struct plugin_api* newrb); |
30 | int highscore_save(char *filename, struct highscore *scores, int num_scores); | 30 | int highscore_save(char *filename, struct highscore *scores, int num_scores); |
31 | int highscore_load(char *filename, struct highscore *scores, int num_scores); | 31 | int highscore_load(char *filename, struct highscore *scores, int num_scores); |
32 | int highscore_update(int score, int level, struct highscore *scores, int num_scores); | ||
32 | 33 | ||
33 | #endif | 34 | #endif |
diff --git a/apps/plugins/rockblox.c b/apps/plugins/rockblox.c index 6337ff4acb..16530ff337 100644 --- a/apps/plugins/rockblox.c +++ b/apps/plugins/rockblox.c | |||
@@ -118,6 +118,17 @@ PLUGIN_HEADER | |||
118 | #define ROCKBLOX_DROP BUTTON_FF | 118 | #define ROCKBLOX_DROP BUTTON_FF |
119 | #define ROCKBLOX_RESTART BUTTON_PLAY | 119 | #define ROCKBLOX_RESTART BUTTON_PLAY |
120 | 120 | ||
121 | #elif CONFIG_KEYPAD == GIGABEAT_PAD | ||
122 | |||
123 | #define ROCKBLOX_OFF BUTTON_A | ||
124 | #define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN | ||
125 | #define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP | ||
126 | #define ROCKBLOX_ROTATE BUTTON_UP | ||
127 | #define ROCKBLOX_DOWN BUTTON_DOWN | ||
128 | #define ROCKBLOX_LEFT BUTTON_LEFT | ||
129 | #define ROCKBLOX_RIGHT BUTTON_RIGHT | ||
130 | #define ROCKBLOX_DROP BUTTON_SELECT | ||
131 | #define ROCKBLOX_RESTART BUTTON_MENU | ||
121 | #endif | 132 | #endif |
122 | 133 | ||
123 | #define BLOCKS_NUM 7 | 134 | #define BLOCKS_NUM 7 |
@@ -142,6 +153,24 @@ PLUGIN_HEADER | |||
142 | #define LEVEL_Y 70 | 153 | #define LEVEL_Y 70 |
143 | #define LINES_Y 105 | 154 | #define LINES_Y 105 |
144 | 155 | ||
156 | #elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320) | ||
157 | |||
158 | #define BLOCK_WIDTH 12 | ||
159 | #define BLOCK_HEIGHT 12 | ||
160 | #define BOARD_X 86 | ||
161 | #define BOARD_Y 0 | ||
162 | #define PREVIEW_X 12 | ||
163 | #define PREVIEW_Y 11 | ||
164 | #define LABEL_X 20 | ||
165 | #define SCORE_Y 80 | ||
166 | #define LEVEL_Y 110 | ||
167 | #define LEVEL_X 46 | ||
168 | #define LINES_X 16 | ||
169 | #define LINES_Y 110 | ||
170 | #define HIGH_SCORE_Y 184 | ||
171 | #define HIGH_LEVEL_Y 193 | ||
172 | #define HIGH_LABEL_X 7 | ||
173 | |||
145 | #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176) | 174 | #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176) |
146 | 175 | ||
147 | #define BLOCK_WIDTH 8 | 176 | #define BLOCK_WIDTH 8 |
@@ -227,6 +256,10 @@ PLUGIN_HEADER | |||
227 | #define LEVEL_X LABEL_X | 256 | #define LEVEL_X LABEL_X |
228 | #endif | 257 | #endif |
229 | 258 | ||
259 | #ifndef LINES_X | ||
260 | #define LINES_X LABEL_X | ||
261 | #endif | ||
262 | |||
230 | #define MYLCD(fn) rb->lcd_ ## fn | 263 | #define MYLCD(fn) rb->lcd_ ## fn |
231 | 264 | ||
232 | extern const fb_data rockblox_background[]; | 265 | extern const fb_data rockblox_background[]; |
@@ -282,7 +315,7 @@ static struct plugin_api *rb; | |||
282 | 315 | ||
283 | static bool gameover = false; | 316 | static bool gameover = false; |
284 | /* c=current f=figure o=orientation n=next */ | 317 | /* c=current f=figure o=orientation n=next */ |
285 | static int lines, level, score, cx, cy, cf, co, nf; | 318 | static int lines = 0, level = 0, score = 0, cx, cy, cf, co, nf; |
286 | static short board[BOARD_HEIGHT][BOARD_WIDTH]; /* 20 rows of 10 blocks */ | 319 | static short board[BOARD_HEIGHT][BOARD_WIDTH]; /* 20 rows of 10 blocks */ |
287 | 320 | ||
288 | #ifdef SCROLL_WHEEL | 321 | #ifdef SCROLL_WHEEL |
@@ -395,6 +428,12 @@ figures[BLOCKS_NUM] = { | |||
395 | } | 428 | } |
396 | }; | 429 | }; |
397 | 430 | ||
431 | /* Rockbox File System only supports full filenames inc dir */ | ||
432 | #define HIGH_SCORE "/.rockbox/rocks/rockblox.score" | ||
433 | #define MAX_HIGH_SCORES 5 | ||
434 | /* Default High Scores... */ | ||
435 | struct highscore Highest[MAX_HIGH_SCORES]; | ||
436 | |||
398 | /* get random number from (0) to (range-1) */ | 437 | /* get random number from (0) to (range-1) */ |
399 | static int t_rand (int range) | 438 | static int t_rand (int range) |
400 | { | 439 | { |
@@ -425,7 +464,7 @@ static void show_details (void) | |||
425 | rb->snprintf (str, sizeof (str), "%d", level); | 464 | rb->snprintf (str, sizeof (str), "%d", level); |
426 | rb->lcd_putsxy (LEVEL_X, LEVEL_Y, str); | 465 | rb->lcd_putsxy (LEVEL_X, LEVEL_Y, str); |
427 | rb->snprintf (str, sizeof (str), "%d", lines); | 466 | rb->snprintf (str, sizeof (str), "%d", lines); |
428 | rb->lcd_putsxy (LABEL_X, LINES_Y, str); | 467 | rb->lcd_putsxy (LINES_X, LINES_Y, str); |
429 | #else /* HAVE_LCD_CHARCELLS */ | 468 | #else /* HAVE_LCD_CHARCELLS */ |
430 | rb->snprintf (str, sizeof (str), "L%d/%d", level, lines); | 469 | rb->snprintf (str, sizeof (str), "L%d/%d", level, lines); |
431 | rb->lcd_puts (5, 0, str); | 470 | rb->lcd_puts (5, 0, str); |
@@ -436,6 +475,10 @@ static void show_details (void) | |||
436 | 475 | ||
437 | static void init_rockblox (void) | 476 | static void init_rockblox (void) |
438 | { | 477 | { |
478 | int i; | ||
479 | char str[25]; /* for strings */ | ||
480 | highscore_update(score, level, Highest, MAX_HIGH_SCORES); | ||
481 | |||
439 | level = 1; | 482 | level = 1; |
440 | lines = 0; | 483 | lines = 0; |
441 | score = 0; | 484 | score = 0; |
@@ -454,6 +497,13 @@ static void init_rockblox (void) | |||
454 | pgfx_update(); | 497 | pgfx_update(); |
455 | #endif | 498 | #endif |
456 | show_details (); | 499 | show_details (); |
500 | #ifdef HIGH_SCORE_Y | ||
501 | for (i = MAX_HIGH_SCORES-1; i>=0; i--) | ||
502 | { | ||
503 | rb->snprintf (str, sizeof (str), "%06d L%1d", Highest[i].score, Highest[i].level); | ||
504 | rb->lcd_putsxy (HIGH_LABEL_X, HIGH_SCORE_Y + (10 * ((MAX_HIGH_SCORES-1) - i)), str); | ||
505 | } | ||
506 | #endif | ||
457 | } | 507 | } |
458 | 508 | ||
459 | static inline int level_speed(int level) | 509 | static inline int level_speed(int level) |
@@ -781,6 +831,9 @@ static int rockblox_loop (void) | |||
781 | case ROCKBLOX_OFF: | 831 | case ROCKBLOX_OFF: |
782 | return PLUGIN_OK; | 832 | return PLUGIN_OK; |
783 | 833 | ||
834 | #if defined(ROCKBLOX_ROTATE) | ||
835 | case ROCKBLOX_ROTATE: | ||
836 | #endif | ||
784 | case ROCKBLOX_ROTATE_RIGHT: | 837 | case ROCKBLOX_ROTATE_RIGHT: |
785 | case ROCKBLOX_ROTATE_RIGHT | BUTTON_REPEAT: | 838 | case ROCKBLOX_ROTATE_RIGHT | BUTTON_REPEAT: |
786 | #ifdef SCROLL_WHEEL | 839 | #ifdef SCROLL_WHEEL |
@@ -910,6 +963,11 @@ enum plugin_status plugin_start (struct plugin_api *api, void *parameter) | |||
910 | rb = api; | 963 | rb = api; |
911 | 964 | ||
912 | rb->srand (*rb->current_tick); | 965 | rb->srand (*rb->current_tick); |
966 | |||
967 | /* Load HighScore if any */ | ||
968 | highscore_init(rb); | ||
969 | highscore_load(HIGH_SCORE,Highest,MAX_HIGH_SCORES); | ||
970 | |||
913 | #if LCD_DEPTH > 1 | 971 | #if LCD_DEPTH > 1 |
914 | rb->lcd_set_backdrop(NULL); | 972 | rb->lcd_set_backdrop(NULL); |
915 | #endif | 973 | #endif |
@@ -935,6 +993,8 @@ enum plugin_status plugin_start (struct plugin_api *api, void *parameter) | |||
935 | #else | 993 | #else |
936 | pgfx_release(); | 994 | pgfx_release(); |
937 | #endif | 995 | #endif |
996 | /* Save user's HighScore */ | ||
997 | highscore_save(HIGH_SCORE,Highest,MAX_HIGH_SCORES); | ||
938 | /* Restore user's original backlight setting */ | 998 | /* Restore user's original backlight setting */ |
939 | rb->backlight_set_timeout (rb->global_settings->backlight_timeout); | 999 | rb->backlight_set_timeout (rb->global_settings->backlight_timeout); |
940 | 1000 | ||