Skip to content

Instantly share code, notes, and snippets.

@Blecki
Created May 5, 2014 01:41
Show Gist options
  • Select an option

  • Save Blecki/418cba6bb9208331eeb6 to your computer and use it in GitHub Desktop.

Select an option

Save Blecki/418cba6bb9208331eeb6 to your computer and use it in GitHub Desktop.
# Draw a map window
global MAPSIZE:number = 5;
global ExitSymbols:list = { "\\" "|" "/" "-" "X" "-" "/" "|" "\\" };
macro draw (direction:number) at (x:number) (y:number) {
var _x = x + (direction % 3);
var _y = y + [floor (direction / 3)];
move cursor to _x _y;
raw write (ExitSymbols@direction):string;
}
global dm-visited:list;
macro draw (room:room) at (x:number) (y:number) with (link-counter:number) to the (rel:number) {
if x < 0 || x >= MAPSIZE { return; }
if y < 0 || y >= MAPSIZE { return; }
if dm-visited @ (x + (y * MAPSIZE)) == true { return; }
let dm-visited @ (x + (y * MAPSIZE)) = true;
move cursor to ((x * 3) + 1) ((y * 3) + 1);
if link-counter == 2 {
Write "<fGREEN|\x18>";
}
else if link-counter == 1 {
write $"<fRED|<move player [rel]|\x18>>";
}
else {
Write "\x18";
}
foreach exit in room.exits {
var direction = (exit):exit.direction;
draw direction at (x * 3) (y * 3);
var destination = (exit):exit.destination;
if direction == NORTHWEST { draw destination at (x - 1) (y - 1) with (link-counter - 1) to the direction; }
else if direction == NORTH { draw destination at (x) (y - 1) with (link-counter - 1) to the direction; }
else if direction == NORTHEAST { draw destination at (x + 1) (y - 1) with (link-counter - 1) to the direction; }
else if direction == WEST { draw destination at (x - 1) (y) with (link-counter - 1) to the direction; }
else if direction == EAST { draw destination at (x + 1) (y) with (link-counter - 1) to the direction; }
else if direction == SOUTHWEST { draw destination at (x - 1) (y + 1) with (link-counter - 1) to the direction; }
else if direction == SOUTH { draw destination at (x) (y + 1) with (link-counter - 1) to the direction; }
else if direction == SOUTHEAST { draw destination at (x + 1) (y + 1) with (link-counter - 1) to the direction; }
}
}
macro draw (room:room) on map {
let dm-visited = {};
foreach x from 0 to (MAPSIZE * MAPSIZE) {
let dm-visited = [append false to dm-visited];
}
draw room at [floor (MAPSIZE / 2)] [floor (MAPSIZE / 2)] with 2 to the 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment