-
Notifications
You must be signed in to change notification settings - Fork 1
/
sidewinder.c
39 lines (35 loc) · 933 Bytes
/
sidewinder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "maze.h"
#include <stdlib.h>
void sidewinder_map(Map * map) {
int tilesInRun = 0;
Tile * tile;
for (int y = 0; y < map->height; y++) {
for (int x = 0; x < map->width; x++) {
tile = &map->tiles[(y * map->width) + x];
tile->x = x;
tile->y = y;
int shouldClose = 0;
if (x + 1 == map->width || (y + 1 != map->height && rand() % 2 == 0)) {
shouldClose = 1;
}
if (shouldClose) {
int randomTileInRun;
if (tilesInRun == 0) {
randomTileInRun = 0;
} else {
randomTileInRun = (rand() % tilesInRun);
}
map->tiles[((y * map->width) + x) - randomTileInRun].connections |= DOWN;
tilesInRun = 0;
} else {
tile->connections = RIGHT;
tilesInRun++;
}
startRender();
renderMap(map);
debugRenderCursor(x, y, 0, 100, 0);
endRender();
delay(1);
}
}
}