-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
104 lines (93 loc) · 3.55 KB
/
main.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
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
function love.load()
TileSet = love.graphics.newImage('res/countryside.png')
tileW, tileH = 32, 32
local tileSetW, tileSetH = TileSet:getWidth(), TileSet:getHeight()
-- Quads = {}
-- Quads[1] = love.graphics.newQuad(0, 0, tileW, tileH, tileSetW, tileSetH)
-- Quads[2] = love.graphics.newQuad(32, 0, tileW, tileH, tileSetW, tileSetH)
-- Quads[3] = love.graphics.newQuad(0, 32, tileW, tileH, tileSetW, tileSetH)
-- Quads[4] = love.graphics.newQuad(32, 32, tileW, tileH, tileSetW, tileSetH)
--[[ 1 grass
2 box
3 flower
4 boxtop
]]
TileTable = {
{4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4},
{4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 4},
{4, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 4},
{4, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4},
{4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4},
{4, 1, 1, 4, 1, 1, 1, 1, 1, 2, 2, 1, 1, 4, 1, 1, 1, 4, 1, 4, 2, 2, 1,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in ipairs(quadInfos) do
-- Quads[i] = love.graphics.newQuad(info[1], info[2], tileW, tileH, tileSetW, tileSetH)
-- end
Quads = {}
for _, info in ipairs(quadInfos) do
Quads[info[1]] = love.graphics.newQuad(info[2], info[3], tileW, tileH, tileSetW, tileSetH)
end
tileString = [[
^#######################^
^ * ^
^ * ^
^ * ^
^ ^
^ ## ^## ^## ^ ^ ^
^ ^ ^ ^ ^ ^ ^ ^ ^
^ ^ ^ ^ *# ^ ^ ^ ^
^ ^ ^ ^## ^## # # ^
^ ^ ^ ^ ^ ^ ^ * ^
^ * ^ ^ ^ ^ ^ ^ ^
^ # # ^* # ^ * ^ ^
^ ## ### ### # ^
^ ^
^ ***************** ^
^ ^
^ * * ^
#########################
]]
TileTable = {}
local width = #tileString:gmatch("[^\n]+")
for x = 1, width, 1 do TileTable[x] = {} end
local rowIndex, columnIndex = 1, 1
for row in tileString:gmatch("[^\n]") do
assert(#row == width, 'Map not align')
columnIndex = 1
for character in row:gmatch(".") do
TileTable[columnIndex][rowIndex] = character
columnIndex = columnIndex + 1
end
rowIndex = rowIndex + 1
end
end
function love.update(dt)
end
function love.draw()
for rowIndex = 1, #TileTable do
local row = TileTable[rowIndex]
for columnIndex = 1, #row do
local number = row[columnIndex]
love.graphics.draw(TileSet, Quads[number],(columnIndex - 1) * tileW,(rowIndex - 1) * tileH)
end
end
end