diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7b97055 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.xcf filter=lfs diff=lfs merge=lfs -text +*.jpg filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index e1508f9..9a87bea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ -build-* +build-*-Debug *.dat *~ +*.user +*.dis +*.lnk +*.map +*.stn +*.img +*.sym diff --git a/Project Icon.jpg b/Project Icon.jpg new file mode 100644 index 0000000..ec17dfb --- /dev/null +++ b/Project Icon.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0434ac892b4a23285e853e9389cce6b7f47f7ab34cc876f7dcedc4ec97e7c9d9 +size 7887 diff --git a/importer/main.c b/importer/main.c index fa650ed..9c97b10 100644 --- a/importer/main.c +++ b/importer/main.c @@ -1,3 +1,25 @@ +/* + * Warehouse for JoeyLib - A Sokoban Clone + * Copyright (C) 2020 Scott Duensing + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +*/ + + #include #include #include @@ -8,14 +30,16 @@ #define MAX_LINE 8192 +static char puzzleChars[] = { "_# .$@+*" }; + + int isLegal(char c) { int x; - char legal[] = { "_# .$@+*" }; if (c == '-') c = ' '; - for (x=0; x<(int)strlen(legal); x++) { - if (legal[x] == c) { + for (x=0; x<(int)strlen(puzzleChars); x++) { + if (puzzleChars[x] == c) { return x + 1; } } @@ -29,6 +53,8 @@ int main(int argc, char *argv[]) { char line[MAX_LINE]; // Ooo! Look! Potential buffer overflow! char height; unsigned char width; + unsigned char b1; + unsigned char b2; int16_t x; int16_t y; int16_t count = 0; @@ -64,12 +90,19 @@ int main(int argc, char *argv[]) { width = 0; while (fgets(line, MAX_LINE, in)) { + // Is there a newline to remove? + if ((strlen(line) > 0) && (line[strlen(line) - 1] == '\n')) { + line[strlen(line) - 1] = 0; + } // Is there anything on this line? if (strlen(line) > 0) { // Is this a puzzle line? if (isLegal(line[0]) > 0) { // Got it. Read this line. - if (width < strlen(line)) width = strlen(line); + if (width < strlen(line)) { + width = strlen(line); + printf("Width %d\n", width); + } height++; for (x=0; x= 0) { // Yep! Output it! + height++; // Make it 1 based ('width' has been 1 based the whole time) if ((width & 1) == 1) { - // Width must be even - fill new column with zeros. - for (y=0; y + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. +*/ + + +#include +#include +#include +#include + + +#define JOEY_MAIN +#include "joey.h" +#ifdef JOEY_IIGS +segment "warehouse"; +#endif + + +#define MAX_WIDTH 20 +#define MAX_HEIGHT 12 + +#define TILE_NOTHING 0 +#define TILE_WALL 1 +#define TILE_FLOOR 2 +#define TILE_GOAL 3 +#define TILE_CRATE 4 +#define TILE_PLAYER 5 +#define TILE_CRATE_ON_GOAL 6 +#define TILE_PLAYER_ON_GOAL 7 + + +typedef struct PuzzleS { + byte width; + byte height; + byte puzzle[MAX_WIDTH][MAX_HEIGHT]; +} PuzzleT; + +typedef struct SaveS { + jint16 lastPuzzle; + jint16 solvedSize; + byte *solved; +} SaveT; + + +static jlImgT *fontI = NULL; +static jlImgT *tilesI = NULL; + +static jint16 puzzleCount = 0; + +static PuzzleT puzzle; +static SaveT saveGame; + + +static char puzzleChars[] = { "_# .$@+*" }; + + +void loadPuzzle(jint16 number); +void printAt(jlImgT *font, jint16 cx, jint16 cy, const char *what, ...); + + +void loadPuzzle(jint16 number) { + FILE *in = NULL; + jint16 count = 0; + byte x = 0; + byte y = 0; + + in = fopen("data/puzzles.dat", "rb"); + if (!in) jlUtilDie("Unable to open puzzle database!"); + + // Skip over puzzle count bytes. + fread(&puzzleCount, sizeof(jint16), 1, in); + + // Iterate until we find the puzzle we need. + while (count < number) { + // Load width of puzzle + puzzle.width = fgetc(in); + // Load height of puzzle + puzzle.height = fgetc(in); + // Load the puzzle itself + for (y=0; y> 4; + } + } + // 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