Skip to content

Instantly share code, notes, and snippets.

@JoeStrout
Created April 7, 2023 23:38
Show Gist options
  • Save JoeStrout/2b6874ef5d578c23621611e60f92eb35 to your computer and use it in GitHub Desktop.
Save JoeStrout/2b6874ef5d578c23621611e60f92eb35 to your computer and use it in GitHub Desktop.
Map.getDrawInfo = function(display, x, y, renderOffset)
//if self.isEntityAt(point.make(x, y)) then return
rx = renderOffset.x + x
ry = renderOffset.y + y
if not math.isInRange(rx, 0, SCREEN_MAX_X) or not math.isInRange(ry, 0, SCREEN_MAX_Y) then
clear
print "ERROR: getDrawInfo called out of range"
exit
return
end if
if not math.isInRange(x, 0, self.width - 1) or not math.isInRange(y, 0, self.height - 1) then
return [color.black, color.gray, "#"]
end if
t = self.tiles[y][x]
if t.isCurrentlyVisible then
return t.getDrawInfo(false)
else if t.hasBeenVisited then
return t.getDrawInfo(true)
else
return [color.black, color.gray, "#"]
end if
end function
Map.draw = function(display, player, renderOffset)
//halfHeight = self.height / 2
//halfWidth = self.width / 2
halfHeight = 26 / 2
halfWidth = 64 / 2
minx = -renderOffset.x
maxx = minx + SCREEN_MAX_X
miny = -renderOffset.y
maxy = miny + SCREEN_MAX_Y
display.row = 24; display.column = 0;
display.row = 25; display.column = 0
curRun = null
for y in range(maxy, miny) // (since Y is inverted)
for x in range(minx, maxx)
info = self.getDrawInfo(display, x, y, renderOffset)
if curRun[:2] == info[:2] then
curRun[2] += info[2]
else
if curRun then
display.backColor = curRun[0]
display.color = curRun[1]
display.print curRun[2]
end if
curRun = info
end if
end for
end for
display.backColor = curRun[0]
display.color = curRun[1]
// careful about the very last one -- we don't want to trigger a scroll
display.print curRun[2][:-1]
display.setCellBackColor display.column, display.row, curRun[2][0]
display.setCellColor display.column, display.row, curRun[2][1]
display.setCell display.column, display.row, curRun[2][2]
end function
Tile.getDrawInfo = function(dim=false)
fg = self.foregroundColor
bg = self.backgroundColor
if dim then
if fg isa Color then fg = fg.darker.str else fg = "#444444"
if bg isa Color then bg = bg.darker.str else bg = color.black
else
if fg isa Color then fg = fg.str
if bg isa Color then bg = bg.str
end if
return [bg, fg, self.char]
end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment