-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
109 lines (101 loc) · 1.88 KB
/
main.lua
File metadata and controls
109 lines (101 loc) · 1.88 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local wfc = require("wfc")
GRID_HEIGHT = 100
GRID_WIDTH = 100
CELL_SIZE = 10
local ruleSet = { RULES = {
{
3, -- sand
10,
0,
0.5,
},
{
2, -- grass
8,
3,
0,
},
{
0, -- mountain
20,
0,
0,
},
{
4, -- water
0,
0,
19,
},
}
}
local ruleSetTWO = {
RULES = {
{
5, -- sand
4,
0,
1,
0.5,
},
{
3, -- grass
9,
2,
0,
1,
},
{
0, -- mountain
20,
0,
0,
2,
},
{
4, -- water
0,
0,
13,
0.5,
},
{
3, -- village
5,
0,
2,
30,
},
}
}
local colors = {
[-1] = {0.5,0.5,0.5},
{1,1,0},
{0,1,0},
{1,1,1},
{0,0,1},
{1,0,1},
}
local wfcInstance = wfc.new(GRID_HEIGHT, GRID_WIDTH, nil, ruleSet, os.time())
wfcInstance.CURRENT_STATE.state = wfc.__createBorder(wfcInstance.CURRENT_STATE.state, 1)
local not_filled = true
wfcInstance:init()
function love.load()
love.window.setMode(1024, 768, {resizable=true, vsync=false, minwidth=800, minheight=600})
while not_filled do
local res = wfcInstance:performStep()
if res == "FILLED" then
not_filled = false
end
end
end
function love.draw()
for y = 1, GRID_HEIGHT do
for x = 1, GRID_WIDTH do
local value = wfcInstance.CURRENT_STATE.state[x][y]
local color = colors[value]
love.graphics.setColor(color)
love.graphics.rectangle("fill", (x-1) * CELL_SIZE, (y-1) * CELL_SIZE, CELL_SIZE, CELL_SIZE)
end
end
end