-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.lua
98 lines (82 loc) · 2.79 KB
/
world.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
local s = require('setup')
local World = {}
function World.new()
local self = {}
local flip = 0
-- Map -----------------------------------------------------------
function self:loadMap(level)
local map = {}
local path =
s.levels.folder .. '/' ..
tostring(level) ..
'.' .. s.levels.extension
for line in love.filesystem.lines(path) do
local lines = {}
for char in string.gmatch(line, s.levels.charsRegex) do
table.insert(lines, char)
end
table.insert(map, lines)
end
return map
end
local map1 = self:loadMap(1)
local map2 = self:loadMap(2)
-- function self:getMap() return map end
-- Update --------------------------------------------------------
function self:update(dt)
if love.keyboard.isDown('w') then flip = 0 end
if love.keyboard.isDown('s') then flip = 1 end
end
-- Draw ----------------------------------------------------------
function self:draw()
self:drawTiles2()
self:drawTiles()
end
function self:drawTiles()
local rowFirst
local rowLast
if flip == 0 then
rowFirst = 1
rowLast = s.tiles.numRows
elseif flip == 1 then
rowFirst = s.tiles.numRows
rowLast = 1
end
for row = rowFirst, rowLast do
for col = 1, s.tiles.numCols, 1 do
local x = ((col - 1) * s.tiles.size)
local y = ((row - 1) * s.tiles.size)
local w = s.tiles.size
local h = s.tiles.size
-- Tile
local tileCode = map1[row][col]
love.graphics.setColor(s.colors.tiles[tileCode])
love.graphics.rectangle('fill', x, y, w, h)
-- Grid
love.graphics.setColor(s.colors.grid)
love.graphics.setLineWidth(1)
love.graphics.rectangle('line', x, y, w, h)
end
end
end
function self:drawTiles2()
for row = 1, s.tiles.numRows, 1 do
for col = 1, s.tiles.numCols, 1 do
local x = ((col - 1) * s.tiles.size)
local y = ((row - 1) * s.tiles.size)
local w = s.tiles.size
local h = s.tiles.size
-- Tile
local tileCode = map2[row][col]
love.graphics.setColor(s.colors.tiles2[tileCode])
love.graphics.rectangle('fill', x, y, w, h)
-- Grid
love.graphics.setColor(s.colors.grid)
love.graphics.setLineWidth(1)
love.graphics.rectangle('line', x, y, w, h)
end
end
end
return self
end
return World