-
Notifications
You must be signed in to change notification settings - Fork 1
/
Map.lua
64 lines (50 loc) · 1.63 KB
/
Map.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
--[[
Structure made for game maps.
]]
local Map = {}
Map.__index = Map
function Map:new(mapName, mapData, mapLevel)
local map = {
props = {
mapName = mapName,
mapData = mapData,
mapLevel = mapLevel,
}
}
setmetatable(map, Map)
return map
end
function Map:getMapLevel()
return self.props["mapLevel"]
end
function Map:getNameMap()
return self.props["mapName"]
end
function Map:getMap()
return self.props["mapData"]
end
-- Return which tile the player is on.
function Map:isColliderInside(x,y)
return self.props["mapData"][y][x]
end
function Map:isCollider(x,y,name)
if x < 2 or y < 2 or x > table.getn(self.props["mapData"][1])-1 or y > table.getn(self.props["mapData"])-1 then return false
elseif self.props["mapData"][y][x] == name then return true
elseif self.props["mapData"][y + 1][x] == name then return true
elseif self.props["mapData"][y - 1][x] == name then return true
elseif self.props["mapData"][y][x + 1] == name then return true
elseif self.props["mapData"][y][x - 1] == name then return true
else return false
end
end
-- Returns which position the player collided with monster
function Map:getMonsterTile(x,y,name)
if self.props["mapData"][y][x] == name then return x,y,name
elseif self.props["mapData"][y + 1][x] == name then return y + 1,x,name
elseif self.props["mapData"][y - 1][x] == name then return y - 1,x,name
elseif self.props["mapData"][y][x + 1] == name then return y,x + 1,name
elseif self.props["mapData"][y][x - 1] == name then return y,x - 1,name
else return false
end
end
return Map