-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.lua
More file actions
57 lines (46 loc) · 1.37 KB
/
tile.lua
File metadata and controls
57 lines (46 loc) · 1.37 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
Tile = {}
Tile.__index = Tile
--eventually come up with a way to automatically do this, without a need for names
Tile.quads = {}
Tile.quads[0] = love.graphics.newQuad(0,32,32,32,64,64)
Tile.quads[1] = love.graphics.newQuad(0,0,32,32,64,64)
Tile.quads[2] = love.graphics.newQuad(32,0,32,32,64,64)
--todo move callbacks to specific tile type
--needs to have access to player data. A delegate would allow you to avoid
--having to pass player, since the function will be in scope
function Tile:damagePlayer(player)
player:takeDamage(50)
end
function Tile:removeTile(object)
end
function Tile:doNothing(object)
end
--a convenience function that allows for collisioin resolution
--should be added while the game is running when a player is near the tile
local count = 0
function Tile:addBoundingBox(pos, tileSize)
self.box = AABB:new(pos, tileSize, tileSize)
count = count + 1
print(count)
end
Tile.types =
{
plain = function(x) Tile:doNothing(x) end,
damage = function(x) Tile:damagePlayer(x) end,
removable = function(x) Tile:removeTile(x) end
}
function Tile.new(tileType)
--dont need pos since t map can take care of that
local tile = {}
--this is temporary
tile.solid = (tileType ~= 0) or false
if tileType == 2 then
tileType = "damage"
else
tileType = "plain"
end
tile.tileType = tileType
tile.action = Tile.types[tileType]
setmetatable(tile, Tile)
return tile
end