Level selection working.

This commit is contained in:
Scott Duensing 2020-08-03 18:11:04 -05:00
parent 8bb1091352
commit 68061ae7ae
10 changed files with 128 additions and 66 deletions

2
.gitignore vendored
View file

@ -8,3 +8,5 @@ build-*-Debug
*.stn
*.img
*.sym
*.png
*.jpg

BIN
warehouse/about.xcf (Stored with Git LFS)

Binary file not shown.

BIN
warehouse/backgrnd.xcf (Stored with Git LFS)

Binary file not shown.

View file

@ -1,7 +1,7 @@
#!/bin/bash -e
PROJECT=Warehouse
DATA=(font.img kanga.img tiles.img backgrnd.img about.img play.img ../puzzles.dat ../index.dat)
DATA=(font.img kanga.img tiles.img title.img about.img help.img ../puzzles.dat ../index.dat)
#SOURCE=(*.c *.h)
SOURCE=()

BIN
warehouse/help.xcf (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -70,9 +70,12 @@ typedef struct CoordS {
static jlImgT *fontI = NULL;
static jlImgT *tilesI = NULL;
static jlImgT *aboutI = NULL;
static jlImgT *helpI = NULL;
static jint16 puzzleCount;
static jint16 puzzleCurrent;
static jint16 puzzleLast;
static jint32 *puzzleIndex = NULL;
@ -119,7 +122,7 @@ bool readInput(byte *key);
void redraw(void);
void resetPuzzle(void);
void selectLevel(void);
void showImage(char *name);
void showImage(jlImgT *image);
void showPalette(void);
void ticker(void);
void title(void);
@ -318,6 +321,8 @@ bool mainMenu(void) {
bool running = true;
char choice = 0;
//***TODO*** Reset disk?
while ((choice >= 0) && running && !jlUtilMustExit()) {
choice = menu("Main Menu", options, choice, 0, 0, 0);
switch (choice) {
@ -326,15 +331,19 @@ bool mainMenu(void) {
break;
case 1: // About
showImage("about");
showImage(aboutI);
break;
case 2: // How to Play
showImage("play");
showImage(helpI);
break;
case 3: // Select Level
selectLevel();
if (puzzleLast != puzzleCurrent) {
// New puzzle selected, exit menu.
choice = -1;
}
break;
case 4: // Reset Level
@ -372,7 +381,7 @@ char menu(char *title, char *menuItems[], char selected, byte width, byte offset
jint16 ypos;
jint16 last;
jint16 lastY;
jlImgT *screen = NULL; //***TODO*** Maybe re-use tilesI to save RAM?
jlImgT *screen = NULL;
jlImgCreate(screen);
@ -457,7 +466,6 @@ void moveCrate(byte sx, byte sy, byte dx, byte dy) {
void play(void) {
jint16 last = 0;
byte key = 0;
bool playing = true;
byte tile = 0;
@ -479,22 +487,6 @@ void play(void) {
if (playing) redraw();
break;
case 'Q': //***REMOVE***
case 'q':
puzzleCurrent--;
if (puzzleCurrent < 1) {
puzzleCurrent = puzzleCount;
}
break;
case 'W'://***REMOVE***
case 'w':
puzzleCurrent++;
if (puzzleCurrent >= puzzleCount) {
puzzleCurrent = 1;
}
break;
case 'I':
case 'i':
// Can we move up?
@ -564,9 +556,9 @@ void play(void) {
break;
}
}
// Load new level? ***REMOVE***
if (last != puzzleCurrent) {
last = puzzleCurrent;
// Load new level?
if (puzzleLast != puzzleCurrent) {
puzzleLast = puzzleCurrent;
loadPuzzle(puzzleCurrent);
avatarXLast = -1;
avatarYLast = -1;
@ -657,15 +649,19 @@ void selectLevel(void) {
jint16 lastY;
jint16 p;
jint16 c = 0;
jint16 index = -1;;
jint16 index = -1;
jint16 marginX = 16;
jint16 marginY = 16;
jint16 spacingX;
jint16 spacingY;
jint16 cols = (jint16)(sqrt(puzzleCount) + 0.5f);
jint16 dangling = puzzleCount - (cols * (cols - 1));
char bit = 0;
byte data;
bool inMenu = true;
jlImgT *screen = NULL;
jlImgCreate(screen);
jlPaletteSet( 0, 0, 0, 0);
jlPaletteSet( 1, 0, 15, 0);
@ -710,6 +706,8 @@ void selectLevel(void) {
}
}
printAt(fontI, 0, 24, "Green are Completed. Red are Unsolved.");
p = puzzleCurrent;
lastX = -1;
lastY = -1;
@ -722,6 +720,62 @@ void selectLevel(void) {
case 27:
inMenu = false;
break;
case 13:
// Actually loaded and redrawn in play loop.
puzzleCurrent = p;
inMenu = false;
break;
case 'I':
case 'i':
// Case when we'll land in the 'dangling' line.
if (p <= dangling) {
p = puzzleCount - (dangling - p);
} else {
// Moving from top to bottom but not into the 'dangling' line.
if (p <= cols) {
p = p - (cols + dangling) + 1;
} else {
// General case to move up a line.
p -= cols;
}
}
break;
case 'J':
case 'j':
if (p > 1) {
p--;
} else {
p = puzzleCount;
}
break;
case 'K':
case 'k':
if (p < puzzleCount) {
p++;
} else {
p = 1;
}
break;
case 'M':
case 'm':
// Are we moving down from the 'dangling' line?
if (p > (cols * (cols - 1))) {
p = dangling - (puzzleCount - p);
} else {
// Moving from bottom to top but not from the 'dangling' line.
if (p > puzzleCount - cols) {
p = p + cols + dangling;
} else {
// General case to move down a line.
p += cols;
}
}
break;
}
}
x = ((p - 1) % cols) * spacingX + marginX;
@ -735,25 +789,21 @@ void selectLevel(void) {
jlDrawBox(x - 1, y - 1, x + 2, y + 2);
lastX = x;
lastY = y;
}
}
printAt(fontI, 5, 0, "Select Your Next Level: %d ", p);
printAt(fontI, 0, 24, "Green are Completed. Red are Unsolved.");
printAt(fontI, 6, 0, "Select Your Next Level: %d ", p);
jlDisplayPresent();
jlKeyWaitForAny();
}
}
jlImgDisplay(screen);
jlImgFree(screen);
}
void showImage(char *name) {
void showImage(jlImgT *image) {
jlImgT *screen = NULL;
jlImgT *image = NULL;
byte key;
//***TODO*** Maybe re-use tilesI to save RAM?
jlImgCreate(screen);
if (!jlImgLoad(image, name)) jlUtilDie("Unable to open %s!", name);
jlImgDisplay(image);
jlDisplayPresent();
@ -765,7 +815,6 @@ void showImage(char *name) {
jlImgDisplay(screen);
jlDisplayPresent();
jlImgFree(image);
jlImgFree(screen);
}
@ -782,13 +831,14 @@ void showPalette(void) {
void ticker(void) {
char *spinner = "/-\\|";
static byte count = 0;
static jint16 last = 0;
static juint16 last = 0;
printAt(fontI, 0, 24, "%d puzzles. Showing #%d. %d/%d %c ",
puzzleCount, puzzleCurrent, cratesOnTarget, crateCount, spinner[count++]);
puzzleCount, puzzleCurrent, cratesOnTarget, crateCount, spinner[count]);
jlDisplayPresent();
if (jlUtilTimeSpan(last, jlUtilTimer()) > 3) {
count++;
if (count > 3) count = 0;
last = jlUtilTimer();
}
@ -797,7 +847,7 @@ void ticker(void) {
void title(void) {
char *images[] = { "kanga", "backgrnd", 0 };
char *images[] = { "kanga", "title", 0 };
byte count = 1; // CHANGE
jlDrawColorSet(0);
@ -832,6 +882,8 @@ int main(void) {
// Load the rest of our data.
if (!jlImgLoad(tilesI, "tiles")) jlUtilDie("Unable to load tiles!");
if (!jlImgLoad(fontI, "font")) jlUtilDie("Unable to load font!");
if (!jlImgLoad(aboutI, "about")) jlUtilDie("Unable to load about!");
if (!jlImgLoad(helpI, "help")) jlUtilDie("Unable to load help!");
// Load the index.
in = fopen("data/index.dat", "rb");
@ -867,6 +919,8 @@ int main(void) {
jlFree(saveGame.solved);
jlFree(puzzleIndex);
jlImgFree(helpI);
jlImgFree(aboutI);
jlImgFree(tilesI);
jlImgFree(fontI);

BIN
warehouse/play.xcf (Stored with Git LFS)

Binary file not shown.

BIN
warehouse/tiles.xcf (Stored with Git LFS)

Binary file not shown.

BIN
warehouse/title.xcf (Stored with Git LFS) Normal file

Binary file not shown.

6
warehouse/updateImages.sh Executable file
View file

@ -0,0 +1,6 @@
#!/bin/bash
for IMAGE in *.xcf; do
echo Converting ${IMAGE}...
$JOEY/joeylib/scripts/xcf2img.sh ${IMAGE}
done