-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdsrender.lua
More file actions
65 lines (44 loc) · 1.26 KB
/
Copy pathdsrender.lua
File metadata and controls
65 lines (44 loc) · 1.26 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local coroutine = _tl_compat and _tl_compat.coroutine or coroutine
local yield = coroutine.yield
local gr = love.graphics
local serpent = require('serpent')
local color = require('height_map').color
local map = {}
local square_width = 32
local mapSize = 0
local function new(data)
local ok, t = serpent.load(data)
if not ok then
error('Could not load data to dsrender')
end
mapSize = #map
return t
end
local function render()
local x, y = 0, 0
for i = 1, mapSize do
for j = 1, mapSize do
local c = map[i] and map[i][j] or nil
if c then
gr.setColor(color(c ^ 2))
gr.rectangle("fill",
x + square_width * i, y + square_width * j,
square_width, square_width)
end
end
end
end
while true do
local cmd
repeat
cmd = graphic_command_channel:demand()
if cmd == "new" then
map = new(graphic_command_channel:demand())
elseif cmd == "render" then
render()
else
error('dsrender unkonwn command: ' .. cmd)
end
until not cmd
yield()
end