-
Notifications
You must be signed in to change notification settings - Fork 107
/
castlefire.lua
103 lines (86 loc) · 2.09 KB
/
castlefire.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
92
93
94
95
96
97
98
99
100
101
102
103
castlefire = class:new()
function castlefire:init(x, y, length, dir)
self.x = x
self.y = y+1/16
self.length = length or 6
self.dir = dir or "cw"
self.quadi = 1
self.child = {}
for i = 1, self.length do
local temp = castlefirefire:new()
table.insert(objects["castlefirefire"], temp)
table.insert(self.child, temp)
end
self.angle = 0
self.timer = 0
self.timer2 = 0
self:updatepos()
self:updatequad()
end
function castlefire:update(dt)
self.timer = self.timer + dt
while self.timer > castlefiredelay do
self.timer = self.timer - castlefiredelay
if self.dir == "cw" then
self.angle = self.angle + castlefireangleadd
self.angle = math.fmod(self.angle, 360)
else
self.angle = self.angle - castlefireangleadd
while self.angle < 0 do
self.angle = self.angle + 360
end
end
self:updatepos()
end
self.timer2 = self.timer2 + dt
while self.timer2 > castlefireanimationdelay do
self.timer2 = self.timer2 - castlefireanimationdelay
self.quadi = self.quadi + 1
if self.quadi > 4 then
self.quadi = 1
end
self:updatequad()
end
end
function castlefire:updatepos()
local x = self.x-.5
local y = self.y-.5
for i = 1, self.length do
local xadd = math.cos(math.rad(self.angle))*(i-1)*0.5
local yadd = math.sin(math.rad(self.angle))*(i-1)*0.5
self.child[i].x = x+xadd-0.25
self.child[i].y = y+yadd-0.25
end
end
function castlefire:updatequad()
for i = 1, self.length do
self.child[i].quad = fireballquad[self.quadi]
end
end
--------------
castlefirefire = class:new()
function castlefirefire:init()
--PHYSICS STUFF
self.y = 0
self.x = 0
self.width = 8/16
self.height = 8/16
self.active = true
self.static = true
self.category = 23
self.mask = { true,
true, false, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true}
--IMAGE STUFF
self.drawable = true
self.graphic = fireballimg
self.quad = fireballquad[1]
self.offsetX = 4
self.offsetY = 4
self.quadcenterX = 4
self.quadcenterY = 4
end