forked from Mari0-CE/Mari0-Community-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulletbill.lua
211 lines (182 loc) · 4.55 KB
/
bulletbill.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
rocketlauncher = class("rocketlauncher")
function rocketlauncher:init(x, y)
self.x = x
self.y = y
self.id = id
self:randomtime()
self.timer = self.time-0.5
self.autodelete = true
end
function rocketlauncher:update(dt)
self.timer = self.timer + dt
if self.timer > self.time and self.x > xscroll and self.x < xscroll+width+2 then
if self:fire() then
self.timer = 0
self:randomtime()
--remove on non solids
if not tilequads[map[self.x][self.y][1]]:getproperty("collision", self.x, self.y) then
return true
else
return false
end
end
end
end
function rocketlauncher:fire()
--count all bullet bills
local count = 0
for i, v in pairs(objects["enemy"]) do
if v.t == "bulletbill" then
count = count + 1
end
end
if count >= maximumbulletbills then
return false
end
--get nearest player
local pl = 1
for i = 2, players do
if math.abs(objects["player"][i].x + 14/16 - self.x) < math.abs(objects["player"][pl].x + 14/16 - self.x) then
pl = i
end
end
if objects["player"][pl].x + 14/16 > self.x + bulletbillrange then
table.insert(objects["enemy"], enemy:new(self.x, self.y, "bulletbill"))
return true
elseif objects["player"][pl].x + 14/16 < self.x - bulletbillrange then
table.insert(objects["enemy"], enemy:new(self.x, self.y, "bulletbill"))
return true
end
end
function rocketlauncher:randomtime()
local rand = math.random(bulletbilltimemin*10, bulletbilltimemax*10)/10
self.time = rand
end
----------------------
--[[
bulletbill = class("bulletbill")
function bulletbill:init(x, y, dir)
self.startx = x-14/16
--PHYSICS STUFF
self.x = self.startx
self.y = y-14/16
self.speedy = 0
if dir == "left" then
self.speedx = -bulletbillspeed
self.customscissor = {self.x-18/16, self.y-2/16, 1, 1}
else
self.speedx = bulletbillspeed
self.customscissor = {self.x+14/16, self.y-2/16, 1, 1}
end
self.width = 12/16
self.height = 12/16
self.static = false
self.active = true
self.gravity = 0
self.rotation = 0
self.autodelete = true
self.timer = 0
--IMAGE STUFF
self.drawable = true
self.quad = bulletbillquad[spriteset]
self.offsetX = 6
self.offsetY = 2
self.quadcenterX = 8
self.quadcenterY = 8
self.graphic = bulletbillimg
self.category = 11
self.animationdirection = dir
self.mask = { true,
true, false, false, false, true,
true, true, true, true, true,
true, false, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, true, true, true, true}
self.shot = false
playsound("bulletbill")
end
function bulletbill:update(dt)
if self.x < self.startx - 1 or self.x > self.startx + 1 then
self.customscissor = nil
end
if self.shot then
self.speedy = self.speedy + shotgravity*dt
self.x = self.x+self.speedx*dt
self.y = self.y+self.speedy*dt
--check if goomba offscreen
if self.y > 18 then
return true
else
return false
end
else
self.timer = self.timer + dt
if self.timer >= bulletbilllifetime then
return true
end
if self.rotation ~= 0 then
if math.abs(math.abs(self.rotation)-math.pi/2) < 0.1 then
self.rotation = -math.pi/2
else
self.rotation = 0
end
end
if self.speedx < 0 then
self.animationdirection = "left"
elseif self.speedx > 0 then
self.animationdirection = "right"
elseif self.speedy < 0 then
self.animationdirection = "right"
elseif self.speedy > 0 then
self.animationdirection = "left"
end
end
end
function bulletbill:stomp(dir) --fireball, star, turtle
self.shot = true
self.speedy = 0
self.direction = dir or "right"
self.active = false
self.gravity = shotgravity
if self.direction == "left" then
self.speedx = -shotspeedx
else
self.speedx = shotspeedx
end
end
function bulletbill:shotted(dir)
self:stomp(dir)
end
function bulletbill:rightcollide(a, b)
self:globalcollide(a, b)
return false
end
function bulletbill:leftcollide(a, b)
self:globalcollide(a, b)
return false
end
function bulletbill:ceilcollide(a, b)
self:globalcollide(a, b)
if a == "player" or a == "box" then
self:stomp()
end
return false
end
function bulletbill:floorcollide(a, b)
self:globalcollide(a, b)
return false
end
function bulletbill:globalcollide(a, b)
if self.killstuff then
if a == "goomba" or a == "koopa" then
b:shotted("left")
return true
end
else
return true
end
end
function bulletbill:portaled()
self.killstuff = true
end--]]