diff --git a/importer/main.c b/importer/main.c index 9c97b10..1b2d097 100644 --- a/importer/main.c +++ b/importer/main.c @@ -57,13 +57,14 @@ int main(int argc, char *argv[]) { unsigned char b2; int16_t x; int16_t y; - int16_t count = 0; - int32_t bytes = 0; + int16_t count; + int32_t bytes; FILE *in; - FILE *out; + FILE *puzzles; + FILE *index; - if (argc != 3) { - printf("%s: [letslogic.txt] [puzzles.dat]\n", argv[0]); + if (argc != 4) { + printf("%s: [letslogic.txt] [puzzles.dat] [index.dat]\n", argv[0]); return 1; } @@ -73,18 +74,26 @@ int main(int argc, char *argv[]) { return 2; } - out = fopen(argv[2], "wb"); - if (!out) { + puzzles = fopen(argv[2], "wb"); + if (!puzzles) { fclose(in); printf("Unable to write %s\n", argv[2]); return 2; } - // Skip two bytes at the front of the file to later write the puzzle count into. - fputc(0, out); - fputc(0, out); - bytes = 2; + index = fopen(argv[3], "wb"); + if (!index) { + fclose(puzzles); + fclose(in); + printf("Unable to write %s\n", argv[3]); + return 2; + } + // Skip two bytes at the front of the index file to later write the puzzle count into. + fputc(0, index); + fputc(0, index); + + bytes = 0; count = 0; height = -1; width = 0; @@ -101,7 +110,7 @@ int main(int argc, char *argv[]) { // Got it. Read this line. if (width < strlen(line)) { width = strlen(line); - printf("Width %d\n", width); + //printf("Width %d\n", width); } height++; for (x=0; x> 4; + // Skip to requested puzzle. + fseek(in, puzzleIndex[number - 1], SEEK_SET); + // Load width of puzzle + fread(&puzzle.width, sizeof(byte), 1, in); + // Load height of puzzle + fread(&puzzle.height, sizeof(byte), 1, in); + // Load the puzzle itself + for (y=0; y> 4; + // Is this our start location? If so, replace with proper tile and remember where we are. + if (puzzle.puzzle[x][y] == TILE_PLAYER) { + puzzle.puzzle[x][y] = TILE_FLOOR; + avatarX = x; + avatarY = y; + } + if (puzzle.puzzle[x][y] == TILE_PLAYER_ON_GOAL) { + puzzle.puzzle[x][y] = TILE_GOAL; + avatarX = x; + avatarY = y; + } + if (puzzle.puzzle[x + 1][y] == TILE_PLAYER) { + puzzle.puzzle[x + 1][y] = TILE_FLOOR; + avatarX = x + 1; + avatarY = y; + } + if (puzzle.puzzle[x + 1][y] == TILE_PLAYER_ON_GOAL) { + puzzle.puzzle[x + 1][y] = TILE_GOAL; + avatarX = x + 1; + avatarY = y; } } - // Count it. - count++; } fclose(in); - //***DEBUG*** - printf("Puzzles found: %d\n", puzzleCount); - printf("Puzzle %d - %dx%d\n", count, puzzle.width, puzzle.height); - for (y=0; y= puzzleCount) { + current = 1; + } + break; + + case 'I': + case 'i': + if (puzzleNow[avatarX][avatarY - 1] == TILE_FLOOR) { + avatarY--; + } + break; + + case 'J': + case 'j': + if (puzzleNow[avatarX - 1][avatarY] == TILE_FLOOR) { + avatarX--; + } + break; + + case 'K': + case 'k': + if (puzzleNow[avatarX + 1][avatarY] == TILE_FLOOR) { + avatarX++; + } + break; + + case 'M': + case 'm': + if (puzzleNow[avatarX][avatarY + 1] == TILE_FLOOR) { + avatarY++; + } + break; + } + } + // Load new level? + if (last != current) { + last = current; + loadPuzzle(current); + avatarXLast = -1; + avatarYLast = -1; + jlDrawClear(); + printAt(fontI, 0, 24, "%d puzzles found. Showing #%d", puzzleCount, current); + } + // Redraw? + if ((avatarX != avatarXLast) || (avatarY != avatarYLast)) { + puzzleBefore[avatarXLast][avatarYLast] = TILE_NOTHING; + //printPuzzle("Now", puzzleNow); + //printPuzzle("Before", puzzleBefore); + drawPuzzle(); + drawAvatar(); + jlDisplayPresent(); + } + } jlFree(saveGame.solved); - + jlFree(puzzleIndex); jlImgFree(tilesI); - jlImgFree(fontI); jlUtilShutdown(); diff --git a/warehouse/postlink.sh b/warehouse/postlink.sh index 67bc443..f7a9ca9 100755 --- a/warehouse/postlink.sh +++ b/warehouse/postlink.sh @@ -5,5 +5,6 @@ export JOEY=$2 mkdir -p data cp -f "${GAME}"/../puzzles.dat data/. +cp -f "${GAME}"/../index.dat data/. cp -f "${GAME}"/*.img data/. cp -f "${GAME}"/*.stn data/.