-
Notifications
You must be signed in to change notification settings - Fork 69
/
door.lua
91 lines (73 loc) · 1.77 KB
/
door.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
Door = {solid = true}
Door.__index = Door
--setmetatable(Door,Entity)
local GRAVITY = 550
local SCORE = 50
function Door.create(x,y,dir)
local self = setmetatable({}, Door)
self.alive = true
self.health = 0.3
self.x = x
if dir == "left" then
self.x = self.x+12
end
self.y = y
self.cx = math.floor(x/16)
self.cy = math.floor(y/16)
self.state = 0 -- 0 = closed, 1 = off hinges
self.dir = dir
self.xspeed = 0
self.yspeed = 0
self.bbox = {x=self.x, y=self.y, w=4, h=47}
return self
end
function Door:update(dt)
if self.state == 0 then
if map:hasFire(self.cx, self.cy) or map:hasFire(self.cx, self.cy+1)
or map:hasFire(self.cx, self.cy+2) then
self.health = self.health - dt*0.2
end
if self.health < 0 then
self.state = 1
self.xspeed = math.random(-50,50)
self.yspeed = -100
playSound("door")
end
elseif self.state == 1 then
self.yspeed = self.yspeed + GRAVITY*dt
self.x = self.x + self.xspeed*dt
self.y = self.y + self.yspeed*dt
self.solid = false
if self.y > MAPH then
self.alive = false
end
end
end
function Door:shot(dt,dir)
self.health = self.health - dt
if self.health < 0 then
self.state = 1
self.xspeed = 50*dir
self.yspeed = -100
score = score + SCORE
playSound("door")
stats[5] = stats[5] + math.random(80,120)
end
end
function Door:draw()
if self.health > 0.20 then
love.graphics.draw(img.door, quad.door_normal, self.x-2, self.y+24, self.state*(100+self.yspeed)*self.xspeed*0.0005, 1,1, 0, 24)
else
love.graphics.draw(img.door, quad.door_damaged, self.x-2, self.y+24, self.state*(100+self.yspeed)*self.xspeed*0.0005, 1,1, 0, 24)
end
end
function Door:getBBox()
return self.bbox
end
function Door:collideBox(box)
if self.state == 0 then
return collideBoxes(self.bbox,box)
else
return false
end
end