-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example_-_dijkstra maps.lua
55 lines (50 loc) · 1.12 KB
/
Example_-_dijkstra maps.lua
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
--
map ={}
for x=0,10 do
map[x]={}
for y=0,10 do
map[x][y]=0
end
end
openlist = {}
-- Use this function to perform your initial setup
function setup()
print("Hello World!")
flood()
end
-- This function gets called once every frame
function draw()
-- This sets a dark background color
background(40, 40, 50)
-- This sets the line thickness
strokeWidth(5)
drawmap()
-- Do your drawing here
end
function drawmap()
for y=0,10 do
for x=0,10 do
text(map[x][y],WIDTH-x*30,y*30)
end
end
end
function flood()
dx = {0,1,0,-1}
dy = {-1,0,1,0}
local pos = vec2(5,5)
table.insert(openlist,pos)
while #openlist>0 do
pos = openlist[1]
table.remove(openlist,1)
for i=1,4 do
local nx = pos.x+dx[i]
local ny = pos.y+dy[i]
if nx>-1 and nx<10 and ny>-1 and ny<10 then
if map[pos.x+dx[i]][pos.y+dy[i]] == 0 then
table.insert(openlist,vec2(nx,ny))
map[nx][ny]=map[pos.x][pos.y]+1
end
end
end
end
end