summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Cellerier <dionoea@videolan.org>2007-06-16 23:12:41 +0000
committerAntoine Cellerier <dionoea@videolan.org>2007-06-16 23:12:41 +0000
commitbbb9da3f8ce19421e7fe9f12e7401f7d84989cc0 (patch)
treed2cb3ba02bac0507fda757cb156bfb0dce0cb5ad
parent56780e3e417cb1b9d1d453592d58c988c8029c16 (diff)
downloadrockbox-bbb9da3f8ce19421e7fe9f12e7401f7d84989cc0.tar.gz
rockbox-bbb9da3f8ce19421e7fe9f12e7401f7d84989cc0.zip
Add "Puzzle" game type to jewels. Idea from Sam Hocevar's MonsterZ (http://sam.zoy.org/monsterz).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13644 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/bitmaps/native/jewels.112x64x1.bmpbin318 -> 798 bytes
-rw-r--r--apps/plugins/bitmaps/native/jewels.128x128x16.bmpbin4982 -> 14222 bytes
-rw-r--r--apps/plugins/bitmaps/native/jewels.138x110x2.bmpbin2742 -> 5862 bytes
-rw-r--r--apps/plugins/bitmaps/native/jewels.160x128x16.bmpbin6200 -> 17718 bytes
-rw-r--r--apps/plugins/bitmaps/native/jewels.160x128x2.bmpbin3126 -> 6966 bytes
-rw-r--r--apps/plugins/bitmaps/native/jewels.220x176x16.bmpbin12024 -> 34462 bytes
-rw-r--r--apps/plugins/bitmaps/native/jewels.320x240x16.bmpbin22136 -> 63534 bytes
-rw-r--r--apps/plugins/jewels.c226
8 files changed, 198 insertions, 28 deletions
diff --git a/apps/plugins/bitmaps/native/jewels.112x64x1.bmp b/apps/plugins/bitmaps/native/jewels.112x64x1.bmp
index 447df6d1da..f245f330e5 100644
--- a/apps/plugins/bitmaps/native/jewels.112x64x1.bmp
+++ b/apps/plugins/bitmaps/native/jewels.112x64x1.bmp
Binary files differ
diff --git a/apps/plugins/bitmaps/native/jewels.128x128x16.bmp b/apps/plugins/bitmaps/native/jewels.128x128x16.bmp
index c22c8d917e..0061df3c3d 100644
--- a/apps/plugins/bitmaps/native/jewels.128x128x16.bmp
+++ b/apps/plugins/bitmaps/native/jewels.128x128x16.bmp
Binary files differ
diff --git a/apps/plugins/bitmaps/native/jewels.138x110x2.bmp b/apps/plugins/bitmaps/native/jewels.138x110x2.bmp
index b2096e19b0..75bd9566bd 100644
--- a/apps/plugins/bitmaps/native/jewels.138x110x2.bmp
+++ b/apps/plugins/bitmaps/native/jewels.138x110x2.bmp
Binary files differ
diff --git a/apps/plugins/bitmaps/native/jewels.160x128x16.bmp b/apps/plugins/bitmaps/native/jewels.160x128x16.bmp
index 5d9606d012..6874564585 100644
--- a/apps/plugins/bitmaps/native/jewels.160x128x16.bmp
+++ b/apps/plugins/bitmaps/native/jewels.160x128x16.bmp
Binary files differ
diff --git a/apps/plugins/bitmaps/native/jewels.160x128x2.bmp b/apps/plugins/bitmaps/native/jewels.160x128x2.bmp
index 603925f145..f6b5e9ea61 100644
--- a/apps/plugins/bitmaps/native/jewels.160x128x2.bmp
+++ b/apps/plugins/bitmaps/native/jewels.160x128x2.bmp
Binary files differ
diff --git a/apps/plugins/bitmaps/native/jewels.220x176x16.bmp b/apps/plugins/bitmaps/native/jewels.220x176x16.bmp
index 36d4f51249..64f54b0391 100644
--- a/apps/plugins/bitmaps/native/jewels.220x176x16.bmp
+++ b/apps/plugins/bitmaps/native/jewels.220x176x16.bmp
Binary files differ
diff --git a/apps/plugins/bitmaps/native/jewels.320x240x16.bmp b/apps/plugins/bitmaps/native/jewels.320x240x16.bmp
index 201c178183..67b2d16541 100644
--- a/apps/plugins/bitmaps/native/jewels.320x240x16.bmp
+++ b/apps/plugins/bitmaps/native/jewels.320x240x16.bmp
Binary files differ
diff --git a/apps/plugins/jewels.c b/apps/plugins/jewels.c
index c6efcbccef..20fb60c808 100644
--- a/apps/plugins/jewels.c
+++ b/apps/plugins/jewels.c
@@ -203,15 +203,22 @@ PLUGIN_HEADER
203/* animation frame rate */ 203/* animation frame rate */
204#define MAX_FPS 20 204#define MAX_FPS 20
205 205
206/* Game types */
207enum game_type {
208 GAME_TYPE_NORMAL,
209 GAME_TYPE_PUZZLE
210};
211
206/* menu values */ 212/* menu values */
207#define FONT_HEIGHT 8 213#define FONT_HEIGHT 8
208#define MAX_MITEMS 5 214#define MAX_MITEMS 6
209#define MENU_WIDTH 100 215#define MENU_WIDTH 100
210 216
211/* menu results */ 217/* menu results */
212enum menu_result { 218enum menu_result {
213 MRES_NONE, 219 MRES_NONE,
214 MRES_NEW, 220 MRES_NEW,
221 MRES_PUZZLE,
215 MRES_SAVE, 222 MRES_SAVE,
216 MRES_RESUME, 223 MRES_RESUME,
217 MRES_SCORES, 224 MRES_SCORES,
@@ -240,8 +247,9 @@ struct jewels_menu {
240 enum menu_result res; 247 enum menu_result res;
241 } items[MAX_MITEMS]; 248 } items[MAX_MITEMS];
242} bjmenu[] = { 249} bjmenu[] = {
243 {"Jewels", false, 0, 5, 250 {"Jewels", false, 0, 6,
244 {{"New Game", MRES_NEW}, 251 {{"New Game", MRES_NEW},
252 {"Puzzle", MRES_PUZZLE},
245 {"Resume Game", MRES_RESUME}, 253 {"Resume Game", MRES_RESUME},
246 {"High Scores", MRES_SCORES}, 254 {"High Scores", MRES_SCORES},
247 {"Help", MRES_HELP}, 255 {"Help", MRES_HELP},
@@ -283,19 +291,76 @@ struct tile {
283 * score is the current level score 291 * score is the current level score
284 * segments is the number of cleared segments in the current run 292 * segments is the number of cleared segments in the current run
285 * level is the current level 293 * level is the current level
294 * type is the game type (normal or puzzle)
286 * highscores is the list of high scores 295 * highscores is the list of high scores
287 * resume denotes whether to resume the currently loaded game 296 * resume denotes whether to resume the currently loaded game
288 * dirty denotes whether the high scores are out of sync with the saved file 297 * dirty denotes whether the high scores are out of sync with the saved file
289 * playboard is the game playing board (first row is hidden) 298 * playboard is the game playing board (first row is hidden)
299 * num_jewels is the number of different jewels to use
290 */ 300 */
291struct game_context { 301struct game_context {
292 unsigned int score; 302 unsigned int score;
293 unsigned int segments; 303 unsigned int segments;
294 unsigned int level; 304 unsigned int level;
305 unsigned int type;
295 unsigned int highscores[NUM_SCORES]; 306 unsigned int highscores[NUM_SCORES];
296 bool resume; 307 bool resume;
297 bool dirty; 308 bool dirty;
298 struct tile playboard[BJ_HEIGHT][BJ_WIDTH]; 309 struct tile playboard[BJ_HEIGHT][BJ_WIDTH];
310 unsigned int num_jewels;
311};
312
313#define MAX_NUM_JEWELS 7
314
315#define MAX_PUZZLE_TILES 4
316#define NUM_PUZZLE_LEVELS 10
317
318struct puzzle_tile {
319 int x;
320 int y;
321 int tile_type;
322};
323
324struct puzzle_level {
325 unsigned int num_jewels;
326 unsigned int num_tiles;
327 struct puzzle_tile tiles[MAX_PUZZLE_TILES];
328};
329
330#define PUZZLE_TILE_UP 1
331#define PUZZLE_TILE_DOWN 2
332#define PUZZLE_TILE_LEFT 4
333#define PUZZLE_TILE_RIGHT 8
334
335struct puzzle_level puzzle_levels[NUM_PUZZLE_LEVELS] = {
336 { 5, 2, { {3, 3, PUZZLE_TILE_RIGHT},
337 {4, 2, PUZZLE_TILE_LEFT} } },
338 { 5, 2, { {3, 2, PUZZLE_TILE_DOWN},
339 {3, 4, PUZZLE_TILE_UP} } },
340 { 6, 3, { {3, 2, PUZZLE_TILE_DOWN},
341 {3, 4, PUZZLE_TILE_UP|PUZZLE_TILE_DOWN},
342 {3, 6, PUZZLE_TILE_UP} } },
343 { 6, 3, { {3, 2, PUZZLE_TILE_RIGHT},
344 {4, 3, PUZZLE_TILE_LEFT|PUZZLE_TILE_RIGHT},
345 {5, 4, PUZZLE_TILE_LEFT} } },
346 { 6, 2, { {3, 4, PUZZLE_TILE_RIGHT},
347 {4, 2, PUZZLE_TILE_LEFT} } },
348 { 6, 2, { {3, 2, PUZZLE_TILE_DOWN},
349 {4, 4, PUZZLE_TILE_UP} } },
350 { 7, 4, { {3, 2, PUZZLE_TILE_LEFT|PUZZLE_TILE_DOWN},
351 {4, 3, PUZZLE_TILE_LEFT|PUZZLE_TILE_UP},
352 {3, 4, PUZZLE_TILE_RIGHT|PUZZLE_TILE_DOWN},
353 {4, 4, PUZZLE_TILE_RIGHT|PUZZLE_TILE_UP} } },
354 { 6, 3, { {3, 2, PUZZLE_TILE_DOWN},
355 {4, 4, PUZZLE_TILE_UP|PUZZLE_TILE_DOWN},
356 {3, 6, PUZZLE_TILE_UP} } },
357 { 7, 3, { {2, 2, PUZZLE_TILE_RIGHT},
358 {4, 1, PUZZLE_TILE_LEFT|PUZZLE_TILE_RIGHT},
359 {5, 4, PUZZLE_TILE_LEFT} } },
360 { 7, 4, { {3, 0, PUZZLE_TILE_LEFT|PUZZLE_TILE_DOWN},
361 {5, 0, PUZZLE_TILE_LEFT|PUZZLE_TILE_UP},
362 {2, 7, PUZZLE_TILE_RIGHT|PUZZLE_TILE_DOWN},
363 {4, 7, PUZZLE_TILE_RIGHT|PUZZLE_TILE_UP} } },
299}; 364};
300 365
301/***************************************************************************** 366/*****************************************************************************
@@ -574,7 +639,7 @@ static void jewels_putjewels(struct game_context* bj){
574 done = true; 639 done = true;
575 for(j=0; j<BJ_WIDTH; j++) { 640 for(j=0; j<BJ_WIDTH; j++) {
576 if(bj->playboard[1][j].type == 0) { 641 if(bj->playboard[1][j].type == 0) {
577 bj->playboard[0][j].type = rb->rand()%7+1; 642 bj->playboard[0][j].type = rb->rand()%bj->num_jewels+1;
578 } 643 }
579 for(i=BJ_HEIGHT-2; i>=0; i--) { 644 for(i=BJ_HEIGHT-2; i>=0; i--) {
580 if(!mark && bj->playboard[i+1][j].type == 0) { 645 if(!mark && bj->playboard[i+1][j].type == 0) {
@@ -584,7 +649,7 @@ static void jewels_putjewels(struct game_context* bj){
584 if(mark) bj->playboard[i][j].falling = true; 649 if(mark) bj->playboard[i][j].falling = true;
585 } 650 }
586 /*if(bj->playboard[1][j].falling) { 651 /*if(bj->playboard[1][j].falling) {
587 bj->playboard[0][j].type = rb->rand()%7+1; 652 bj->playboard[0][j].type = rb->rand()%bj->num_jewels+1;
588 bj->playboard[0][j].falling = true; 653 bj->playboard[0][j].falling = true;
589 }*/ 654 }*/
590 mark = false; 655 mark = false;
@@ -697,7 +762,8 @@ static unsigned int jewels_clearjewels(struct game_context* bj) {
697 run = 1; 762 run = 1;
698 for(j=0; j<BJ_WIDTH; j++) { 763 for(j=0; j<BJ_WIDTH; j++) {
699 if(bj->playboard[i][j].type == last && 764 if(bj->playboard[i][j].type == last &&
700 bj->playboard[i][j].type != 0) { 765 bj->playboard[i][j].type != 0 &&
766 bj->playboard[i][j].type <= MAX_NUM_JEWELS) {
701 run++; 767 run++;
702 768
703 if(run == 3) { 769 if(run == 3) {
@@ -723,7 +789,8 @@ static unsigned int jewels_clearjewels(struct game_context* bj) {
723 run = 1; 789 run = 1;
724 for(i=1; i<BJ_HEIGHT; i++) { 790 for(i=1; i<BJ_HEIGHT; i++) {
725 if(bj->playboard[i][j].type != 0 && 791 if(bj->playboard[i][j].type != 0 &&
726 bj->playboard[i][j].type == last) { 792 bj->playboard[i][j].type == last &&
793 bj->playboard[i][j].type <= MAX_NUM_JEWELS) {
727 run++; 794 run++;
728 795
729 if(run == 3) { 796 if(run == 3) {
@@ -930,6 +997,7 @@ static bool jewels_movesavail(struct game_context* bj) {
930 for(i=1; i<BJ_HEIGHT; i++) { 997 for(i=1; i<BJ_HEIGHT; i++) {
931 for(j=0; j<BJ_WIDTH; j++) { 998 for(j=0; j<BJ_WIDTH; j++) {
932 mytype = bj->playboard[i][j].type; 999 mytype = bj->playboard[i][j].type;
1000 if(mytype == 0 || mytype > MAX_NUM_JEWELS) continue;
933 1001
934 /* check horizontal patterns */ 1002 /* check horizontal patterns */
935 if(j <= BJ_WIDTH-3) { 1003 if(j <= BJ_WIDTH-3) {
@@ -1015,31 +1083,82 @@ static bool jewels_movesavail(struct game_context* bj) {
1015} 1083}
1016 1084
1017/***************************************************************************** 1085/*****************************************************************************
1018* jewels_nextlevel() advances the game to the next level and returns 1086* jewels_puzzle_is_finished(bj) checks if the puzzle is finished.
1019* points earned.
1020******************************************************************************/ 1087******************************************************************************/
1021static unsigned int jewels_nextlevel(struct game_context* bj) { 1088static int jewels_puzzle_is_finished(struct game_context* bj) {
1022 int i, x, y; 1089 unsigned int i, j;
1090 for(i=0; i<BJ_HEIGHT; i++) {
1091 for(j=0; j<BJ_WIDTH; j++) {
1092 int mytype = bj->playboard[i][j].type;
1093 if(mytype>MAX_NUM_JEWELS) {
1094 mytype -= MAX_NUM_JEWELS;
1095 if(mytype&PUZZLE_TILE_UP) {
1096 if(i==0 || bj->playboard[i-1][j].type<=MAX_NUM_JEWELS ||
1097 !((bj->playboard[i-1][j].type-MAX_NUM_JEWELS)
1098 &PUZZLE_TILE_DOWN))
1099 return 0;
1100 }
1101 if(mytype&PUZZLE_TILE_DOWN) {
1102 if(i==BJ_HEIGHT-1 ||
1103 bj->playboard[i+1][j].type<=MAX_NUM_JEWELS ||
1104 !((bj->playboard[i+1][j].type-MAX_NUM_JEWELS)
1105 &PUZZLE_TILE_UP))
1106 return 0;
1107 }
1108 if(mytype&PUZZLE_TILE_LEFT) {
1109 if(j==0 || bj->playboard[i][j-1].type<=MAX_NUM_JEWELS ||
1110 !((bj->playboard[i][j-1].type-MAX_NUM_JEWELS)
1111 &PUZZLE_TILE_RIGHT))
1112 return 0;
1113 }
1114 if(mytype&PUZZLE_TILE_RIGHT) {
1115 if(j==BJ_WIDTH-1 ||
1116 bj->playboard[i][j+1].type<=MAX_NUM_JEWELS ||
1117 !((bj->playboard[i][j+1].type-MAX_NUM_JEWELS)
1118 &PUZZLE_TILE_LEFT))
1119 return 0;
1120 }
1121 }
1122 }
1123 }
1124 return 1;
1125}
1126
1127/*****************************************************************************
1128* jewels_initlevel() initialises a level.
1129******************************************************************************/
1130static unsigned int jewels_initlevel(struct game_context* bj) {
1023 unsigned int points = 0; 1131 unsigned int points = 0;
1024 1132
1025 /* roll over score, change and display level */ 1133 switch(bj->type) {
1026 while(bj->score >= LEVEL_PTS) { 1134 case GAME_TYPE_NORMAL:
1027 bj->score -= LEVEL_PTS; 1135 bj->num_jewels = MAX_NUM_JEWELS;
1028 bj->level++; 1136 break;
1029 rb->splash(HZ*2, "Level %d", bj->level);
1030 jewels_drawboard(bj);
1031 }
1032 1137
1033 /* randomly clear some jewels */ 1138 case GAME_TYPE_PUZZLE:
1034 for(i=0; i<16; i++) { 1139 {
1035 x = rb->rand()%8; 1140 unsigned int i, j;
1036 y = rb->rand()%8; 1141 struct puzzle_tile *tile;
1037 1142
1038 if(bj->playboard[y][x].type != 0) { 1143 bj->num_jewels = puzzle_levels[bj->level-1].num_jewels;
1039 points++; 1144
1040 bj->playboard[y][x].type = 0; 1145 for(i=0; i<BJ_HEIGHT; i++) {
1146 for(j=0; j<BJ_WIDTH; j++) {
1147 bj->playboard[i][j].type = (rand()%bj->num_jewels)+1;
1148 bj->playboard[i][j].falling = false;
1149 bj->playboard[i][j].delete = false;
1150 }
1151 }
1152 jewels_runboard(bj);
1153 tile = puzzle_levels[bj->level-1].tiles;
1154 for(i=0; i<puzzle_levels[bj->level-1].num_tiles; i++, tile++) {
1155 bj->playboard[tile->y][tile->x].type = MAX_NUM_JEWELS
1156 +tile->tile_type;
1157 }
1041 } 1158 }
1159 break;
1042 } 1160 }
1161
1043 jewels_drawboard(bj); 1162 jewels_drawboard(bj);
1044 1163
1045 /* run the play board */ 1164 /* run the play board */
@@ -1049,6 +1168,44 @@ static unsigned int jewels_nextlevel(struct game_context* bj) {
1049} 1168}
1050 1169
1051/***************************************************************************** 1170/*****************************************************************************
1171* jewels_nextlevel() advances the game to the next level and returns
1172* points earned.
1173******************************************************************************/
1174static unsigned int jewels_nextlevel(struct game_context* bj) {
1175 int i, x, y;
1176 unsigned int points = 0;
1177
1178 switch(bj->type) {
1179 case GAME_TYPE_NORMAL:
1180 /* roll over score, change and display level */
1181 while(bj->score >= LEVEL_PTS) {
1182 bj->score -= LEVEL_PTS;
1183 bj->level++;
1184 rb->splash(HZ*2, "Level %d", bj->level);
1185 jewels_drawboard(bj);
1186 }
1187
1188 /* randomly clear some jewels */
1189 for(i=0; i<16; i++) {
1190 x = rb->rand()%8;
1191 y = rb->rand()%8;
1192
1193 if(bj->playboard[y][x].type != 0) {
1194 points++;
1195 bj->playboard[y][x].type = 0;
1196 }
1197 }
1198 break;
1199
1200 case GAME_TYPE_PUZZLE:
1201 bj->level++;
1202 break;
1203 }
1204
1205 return jewels_initlevel(bj);
1206}
1207
1208/*****************************************************************************
1052* jewels_recordscore() inserts a high score into the high scores list and 1209* jewels_recordscore() inserts a high score into the high scores list and
1053* returns the high score position. 1210* returns the high score position.
1054******************************************************************************/ 1211******************************************************************************/
@@ -1207,6 +1364,12 @@ static int jewels_main(struct game_context* bj) {
1207 switch(res) { 1364 switch(res) {
1208 case MRES_NEW: 1365 case MRES_NEW:
1209 startgame = true; 1366 startgame = true;
1367 bj->type = GAME_TYPE_NORMAL;
1368 continue;
1369
1370 case MRES_PUZZLE:
1371 startgame = true;
1372 bj->type = GAME_TYPE_PUZZLE;
1210 continue; 1373 continue;
1211 1374
1212 case MRES_RESUME: 1375 case MRES_RESUME:
@@ -1396,9 +1559,7 @@ static int jewels_main(struct game_context* bj) {
1396 /******************** 1559 /********************
1397 * setup the board * 1560 * setup the board *
1398 ********************/ 1561 ********************/
1399 jewels_drawboard(bj); 1562 bj->score += jewels_initlevel(bj);
1400 jewels_putjewels(bj);
1401 bj->score += jewels_runboard(bj);
1402 if (!jewels_movesavail(bj)) return BJ_LOSE; 1563 if (!jewels_movesavail(bj)) return BJ_LOSE;
1403 1564
1404 /********************** 1565 /**********************
@@ -1572,7 +1733,16 @@ static int jewels_main(struct game_context* bj) {
1572 break; 1733 break;
1573 } 1734 }
1574 1735
1575 if(bj->score >= LEVEL_PTS) bj->score = jewels_nextlevel(bj); 1736 switch(bj->type) {
1737 case GAME_TYPE_NORMAL:
1738 if(bj->score >= LEVEL_PTS) bj->score = jewels_nextlevel(bj);
1739 break;
1740
1741 case GAME_TYPE_PUZZLE:
1742 if(jewels_puzzle_is_finished(bj))
1743 bj->score += jewels_nextlevel(bj);
1744 break;
1745 }
1576 } 1746 }
1577} 1747}
1578 1748