Commit aa94f92e authored by Nicholas Walton's avatar Nicholas Walton

Almost finished the game! No known glitches, performance OK, all game...

Almost finished the game! No known glitches, performance OK, all game screenshots. Needs web page for other games
parent 0f10a449
This diff is collapsed.
......@@ -131,10 +131,10 @@ extern "C"{
}
sb_free(hwalls);
sb_free(vwalls);
return true;
}
bool MazeGenerateAnimated(Grid* grid, Wall** walls, int w, int h, int cell_size, ksprite_t* frame_buffer, bool (*EventCallback)(ksprite_t*, bool*)){
bool disable_animation = false;
bool MazeGenerate(Grid* grid, Wall** walls, int w, int h, int cell_size) {
if(grid->cells){
free(grid->cells);
grid->cells = NULL;
......@@ -143,27 +143,23 @@ extern "C"{
grid->h = h;
grid->cell_size = cell_size;
grid->cells = (uint8_t*)calloc(sizeof(uint8_t), grid->w*grid->h);
int grid_stack[grid->w*grid->h];
int *grid_stack = (int*)malloc(sizeof(int)*grid->w*grid->h);
int grid_stack_top = 0;
int num_cells_to_visit = grid->w*grid->h-1;
typedef enum {
ALeft, AUp, ARight, ADown
} ALGO_DIRECTION;
ALGO_DIRECTION dir = GRID_RIGHT;
ALGO_DIRECTION dir;
int x = rand()%grid->w;
int y = rand()%grid->h;
grid->start.x = x*grid->cell_size;
grid->start.y = y*grid->cell_size;
grid->start.x = x;
grid->start.y = y;
grid_stack[0] = y*grid->w + x;
uint8_t GRID_CELL_VISITED = 0b10000000;
grid->cells[y*grid->w + x] = GRID_CELL_VISITED;
int deepest_cell = 0;
int deepest_cell_depth = 0;
do{
if(!EventCallback(frame_buffer, &disable_animation)){
return false;
}
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
do {
dir = rand();
bool did_visit = false;
for(int direction_attempts = 0; direction_attempts < GRID_DIRECTION_COUNT && !did_visit; ++direction_attempts){
......@@ -173,7 +169,6 @@ extern "C"{
if(x == 0 || grid->cells[y*grid->w + x-1] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_LEFT;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
--x;
grid->cells[y*grid->w + x] |= GRID_RIGHT;
did_visit = true;
......@@ -183,7 +178,6 @@ extern "C"{
if(x == grid->w-1 || grid->cells[y*grid->w + x+1] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_RIGHT;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
++x;
grid->cells[y*grid->w + x] |= GRID_LEFT;
did_visit = true;
......@@ -193,7 +187,6 @@ extern "C"{
if(y == grid->h-1 || grid->cells[(y+1)*grid->w + x] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_UP;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
++y;
grid->cells[y*grid->w + x] |= GRID_DOWN;
did_visit = true;
......@@ -203,7 +196,6 @@ extern "C"{
if(y == 0 || grid->cells[(y-1)*grid->w + x] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_DOWN;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
--y;
grid->cells[y*grid->w + x] |= GRID_UP;
did_visit = true;
......@@ -214,7 +206,7 @@ extern "C"{
if(did_visit){
--num_cells_to_visit;
int new_cell = y*grid->w + x;
grid->cells[new_cell] = grid->cells[new_cell] | GRID_CELL_VISITED;
grid->cells[new_cell] |= GRID_CELL_VISITED;
grid_stack[++grid_stack_top] = new_cell;
if(grid_stack_top > deepest_cell_depth){
deepest_cell_depth = grid_stack_top;
......@@ -225,10 +217,6 @@ extern "C"{
x = grid_stack[grid_stack_top] - y*grid->w;
--grid_stack_top;
}
MazeDrawCell(grid, x, y, frame_buffer, 0xff00ff00);
if(!disable_animation){
KPFlip();
}
} while (num_cells_to_visit);
grid->cells[deepest_cell] |= GRID_CELL_TROPHY;
grid->end.y = deepest_cell / grid->w;
......@@ -240,11 +228,13 @@ extern "C"{
}
}
}
free(grid_stack);
MazeGenerateWalls(grid, walls);
return true;
}
bool MazeGenerate(Grid* grid, Wall** walls, int w, int h, int cell_size) {
bool MazeGenerateAnimated(Grid* grid, Wall** walls, int w, int h, int cell_size, ksprite_t* frame_buffer, bool (*EventCallback)(ksprite_t*, bool*)){
bool disable_animation = false;
if(grid->cells){
free(grid->cells);
grid->cells = NULL;
......@@ -253,23 +243,27 @@ extern "C"{
grid->h = h;
grid->cell_size = cell_size;
grid->cells = (uint8_t*)calloc(sizeof(uint8_t), grid->w*grid->h);
int grid_stack[grid->w*grid->h];
int *grid_stack = (int*)malloc(sizeof(int)*grid->w*grid->h);
int grid_stack_top = 0;
int num_cells_to_visit = grid->w*grid->h-1;
typedef enum {
ALeft, AUp, ARight, ADown
} ALGO_DIRECTION;
ALGO_DIRECTION dir;
ALGO_DIRECTION dir = GRID_RIGHT;
int x = rand()%grid->w;
int y = rand()%grid->h;
grid->start.x = x*grid->cell_size;
grid->start.y = y*grid->cell_size;
grid->start.x = x;
grid->start.y = y;
grid_stack[0] = y*grid->w + x;
uint8_t GRID_CELL_VISITED = 0b10000000;
grid->cells[y*grid->w + x] = GRID_CELL_VISITED;
int deepest_cell = 0;
int deepest_cell_depth = 0;
do {
do{
if(!EventCallback(frame_buffer, &disable_animation)){
return false;
}
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
dir = rand();
bool did_visit = false;
for(int direction_attempts = 0; direction_attempts < GRID_DIRECTION_COUNT && !did_visit; ++direction_attempts){
......@@ -279,6 +273,7 @@ extern "C"{
if(x == 0 || grid->cells[y*grid->w + x-1] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_LEFT;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
--x;
grid->cells[y*grid->w + x] |= GRID_RIGHT;
did_visit = true;
......@@ -288,6 +283,7 @@ extern "C"{
if(x == grid->w-1 || grid->cells[y*grid->w + x+1] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_RIGHT;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
++x;
grid->cells[y*grid->w + x] |= GRID_LEFT;
did_visit = true;
......@@ -297,6 +293,7 @@ extern "C"{
if(y == grid->h-1 || grid->cells[(y+1)*grid->w + x] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_UP;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
++y;
grid->cells[y*grid->w + x] |= GRID_DOWN;
did_visit = true;
......@@ -306,6 +303,7 @@ extern "C"{
if(y == 0 || grid->cells[(y-1)*grid->w + x] & GRID_CELL_VISITED){
}else{
grid->cells[y*grid->w + x] |= GRID_DOWN;
MazeDrawCell(grid, x, y, frame_buffer, 0xff880088);
--y;
grid->cells[y*grid->w + x] |= GRID_UP;
did_visit = true;
......@@ -316,7 +314,7 @@ extern "C"{
if(did_visit){
--num_cells_to_visit;
int new_cell = y*grid->w + x;
grid->cells[new_cell] |= GRID_CELL_VISITED;
grid->cells[new_cell] = grid->cells[new_cell] | GRID_CELL_VISITED;
grid_stack[++grid_stack_top] = new_cell;
if(grid_stack_top > deepest_cell_depth){
deepest_cell_depth = grid_stack_top;
......@@ -327,6 +325,10 @@ extern "C"{
x = grid_stack[grid_stack_top] - y*grid->w;
--grid_stack_top;
}
MazeDrawCell(grid, x, y, frame_buffer, 0xff00ff00);
if(!disable_animation){
KPFlip();
}
} while (num_cells_to_visit);
grid->cells[deepest_cell] |= GRID_CELL_TROPHY;
grid->end.y = deepest_cell / grid->w;
......@@ -338,6 +340,7 @@ extern "C"{
}
}
}
free(grid_stack);
MazeGenerateWalls(grid, walls);
return true;
}
......@@ -347,4 +350,4 @@ extern "C"{
#endif
#define MAZE_H
#endif
\ No newline at end of file
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment