-
Notifications
You must be signed in to change notification settings - Fork 0
/
dirttile.lua
51 lines (46 loc) · 1.66 KB
/
dirttile.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
require("lovepunk.entity")
require("dirt")
DirtTile = Entity.new(0, 0, gs-2, gs-2)
DirtTile.__index = DirtTile
function DirtTile.new(x, y, player)
local self = setmetatable({}, DirtTile)
self.player = player
self.x = x+1
self.y = y+1
self.type = ""
self.layer = 11
return self
end
function DirtTile:added()
left = self:collide("level", self.x-2, self.y)
right = self:collide("level", self.x+2, self.y)
down = self:collide("level", self.x, self.y+2)
up = self:collide("level", self.x, self.y-2)
self.x = self.x - 1
self.y = self.y - 1
if (left) then
self.scene:add(Dirt.new(self.x-1, self.y, self.player))
self.scene:add(Dirt.new(self.x-1, self.y+4, self.player))
self.scene:add(Dirt.new(self.x-1, self.y+8, self.player))
self.scene:add(Dirt.new(self.x-1, self.y+12,self.player))
end
if (right) then
self.scene:add(Dirt.new(self.x+gs-3, self.y,self.player))
self.scene:add(Dirt.new(self.x+gs-3, self.y+4,self.player))
self.scene:add(Dirt.new(self.x+gs-3, self.y+8,self.player))
self.scene:add(Dirt.new(self.x+gs-3, self.y+12,self.player))
end
if (down) then
self.scene:add(Dirt.new(self.x, self.y + gs -3,self.player))
self.scene:add(Dirt.new(self.x+4, self.y + gs -3,self.player))
self.scene:add(Dirt.new(self.x+8, self.y + gs -3,self.player))
self.scene:add(Dirt.new(self.x+12, self.y + gs -3,self.player))
end
if (up) then
self.scene:add(Dirt.new(self.x, self.y - 1,self.player))
self.scene:add(Dirt.new(self.x+4, self.y - 1,self.player))
self.scene:add(Dirt.new(self.x+8, self.y - 1,self.player))
self.scene:add(Dirt.new(self.x+12, self.y - 1,self.player))
end
self.scene:remove(self)
end