File: particles.lua

package info (click to toggle)
mrrescue 1.02e-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,228 kB
  • sloc: makefile: 9; sh: 1
file content (241 lines) | stat: -rw-r--r-- 4,822 bytes parent folder | download | duplicates (2)
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
Shards = {}
Shards.__index = Shards

local GRAVITY = 350

function Shards.create(x,y,dir)
	local self = setmetatable({}, Shards)

	self.alive = true

	self.shards = {}
	for i = 0,7 do
		self.shards[i] = {}
		self.shards[i].x = x
		self.shards[i].y = y+i*3+4
		self.shards[i].xspeed = dir*math.random(100,200)
		self.shards[i].yspeed = math.random(-50,50)
		self.shards[i].rot = 0
	end

	return self
end

function Shards:update(dt)
	local allOut = true

	for i,v in ipairs(self.shards) do
		v.x = v.x + v.xspeed*dt
		v.yspeed = v.yspeed + GRAVITY*dt
		v.y = v.y + v.yspeed*dt
		v.rot = v.rot + v.xspeed*dt*0.2

		if v.y < MAPH+4 then
			allOut = false
		end
	end

	self.alive = not allOut
end

function Shards:draw()
	for i,v in ipairs(self.shards) do
		love.graphics.draw(img.shards, quad.shard[i], v.x, v.y, v.rot, 1,1, 4,4)
	end
end

BlackSmoke = {}
BlackSmoke.__index = BlackSmoke

function BlackSmoke.create(x,y)
	local self = setmetatable({}, BlackSmoke)
	self.x = math.floor(x)
	self.y = math.floor(y)
	self.alive = true
	self.anim = newAnimation(img.black_smoke, 20, 20, 0.10, 6, function() self.alive = false end)
	return self
end

function BlackSmoke:update(dt)
	self.anim:update(dt)
end

function BlackSmoke:draw()
	if self.alive == true then
		self.anim:draw(self.x, self.y, 0, 1,1, 10, 10)
	end
end

SmallBlackSmoke = {}
SmallBlackSmoke.__index = SmallBlackSmoke

function SmallBlackSmoke.create(x,y)
	local self = setmetatable({}, SmallBlackSmoke)
	self.x = math.floor(x)
	self.y = math.floor(y)
	self.alive = true
	self.anim = newAnimation(img.black_smoke_small, 8, 8, 0.12, 4, function() self.alive = false end)
	return self
end

function SmallBlackSmoke:update(dt)
	self.anim:update(dt)
end

function SmallBlackSmoke:draw()
	if self.alive == true then
		self.anim:draw(self.x, self.y, 0, 1,1, 4, 4)
	end
end

Ashes = { isAshes = true }
Ashes.__index = Ashes

function Ashes.create(x,y)
	local self = setmetatable({}, Ashes)

	self.alive = true
	self.x = math.floor(x)
	self.y = math.floor(y)
	self.anim = newAnimation(img.ashes, 20, 20, 0.17, 8, function() self.alive = false end)
	return self
end

function Ashes:update(dt)
	self.anim:update(dt)
end

function Ashes:draw()
	if self.alive == true then
		self.anim:draw(self.x, self.y, 0, 1,1, 10, 20)
	end
end

Sparkles = {}
Sparkles.__index = Sparkles

function Sparkles.create(x,y,count,time)
	local self = setmetatable({}, Sparkles)
	self.alive = true
	self.particles = {}
	self.time = time or 2
	if count == nil then count = 8 end

	for i=1,count do
		table.insert(self.particles, {x=x, y=y, xspeed=math.random(-100,100), yspeed=math.random(-200,-50), size=i%3})
	end

	return self
end

function Sparkles:update(dt)
	self.time = self.time - dt
	if self.time < 0 then
		self.alive = false
		return
	end

	for i,v in ipairs(self.particles) do
		v.yspeed = v.yspeed + 500*dt
		v.x = v.x + v.xspeed*dt
		v.y = v.y + v.yspeed*dt
	end
end

function Sparkles:draw()
	for i,v in ipairs(self.particles) do
		love.graphics.draw(img.sparkles, quad.sparkles[v.size], v.x, v.y, 0,1,1, 3.5, 3.5)
	end
end

SaveBeam = {}
SaveBeam.__index = SaveBeam

function SaveBeam.create(x,y,dir)
	local self = setmetatable({}, SaveBeam)
	self.alive = true
	self.time = 0
	self.x, self.y = x, math.floor(y)
	self.dir = dir

	return self
end

function SaveBeam:update(dt)
	self.time = self.time + dt*18
	if self.time >= 8 then
		self.time = 7
		self.alive = false
	end
end

function SaveBeam:draw()
	local frame = math.floor(self.time)
	lg.draw(img.savebeam, quad.savebeam[frame], self.x, self.y, 0, self.dir, 1, 1, 16)
end

PopupText = {}
PopupText.__index = PopupText

function PopupText.create(text)
	local self = setmetatable({}, PopupText)
	self.alive = true
	self.time = 0
	self.x = player.flx
	self.y = player.fly-24

	if text == "rescue" then
		self.id = 0
	elseif text == "coolant" then
		self.id = 1
	elseif text == "suit" then
		self.id = 2
	elseif text == "tank" then
		self.id = 3
	elseif text == "reserve" then
		self.id = 4
	elseif text == "regen" then
		self.id = 5
	elseif text == "theft" then
		self.id = 6
	elseif text == "3combo" then
		self.id = 7
	elseif text == "4combo" then
		self.id = 8
	elseif text == "5combo" then
		self.id = 9
	elseif text == "megacombo" then
		self.id = 10
	end

	return self
end

function PopupText:update(dt)
	self.time = self.time + dt
	if self.time > 0.7 then
		self.alive = false
	end
end

function PopupText:draw()
	lg.draw(img.popup_text, quad.popup_text[self.id], self.x, self.y-math.sqrt(self.time)*32, 0, 1, 1, 32, 0)
end

CoalBallBreak = {}
CoalBallBreak.__index = CoalBallBreak

function CoalBallBreak.create(x,y)
	local self = setmetatable({}, CoalBallBreak)
	self.alive = true
	self.x, self.y = math.floor(x), math.floor(y)
	return self
end

function CoalBallBreak:update(dt)
	
end

function CoalBallBreak:draw()
	
end