Adding "indent.sh" to re-indent code; ran it!!!
This commit is contained in:
parent
16336cc854
commit
18f9cad6fe
98 changed files with 5798 additions and 9001 deletions
304
magic/src/maze.c
304
magic/src/maze.c
|
|
@ -28,15 +28,16 @@
|
|||
int xm[4] = { 0, 0, -1, 1 };
|
||||
int ym[4] = { -1, 1, 0, 0 };
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
int x, y;
|
||||
} maze_start_t;
|
||||
|
||||
Mix_Chunk *snd_effect = NULL;
|
||||
Uint8 * maze_mask = NULL, * new_maze_mask = NULL, * maze_array = NULL;
|
||||
Uint32 * maze_color;
|
||||
maze_start_t * maze_starts;
|
||||
SDL_Surface * maze_snapshot = NULL;
|
||||
Uint8 *maze_mask = NULL, *new_maze_mask = NULL, *maze_array = NULL;
|
||||
Uint32 *maze_color;
|
||||
maze_start_t *maze_starts;
|
||||
SDL_Surface *maze_snapshot = NULL;
|
||||
Uint8 maze_r, maze_g, maze_b;
|
||||
int maze_start_x, maze_start_y;
|
||||
int num_maze_starts = 0, maze_starts_size = 0;
|
||||
|
|
@ -52,23 +53,17 @@ int maze_requires_colors(magic_api * api, int which);
|
|||
int maze_modes(magic_api * api, int which);
|
||||
void maze_shutdown(magic_api * api);
|
||||
void maze_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x,
|
||||
int y, SDL_Rect * update_rect);
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void maze_set_color(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * last, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect);
|
||||
void maze_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
void maze_line_callback_drag(void *ptr, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int x, int y);
|
||||
SDL_Surface * snapshot, int ox, int oy, int x, int y, SDL_Rect * update_rect);
|
||||
void maze_line_callback_drag(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y);
|
||||
void maze_release(magic_api * api, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int x, int y,
|
||||
SDL_Rect * update_rect);
|
||||
SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect);
|
||||
void maze_render(magic_api * api, SDL_Surface * canvas);
|
||||
void maze_switchin(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas);
|
||||
void maze_switchout(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas);
|
||||
void maze_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void maze_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||
void zero_maze_arrays(SDL_Surface * canvas);
|
||||
void draw_hall(SDL_Surface * canvas, int x, int y);
|
||||
void maze_add_start(void);
|
||||
|
|
@ -76,7 +71,8 @@ int check_arrays(void);
|
|||
void maze_collapse_contiguous(SDL_Surface * canvas);
|
||||
Uint8 maze_accepted_sizes(magic_api * api, int which, int mode);
|
||||
Uint8 maze_default_size(magic_api * api, int which, int mode);
|
||||
void maze_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size, SDL_Rect * update_rect);
|
||||
void maze_set_size(magic_api * api, int which, int mode, SDL_Surface * canvas, SDL_Surface * last, Uint8 size,
|
||||
SDL_Rect * update_rect);
|
||||
|
||||
|
||||
Uint32 maze_api_version(void)
|
||||
|
|
@ -88,8 +84,7 @@ int maze_init(magic_api * api, Uint32 disabled_features ATTRIBUTE_UNUSED)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%ssounds/magic/maze.ogg",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%ssounds/magic/maze.ogg", api->data_directory);
|
||||
snd_effect = Mix_LoadWAV(fname);
|
||||
|
||||
return (1);
|
||||
|
|
@ -105,42 +100,35 @@ SDL_Surface *maze_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
|
|||
{
|
||||
char fname[1024];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/maze.png",
|
||||
api->data_directory);
|
||||
snprintf(fname, sizeof(fname), "%simages/magic/maze.png", api->data_directory);
|
||||
|
||||
return (IMG_Load(fname));
|
||||
}
|
||||
|
||||
char *maze_get_name(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
char *maze_get_name(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return strdup(gettext("Maze"));
|
||||
}
|
||||
|
||||
int maze_get_group(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
int maze_get_group(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return MAGIC_TYPE_PAINTING;
|
||||
}
|
||||
|
||||
char *maze_get_description(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED,
|
||||
int mode)
|
||||
char *maze_get_description(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode)
|
||||
{
|
||||
if (mode == MODE_PAINT)
|
||||
return(gettext("Click and drag to paint a maze on your picture."));
|
||||
return (gettext("Click and drag to paint a maze on your picture."));
|
||||
else
|
||||
return(gettext("Click to turn your entire picture into a maze."));
|
||||
return (gettext("Click to turn your entire picture into a maze."));
|
||||
}
|
||||
|
||||
int maze_requires_colors(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
int maze_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int maze_modes(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED)
|
||||
int maze_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return MODE_PAINT | MODE_FULLSCREEN;
|
||||
}
|
||||
|
|
@ -164,18 +152,19 @@ void maze_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
|||
}
|
||||
|
||||
/* FIXME */
|
||||
int check_arrays(void) {
|
||||
int check_arrays(void)
|
||||
{
|
||||
if (maze_array == NULL || maze_mask == NULL || new_maze_mask == NULL ||
|
||||
maze_color == NULL || maze_snapshot == NULL || maze_starts == NULL) {
|
||||
return(0);
|
||||
maze_color == NULL || maze_snapshot == NULL || maze_starts == NULL)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
maze_click(magic_api * api, int which, int mode,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y,
|
||||
SDL_Rect * update_rect)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
if (!check_arrays())
|
||||
return;
|
||||
|
|
@ -186,9 +175,12 @@ maze_click(magic_api * api, int which, int mode,
|
|||
maze_start_x = floor(x / MAZE_BLOCK_SIZE) * MAZE_BLOCK_SIZE + (MAZE_BLOCK_SIZE / 2);
|
||||
maze_start_y = floor(y / MAZE_BLOCK_SIZE) * MAZE_BLOCK_SIZE + (MAZE_BLOCK_SIZE / 2);
|
||||
|
||||
if (mode == MODE_PAINT) {
|
||||
if (mode == MODE_PAINT)
|
||||
{
|
||||
maze_drag(api, which, canvas, snapshot, x, y, x, y, update_rect);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Uint32 color;
|
||||
|
||||
maze_add_start();
|
||||
|
|
@ -216,14 +208,13 @@ maze_click(magic_api * api, int which, int mode,
|
|||
|
||||
void
|
||||
maze_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
|
||||
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
|
||||
SDL_Surface * snapshot, int ox ATTRIBUTE_UNUSED,
|
||||
int oy ATTRIBUTE_UNUSED, int x, int y, SDL_Rect * update_rect)
|
||||
{
|
||||
if (!check_arrays())
|
||||
return;
|
||||
|
||||
api->line((void *) api, which, canvas, snapshot, ox, oy, x, y, 1,
|
||||
maze_line_callback_drag);
|
||||
api->line((void *)api, which, canvas, snapshot, ox, oy, x, y, 1, maze_line_callback_drag);
|
||||
|
||||
update_rect->x = 0;
|
||||
update_rect->y = 0;
|
||||
|
|
@ -234,8 +225,8 @@ maze_drag(magic_api * api ATTRIBUTE_UNUSED, int which, SDL_Surface * canvas,
|
|||
|
||||
void maze_release(magic_api * api, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED,
|
||||
SDL_Rect * update_rect) {
|
||||
int x ATTRIBUTE_UNUSED, int y ATTRIBUTE_UNUSED, SDL_Rect * update_rect)
|
||||
{
|
||||
if (snd_effect != NULL)
|
||||
api->stopsound();
|
||||
|
||||
|
|
@ -266,27 +257,34 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
|
|||
|
||||
/* Reset everything we've drawn [back to] wall: */
|
||||
memset(maze_array, MAZE_HALL, (canvas->w * canvas->h));
|
||||
for (y = 0; y < canvas->h; y++) {
|
||||
for (x = 0; x < canvas->w; x++) {
|
||||
if (maze_mask[y * canvas->w + x]) {
|
||||
for (y = 0; y < canvas->h; y++)
|
||||
{
|
||||
for (x = 0; x < canvas->w; x++)
|
||||
{
|
||||
if (maze_mask[y * canvas->w + x])
|
||||
{
|
||||
maze_array[y * canvas->w + x] = MAZE_WALL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Render a maze! */
|
||||
for (s = 0; s < num_maze_starts; s++) {
|
||||
for (s = 0; s < num_maze_starts; s++)
|
||||
{
|
||||
x = maze_starts[s].x;
|
||||
y = maze_starts[s].y;
|
||||
|
||||
/* Render from here, ONLY if it's still non-contiguous to anything: */
|
||||
if (maze_mask[y * canvas->w + x] == s + 1) {
|
||||
if (maze_mask[y * canvas->w + x] == s + 1)
|
||||
{
|
||||
maze_array[y * canvas->w + x] = MAZE_START;
|
||||
|
||||
state = STATE_PICKDIR;
|
||||
iter = 0;
|
||||
do {
|
||||
if (state == STATE_PICKDIR) {
|
||||
do
|
||||
{
|
||||
if (state == STATE_PICKDIR)
|
||||
{
|
||||
dir = (rand() % 4);
|
||||
old_dir = dir;
|
||||
}
|
||||
|
|
@ -296,7 +294,8 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
|
|||
nx = x + (xm[dir] * MAZE_BLOCK_SIZE * 2);
|
||||
ny = y + (ym[dir] * MAZE_BLOCK_SIZE * 2);
|
||||
|
||||
if (nx >= 0 && nx < canvas->w && ny >= 0 && ny < canvas->h && maze_array[ny * canvas->w + nx] == MAZE_WALL) {
|
||||
if (nx >= 0 && nx < canvas->w && ny >= 0 && ny < canvas->h && maze_array[ny * canvas->w + nx] == MAZE_WALL)
|
||||
{
|
||||
draw_hall(canvas, nx, ny);
|
||||
maze_array[ny * canvas->w + nx] = dir + 1;
|
||||
|
||||
|
|
@ -310,18 +309,21 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
|
|||
state = STATE_PICKDIR;
|
||||
}
|
||||
|
||||
if (state == STATE_DONE) {
|
||||
if (state == STATE_DONE)
|
||||
{
|
||||
dir = (dir + 1) % 4;
|
||||
|
||||
if (dir != old_dir)
|
||||
state = STATE_KEEPGOING;
|
||||
}
|
||||
|
||||
if (state == STATE_DONE) {
|
||||
if (state == STATE_DONE)
|
||||
{
|
||||
dir = maze_array[y * canvas->w + x];
|
||||
draw_hall(canvas, x, y);
|
||||
|
||||
if (dir != MAZE_START) {
|
||||
if (dir != MAZE_START)
|
||||
{
|
||||
x = x - (xm[dir - 1] * MAZE_BLOCK_SIZE * 2);
|
||||
y = y - (ym[dir - 1] * MAZE_BLOCK_SIZE * 2);
|
||||
|
||||
|
|
@ -335,11 +337,16 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
|
|||
}
|
||||
|
||||
/* Draw the maze onto the canvas */
|
||||
for (y = 0; y < canvas->h; y++) {
|
||||
for (x = 0; x < canvas->w; x++) {
|
||||
if (maze_array[y * canvas->w + x] == MAZE_WALL) {
|
||||
for (y = 0; y < canvas->h; y++)
|
||||
{
|
||||
for (x = 0; x < canvas->w; x++)
|
||||
{
|
||||
if (maze_array[y * canvas->w + x] == MAZE_WALL)
|
||||
{
|
||||
api->putpixel(canvas, x, y, maze_color[y * canvas->w + x]);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
api->putpixel(canvas, x, y, api->getpixel(maze_snapshot, x, y));
|
||||
}
|
||||
}
|
||||
|
|
@ -348,7 +355,8 @@ void maze_render(magic_api * api, SDL_Surface * canvas)
|
|||
|
||||
|
||||
void maze_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 r, Uint8 g, Uint8 b,
|
||||
SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
maze_r = r;
|
||||
maze_g = g;
|
||||
|
|
@ -357,9 +365,7 @@ void maze_set_color(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED
|
|||
|
||||
|
||||
void maze_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas,
|
||||
SDL_Surface * snapshot ATTRIBUTE_UNUSED,
|
||||
int x, int y)
|
||||
SDL_Surface * canvas, SDL_Surface * snapshot ATTRIBUTE_UNUSED, int x, int y)
|
||||
{
|
||||
magic_api *api = (magic_api *) ptr;
|
||||
int xx, yy, idx;
|
||||
|
|
@ -373,12 +379,17 @@ void maze_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
|
|||
x = floor(x / (MAZE_BLOCK_SIZE * 3)) * (MAZE_BLOCK_SIZE * 3);
|
||||
y = floor(y / (MAZE_BLOCK_SIZE * 3)) * (MAZE_BLOCK_SIZE * 3);
|
||||
|
||||
for (yy = -MAZE_PAINT_RADIUS; yy < MAZE_PAINT_RADIUS; yy++) {
|
||||
if (y + yy > 0 && y + yy < canvas->h) {
|
||||
for (xx = -MAZE_PAINT_RADIUS; xx < MAZE_PAINT_RADIUS; xx++) {
|
||||
if (x + xx > 0 && x + xx < canvas->w) {
|
||||
for (yy = -MAZE_PAINT_RADIUS; yy < MAZE_PAINT_RADIUS; yy++)
|
||||
{
|
||||
if (y + yy > 0 && y + yy < canvas->h)
|
||||
{
|
||||
for (xx = -MAZE_PAINT_RADIUS; xx < MAZE_PAINT_RADIUS; xx++)
|
||||
{
|
||||
if (x + xx > 0 && x + xx < canvas->w)
|
||||
{
|
||||
idx = (y + yy) * canvas->w + (x + xx);
|
||||
if (maze_mask[idx] == 0) {
|
||||
if (maze_mask[idx] == 0)
|
||||
{
|
||||
maze_mask[idx] = num_maze_starts + 1;
|
||||
}
|
||||
maze_color[idx] = color;
|
||||
|
|
@ -390,80 +401,77 @@ void maze_line_callback_drag(void *ptr, int which ATTRIBUTE_UNUSED,
|
|||
}
|
||||
|
||||
void maze_switchin(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas)
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas)
|
||||
{
|
||||
if (maze_array == NULL)
|
||||
{
|
||||
maze_array = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
|
||||
if (maze_array == NULL)
|
||||
{
|
||||
maze_array = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
|
||||
if (maze_array == NULL)
|
||||
{
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_array!\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_array!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (maze_mask == NULL)
|
||||
{
|
||||
maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
|
||||
if (maze_mask == NULL)
|
||||
{
|
||||
maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
|
||||
if (maze_mask == NULL)
|
||||
{
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_mask!\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_mask!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (new_maze_mask == NULL)
|
||||
{
|
||||
new_maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
|
||||
if (new_maze_mask == NULL)
|
||||
{
|
||||
new_maze_mask = (Uint8 *) malloc(sizeof(Uint8) * canvas->w * canvas->h);
|
||||
if (new_maze_mask == NULL)
|
||||
{
|
||||
fprintf(stderr, "new_maze: Cannot malloc() maze_mask!\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "new_maze: Cannot malloc() maze_mask!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (maze_color == NULL)
|
||||
{
|
||||
maze_color = (Uint32 *) malloc(sizeof(Uint32) * canvas->w * canvas->h);
|
||||
if (maze_color == NULL)
|
||||
{
|
||||
maze_color = (Uint32 *) malloc(sizeof(Uint32) * canvas->w * canvas->h);
|
||||
if (maze_color == NULL)
|
||||
{
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_color!\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_color!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (maze_starts == NULL)
|
||||
{
|
||||
int w, h;
|
||||
w = ceil(canvas->w / MAZE_BLOCK_SIZE);
|
||||
h = ceil(canvas->h / MAZE_BLOCK_SIZE);
|
||||
maze_starts_size = (w * h);
|
||||
{
|
||||
int w, h;
|
||||
|
||||
maze_starts = (maze_start_t *) malloc(sizeof(maze_start_t) * maze_starts_size);
|
||||
if (maze_starts == NULL)
|
||||
{
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_starts!\n");
|
||||
return;
|
||||
}
|
||||
w = ceil(canvas->w / MAZE_BLOCK_SIZE);
|
||||
h = ceil(canvas->h / MAZE_BLOCK_SIZE);
|
||||
maze_starts_size = (w * h);
|
||||
|
||||
maze_starts = (maze_start_t *) malloc(sizeof(maze_start_t) * maze_starts_size);
|
||||
if (maze_starts == NULL)
|
||||
{
|
||||
fprintf(stderr, "maze: Cannot malloc() maze_starts!\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
zero_maze_arrays(canvas);
|
||||
|
||||
if (maze_snapshot == NULL)
|
||||
maze_snapshot = SDL_CreateRGBSurface(SDL_SWSURFACE, canvas->w, canvas->h,
|
||||
canvas->format->BitsPerPixel, canvas->format->Rmask,
|
||||
canvas->format->Gmask, canvas->format->Bmask,
|
||||
canvas->format->Amask);
|
||||
canvas->format->BitsPerPixel, canvas->format->Rmask,
|
||||
canvas->format->Gmask, canvas->format->Bmask, canvas->format->Amask);
|
||||
|
||||
if (maze_snapshot != NULL)
|
||||
SDL_BlitSurface(canvas, NULL, maze_snapshot, NULL);
|
||||
}
|
||||
|
||||
void maze_switchout(magic_api * api ATTRIBUTE_UNUSED,
|
||||
int which ATTRIBUTE_UNUSED,
|
||||
int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||
{
|
||||
zero_maze_arrays(canvas);
|
||||
}
|
||||
|
|
@ -485,13 +493,18 @@ void zero_maze_arrays(SDL_Surface * canvas)
|
|||
memset(maze_color, 0, (sizeof(Uint32) * (canvas->w * canvas->h)));
|
||||
}
|
||||
|
||||
void draw_hall(SDL_Surface * canvas, int x, int y) {
|
||||
void draw_hall(SDL_Surface * canvas, int x, int y)
|
||||
{
|
||||
int xx, yy;
|
||||
|
||||
for (yy = -MAZE_BLOCK_SIZE / 2; yy < MAZE_BLOCK_SIZE / 2; yy++) {
|
||||
if (y + yy >= 0 && y + yy < canvas->h) {
|
||||
for (xx = -MAZE_BLOCK_SIZE / 2; xx < MAZE_BLOCK_SIZE / 2; xx++) {
|
||||
if (x + xx >= 0 && x + xx < canvas->w) {
|
||||
for (yy = -MAZE_BLOCK_SIZE / 2; yy < MAZE_BLOCK_SIZE / 2; yy++)
|
||||
{
|
||||
if (y + yy >= 0 && y + yy < canvas->h)
|
||||
{
|
||||
for (xx = -MAZE_BLOCK_SIZE / 2; xx < MAZE_BLOCK_SIZE / 2; xx++)
|
||||
{
|
||||
if (x + xx >= 0 && x + xx < canvas->w)
|
||||
{
|
||||
maze_array[(y + yy) * canvas->w + (x + xx)] = MAZE_HALL;
|
||||
}
|
||||
}
|
||||
|
|
@ -499,42 +512,59 @@ void draw_hall(SDL_Surface * canvas, int x, int y) {
|
|||
}
|
||||
}
|
||||
|
||||
void maze_add_start(void) {
|
||||
void maze_add_start(void)
|
||||
{
|
||||
maze_starts[num_maze_starts].x = maze_start_x;
|
||||
maze_starts[num_maze_starts].y = maze_start_y;
|
||||
|
||||
num_maze_starts++;
|
||||
}
|
||||
|
||||
void maze_collapse_contiguous(SDL_Surface * canvas) {
|
||||
void maze_collapse_contiguous(SDL_Surface * canvas)
|
||||
{
|
||||
int i, x, y, touching, idx;
|
||||
|
||||
for (i = num_maze_starts; i > 0; i--) {
|
||||
for (i = num_maze_starts; i > 0; i--)
|
||||
{
|
||||
touching = -1;
|
||||
for (y = 1; y < canvas->h - 1 && touching == -1; y++) {
|
||||
for (x = 1; x < canvas->w - 1 && touching == -1; x++) {
|
||||
for (y = 1; y < canvas->h - 1 && touching == -1; y++)
|
||||
{
|
||||
for (x = 1; x < canvas->w - 1 && touching == -1; x++)
|
||||
{
|
||||
idx = (y * canvas->w + x);
|
||||
if (maze_mask[idx] == i + 1) {
|
||||
if (maze_mask[idx - 1] != 0 && maze_mask[idx - 1] != i + 1) {
|
||||
if (maze_mask[idx] == i + 1)
|
||||
{
|
||||
if (maze_mask[idx - 1] != 0 && maze_mask[idx - 1] != i + 1)
|
||||
{
|
||||
touching = maze_mask[idx - 1];
|
||||
} else if (maze_mask[idx + 1] != 0 && maze_mask[idx + 1] != i + 1) {
|
||||
}
|
||||
else if (maze_mask[idx + 1] != 0 && maze_mask[idx + 1] != i + 1)
|
||||
{
|
||||
touching = maze_mask[idx + 1];
|
||||
} else if (maze_mask[idx - canvas->w] != 0 && maze_mask[idx - canvas->w] != i + 1) {
|
||||
}
|
||||
else if (maze_mask[idx - canvas->w] != 0 && maze_mask[idx - canvas->w] != i + 1)
|
||||
{
|
||||
touching = maze_mask[idx - canvas->w];
|
||||
} else if (maze_mask[idx + canvas->w] != 0 && maze_mask[idx + canvas->w] != i + 1) {
|
||||
}
|
||||
else if (maze_mask[idx + canvas->w] != 0 && maze_mask[idx + canvas->w] != i + 1)
|
||||
{
|
||||
touching = maze_mask[idx + canvas->w];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (touching != -1) {
|
||||
if (touching != -1)
|
||||
{
|
||||
/* Touching someone else; turn all of our area
|
||||
into that area */
|
||||
for (y = 1; y < canvas->h; y++) {
|
||||
for (x = 1; x < canvas->w; x++) {
|
||||
for (y = 1; y < canvas->h; y++)
|
||||
{
|
||||
for (x = 1; x < canvas->w; x++)
|
||||
{
|
||||
idx = (y * canvas->w + x);
|
||||
if (maze_mask[idx] == i + 1) {
|
||||
if (maze_mask[idx] == i + 1)
|
||||
{
|
||||
maze_mask[idx] = touching;
|
||||
}
|
||||
}
|
||||
|
|
@ -553,6 +583,8 @@ Uint8 maze_default_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UN
|
|||
return 0;
|
||||
}
|
||||
|
||||
void maze_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED, Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
void maze_set_size(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||
SDL_Surface * canvas ATTRIBUTE_UNUSED, SDL_Surface * last ATTRIBUTE_UNUSED,
|
||||
Uint8 size ATTRIBUTE_UNUSED, SDL_Rect * update_rect ATTRIBUTE_UNUSED)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue