-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.lua
More file actions
39 lines (31 loc) · 695 Bytes
/
Copy pathmap.lua
File metadata and controls
39 lines (31 loc) · 695 Bytes
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
Tile = {}
Tile.__index = Tile
function Tile:new()
local tile = { isBlocking = false }
setmetatable(tile, self)
return tile
end
Map = {}
function Map:new(width, height)
local map = { tiles = {}, width = width, height = height }
setmetatable(map, self)
self.__index = self
map.tilesCount = width * height
for i = 1, map.tilesCount do
map.tiles[i] = Tile:new()
end
return map
end
function Map:getTileIndex(x, y)
return (y - 1) * self.width + x
end
function Map:getTile(x, y)
if x < 1 or x > self.width or y < 1 or y > self.height then
return nil
end
local i = self:getTileIndex(x, y)
if i >= 1 and i <= self.tilesCount then
return self.tiles[i]
end
return nil
end