Level selection working.
This commit is contained in:
parent
8bb1091352
commit
68061ae7ae
10 changed files with 128 additions and 66 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,3 +8,5 @@ build-*-Debug
|
||||||
*.stn
|
*.stn
|
||||||
*.img
|
*.img
|
||||||
*.sym
|
*.sym
|
||||||
|
*.png
|
||||||
|
*.jpg
|
||||||
|
|
BIN
warehouse/about.xcf
(Stored with Git LFS)
BIN
warehouse/about.xcf
(Stored with Git LFS)
Binary file not shown.
BIN
warehouse/backgrnd.xcf
(Stored with Git LFS)
BIN
warehouse/backgrnd.xcf
(Stored with Git LFS)
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
PROJECT=Warehouse
|
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=(*.c *.h)
|
||||||
SOURCE=()
|
SOURCE=()
|
||||||
|
|
||||||
|
|
BIN
warehouse/help.xcf
(Stored with Git LFS)
Normal file
BIN
warehouse/help.xcf
(Stored with Git LFS)
Normal file
Binary file not shown.
164
warehouse/main.c
164
warehouse/main.c
|
@ -70,9 +70,12 @@ typedef struct CoordS {
|
||||||
|
|
||||||
static jlImgT *fontI = NULL;
|
static jlImgT *fontI = NULL;
|
||||||
static jlImgT *tilesI = NULL;
|
static jlImgT *tilesI = NULL;
|
||||||
|
static jlImgT *aboutI = NULL;
|
||||||
|
static jlImgT *helpI = NULL;
|
||||||
|
|
||||||
static jint16 puzzleCount;
|
static jint16 puzzleCount;
|
||||||
static jint16 puzzleCurrent;
|
static jint16 puzzleCurrent;
|
||||||
|
static jint16 puzzleLast;
|
||||||
|
|
||||||
static jint32 *puzzleIndex = NULL;
|
static jint32 *puzzleIndex = NULL;
|
||||||
|
|
||||||
|
@ -119,7 +122,7 @@ bool readInput(byte *key);
|
||||||
void redraw(void);
|
void redraw(void);
|
||||||
void resetPuzzle(void);
|
void resetPuzzle(void);
|
||||||
void selectLevel(void);
|
void selectLevel(void);
|
||||||
void showImage(char *name);
|
void showImage(jlImgT *image);
|
||||||
void showPalette(void);
|
void showPalette(void);
|
||||||
void ticker(void);
|
void ticker(void);
|
||||||
void title(void);
|
void title(void);
|
||||||
|
@ -318,6 +321,8 @@ bool mainMenu(void) {
|
||||||
bool running = true;
|
bool running = true;
|
||||||
char choice = 0;
|
char choice = 0;
|
||||||
|
|
||||||
|
//***TODO*** Reset disk?
|
||||||
|
|
||||||
while ((choice >= 0) && running && !jlUtilMustExit()) {
|
while ((choice >= 0) && running && !jlUtilMustExit()) {
|
||||||
choice = menu("Main Menu", options, choice, 0, 0, 0);
|
choice = menu("Main Menu", options, choice, 0, 0, 0);
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
|
@ -326,15 +331,19 @@ bool mainMenu(void) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // About
|
case 1: // About
|
||||||
showImage("about");
|
showImage(aboutI);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // How to Play
|
case 2: // How to Play
|
||||||
showImage("play");
|
showImage(helpI);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // Select Level
|
case 3: // Select Level
|
||||||
selectLevel();
|
selectLevel();
|
||||||
|
if (puzzleLast != puzzleCurrent) {
|
||||||
|
// New puzzle selected, exit menu.
|
||||||
|
choice = -1;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4: // Reset Level
|
case 4: // Reset Level
|
||||||
|
@ -372,7 +381,7 @@ char menu(char *title, char *menuItems[], char selected, byte width, byte offset
|
||||||
jint16 ypos;
|
jint16 ypos;
|
||||||
jint16 last;
|
jint16 last;
|
||||||
jint16 lastY;
|
jint16 lastY;
|
||||||
jlImgT *screen = NULL; //***TODO*** Maybe re-use tilesI to save RAM?
|
jlImgT *screen = NULL;
|
||||||
|
|
||||||
jlImgCreate(screen);
|
jlImgCreate(screen);
|
||||||
|
|
||||||
|
@ -457,7 +466,6 @@ void moveCrate(byte sx, byte sy, byte dx, byte dy) {
|
||||||
|
|
||||||
|
|
||||||
void play(void) {
|
void play(void) {
|
||||||
jint16 last = 0;
|
|
||||||
byte key = 0;
|
byte key = 0;
|
||||||
bool playing = true;
|
bool playing = true;
|
||||||
byte tile = 0;
|
byte tile = 0;
|
||||||
|
@ -479,22 +487,6 @@ void play(void) {
|
||||||
if (playing) redraw();
|
if (playing) redraw();
|
||||||
break;
|
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':
|
||||||
case 'i':
|
case 'i':
|
||||||
// Can we move up?
|
// Can we move up?
|
||||||
|
@ -564,9 +556,9 @@ void play(void) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Load new level? ***REMOVE***
|
// Load new level?
|
||||||
if (last != puzzleCurrent) {
|
if (puzzleLast != puzzleCurrent) {
|
||||||
last = puzzleCurrent;
|
puzzleLast = puzzleCurrent;
|
||||||
loadPuzzle(puzzleCurrent);
|
loadPuzzle(puzzleCurrent);
|
||||||
avatarXLast = -1;
|
avatarXLast = -1;
|
||||||
avatarYLast = -1;
|
avatarYLast = -1;
|
||||||
|
@ -651,21 +643,25 @@ void resetPuzzle(void) {
|
||||||
|
|
||||||
|
|
||||||
void selectLevel(void) {
|
void selectLevel(void) {
|
||||||
jint16 x;
|
jint16 x;
|
||||||
jint16 y;
|
jint16 y;
|
||||||
jint16 lastX;
|
jint16 lastX;
|
||||||
jint16 lastY;
|
jint16 lastY;
|
||||||
jint16 p;
|
jint16 p;
|
||||||
jint16 c = 0;
|
jint16 c = 0;
|
||||||
jint16 index = -1;;
|
jint16 index = -1;
|
||||||
jint16 marginX = 16;
|
jint16 marginX = 16;
|
||||||
jint16 marginY = 16;
|
jint16 marginY = 16;
|
||||||
jint16 spacingX;
|
jint16 spacingX;
|
||||||
jint16 spacingY;
|
jint16 spacingY;
|
||||||
jint16 cols = (jint16)(sqrt(puzzleCount) + 0.5f);
|
jint16 cols = (jint16)(sqrt(puzzleCount) + 0.5f);
|
||||||
char bit = 0;
|
jint16 dangling = puzzleCount - (cols * (cols - 1));
|
||||||
byte data;
|
char bit = 0;
|
||||||
bool inMenu = true;
|
byte data;
|
||||||
|
bool inMenu = true;
|
||||||
|
jlImgT *screen = NULL;
|
||||||
|
|
||||||
|
jlImgCreate(screen);
|
||||||
|
|
||||||
jlPaletteSet( 0, 0, 0, 0);
|
jlPaletteSet( 0, 0, 0, 0);
|
||||||
jlPaletteSet( 1, 0, 15, 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;
|
p = puzzleCurrent;
|
||||||
lastX = -1;
|
lastX = -1;
|
||||||
lastY = -1;
|
lastY = -1;
|
||||||
|
@ -722,6 +720,62 @@ void selectLevel(void) {
|
||||||
case 27:
|
case 27:
|
||||||
inMenu = false;
|
inMenu = false;
|
||||||
break;
|
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;
|
x = ((p - 1) % cols) * spacingX + marginX;
|
||||||
|
@ -735,25 +789,21 @@ void selectLevel(void) {
|
||||||
jlDrawBox(x - 1, y - 1, x + 2, y + 2);
|
jlDrawBox(x - 1, y - 1, x + 2, y + 2);
|
||||||
lastX = x;
|
lastX = x;
|
||||||
lastY = y;
|
lastY = y;
|
||||||
|
printAt(fontI, 6, 0, "Select Your Next Level: %d ", p);
|
||||||
|
jlDisplayPresent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printAt(fontI, 5, 0, "Select Your Next Level: %d ", p);
|
jlImgDisplay(screen);
|
||||||
printAt(fontI, 0, 24, "Green are Completed. Red are Unsolved.");
|
jlImgFree(screen);
|
||||||
|
|
||||||
jlDisplayPresent();
|
|
||||||
jlKeyWaitForAny();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void showImage(char *name) {
|
void showImage(jlImgT *image) {
|
||||||
jlImgT *screen = NULL;
|
jlImgT *screen = NULL;
|
||||||
jlImgT *image = NULL;
|
|
||||||
byte key;
|
byte key;
|
||||||
|
|
||||||
//***TODO*** Maybe re-use tilesI to save RAM?
|
|
||||||
jlImgCreate(screen);
|
jlImgCreate(screen);
|
||||||
if (!jlImgLoad(image, name)) jlUtilDie("Unable to open %s!", name);
|
|
||||||
|
|
||||||
jlImgDisplay(image);
|
jlImgDisplay(image);
|
||||||
jlDisplayPresent();
|
jlDisplayPresent();
|
||||||
|
@ -765,7 +815,6 @@ void showImage(char *name) {
|
||||||
jlImgDisplay(screen);
|
jlImgDisplay(screen);
|
||||||
jlDisplayPresent();
|
jlDisplayPresent();
|
||||||
|
|
||||||
jlImgFree(image);
|
|
||||||
jlImgFree(screen);
|
jlImgFree(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -780,15 +829,16 @@ void showPalette(void) {
|
||||||
|
|
||||||
|
|
||||||
void ticker(void) {
|
void ticker(void) {
|
||||||
char *spinner = "/-\\|";
|
char *spinner = "/-\\|";
|
||||||
static byte count = 0;
|
static byte count = 0;
|
||||||
static jint16 last = 0;
|
static juint16 last = 0;
|
||||||
|
|
||||||
printAt(fontI, 0, 24, "%d puzzles. Showing #%d. %d/%d %c ",
|
printAt(fontI, 0, 24, "%d puzzles. Showing #%d. %d/%d %c ",
|
||||||
puzzleCount, puzzleCurrent, cratesOnTarget, crateCount, spinner[count++]);
|
puzzleCount, puzzleCurrent, cratesOnTarget, crateCount, spinner[count]);
|
||||||
jlDisplayPresent();
|
jlDisplayPresent();
|
||||||
|
|
||||||
if (jlUtilTimeSpan(last, jlUtilTimer()) > 3) {
|
if (jlUtilTimeSpan(last, jlUtilTimer()) > 3) {
|
||||||
|
count++;
|
||||||
if (count > 3) count = 0;
|
if (count > 3) count = 0;
|
||||||
last = jlUtilTimer();
|
last = jlUtilTimer();
|
||||||
}
|
}
|
||||||
|
@ -797,7 +847,7 @@ void ticker(void) {
|
||||||
|
|
||||||
void title(void) {
|
void title(void) {
|
||||||
|
|
||||||
char *images[] = { "kanga", "backgrnd", 0 };
|
char *images[] = { "kanga", "title", 0 };
|
||||||
byte count = 1; // CHANGE
|
byte count = 1; // CHANGE
|
||||||
|
|
||||||
jlDrawColorSet(0);
|
jlDrawColorSet(0);
|
||||||
|
@ -831,7 +881,9 @@ int main(void) {
|
||||||
|
|
||||||
// Load the rest of our data.
|
// Load the rest of our data.
|
||||||
if (!jlImgLoad(tilesI, "tiles")) jlUtilDie("Unable to load tiles!");
|
if (!jlImgLoad(tilesI, "tiles")) jlUtilDie("Unable to load tiles!");
|
||||||
if (!jlImgLoad(fontI, "font")) jlUtilDie("Unable to load font!");
|
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.
|
// Load the index.
|
||||||
in = fopen("data/index.dat", "rb");
|
in = fopen("data/index.dat", "rb");
|
||||||
|
@ -867,6 +919,8 @@ int main(void) {
|
||||||
|
|
||||||
jlFree(saveGame.solved);
|
jlFree(saveGame.solved);
|
||||||
jlFree(puzzleIndex);
|
jlFree(puzzleIndex);
|
||||||
|
jlImgFree(helpI);
|
||||||
|
jlImgFree(aboutI);
|
||||||
jlImgFree(tilesI);
|
jlImgFree(tilesI);
|
||||||
jlImgFree(fontI);
|
jlImgFree(fontI);
|
||||||
|
|
||||||
|
|
BIN
warehouse/play.xcf
(Stored with Git LFS)
BIN
warehouse/play.xcf
(Stored with Git LFS)
Binary file not shown.
BIN
warehouse/tiles.xcf
(Stored with Git LFS)
BIN
warehouse/tiles.xcf
(Stored with Git LFS)
Binary file not shown.
BIN
warehouse/title.xcf
(Stored with Git LFS)
Normal file
BIN
warehouse/title.xcf
(Stored with Git LFS)
Normal file
Binary file not shown.
6
warehouse/updateImages.sh
Executable file
6
warehouse/updateImages.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
for IMAGE in *.xcf; do
|
||||||
|
echo Converting ${IMAGE}...
|
||||||
|
$JOEY/joeylib/scripts/xcf2img.sh ${IMAGE}
|
||||||
|
done
|
Loading…
Add table
Reference in a new issue