forked from Mari0-CE/Mari0-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fireball.lua
156 lines (131 loc) · 3.42 KB
/
fireball.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
fireball = class("fireball")
function fireball:init(x, y, dir, v)
--PHYSICS STUFF
self.y = y+4/16
self.speedy = 0
if dir == "right" then
self.speedx = fireballspeed
self.x = x+6/16
else
self.speedx = -fireballspeed
self.x = x
end
self.width = 8/16
self.height = 8/16
self.active = true
self.static = false
self.category = 13
self.mask = { true,
false, true, false, false, true,
false, true, false, true, false,
false, true, false, true, false,
true, true, false, false, false,
false, true, false, false, true,
false, false, false, false, true}
self.destroy = false
self.destroysoon = false
--self.gravity = 40
--IMAGE STUFF
self.drawable = true
self.graphic = fireballimg
self.quad = fireballquad[1]
self.offsetX = 4
self.offsetY = 4
self.quadcenterX = 4
self.quadcenterY = 4
self.fireballthrower = v
self.rotation = 0 --for portals
self.gravitydirection = math.pi/2
self.timer = 0
self.quadi = 1
self.emancipatecheck = true
end
function fireball:update(dt)
--rotate back to 0 (portals)
self.rotation = 0
--animate
self.timer = self.timer + dt
if self.destroysoon == false then
while self.timer > staranimationdelay do
self.quadi = self.quadi + 1
if self.quadi == 5 then
self.quadi = 1
end
self.quad = fireballquad[self.quadi]
self.timer = self.timer - staranimationdelay
end
else
while self.timer > staranimationdelay do
self.quadi = self.quadi + 1
if self.quadi == 8 then
self.destroy = true
self.quadi = 7
end
self.quad = fireballquad[self.quadi]
self.timer = self.timer - staranimationdelay
end
end
if self.x < xscroll-1 or self.x > xscroll+width+1 or self.y > mapheight and self.active then
self.fireballthrower:fireballcallback()
self.destroy = true
end
if self.destroy then
return true
else
return false
end
end
function fireball:leftcollide(a, b)
self.x = self.x-.5
self:hitstuff(a, b)
self.speedx = fireballspeed
return false
end
function fireball:rightcollide(a, b)
self:hitstuff(a, b)
self.speedx = -fireballspeed
return false
end
function fireball:floorcollide(a, b)
if a ~= "tile" and a ~= "portalwall" then
self:hitstuff(a, b)
end
self.speedy = -fireballjumpforce
return false
end
function fireball:ceilcollide(a, b)
self:hitstuff(a, b)
end
function fireball:passivecollide(a, b)
self:ceilcollide(a, b)
return false
end
function fireball:hitstuff(a, b)
if a == "tile" or a == "bulletbill" or a == "portalwall" or a == "spring" then
self:explode()
playsound("blockhit")
elseif a == "enemy" or a == "bowser" then
if b:shotted("right", false, false, true) ~= false then
if a ~= "bowser" then
addpoints(b.firepoints or 200, self.x, self.y)
end
end
self:explode()
end
end
function fireball:explode()
if self.active then
self.fireballthrower:fireballcallback()
self.destroysoon = true
self.quadi = 5
self.quad = fireballquad[self.quadi]
self.active = false
end
end
function fireball:emancipate()
if not self.kill then
table.insert(emancipateanimations, emancipateanimation:new(self.x, self.y, self.width, self.height, self.graphic, self.quad, self.speedx, self.speedy, self.rotation, self.offsetX, self.offsetY, self.quadcenterX, self.quadcenterY))
self.kill = true
self.drawable = false
end
end