-
Notifications
You must be signed in to change notification settings - Fork 0
/
bullet-impact.lua
59 lines (49 loc) · 1.35 KB
/
bullet-impact.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
BulletImpact = class("BulletImpact")
---
-- BulletImpact:initialize
-- The bullet impact effect.
--
-- @param x X position
-- @param y Y position
--
function BulletImpact:initialize(x, y)
self.x = x
self.y = y
self.life = 0
self.particleid = game.addParticle(self)
self.speed = math.random(40, 70)
self.particles = math.random(5, 12)
end
---
-- BulletImpact:update
-- Updates the bullet impact effect.
--
-- @param dt Time passed since last frame
--
function BulletImpact:update(dt)
self.life = self.life + dt
if self.life > 0.2 then
self:destroy()
end
end
---
-- BulletImpact:draw
-- Draws the bullet impact effect.
--
function BulletImpact:draw()
love.graphics.setColor(255, 250, 240, 200)
local dist1, dist2 = self.life * self.speed * 0.6, self.life * self.speed * 1.4
for i = 1, self.particles do -- bonus randomness!
local theta = i / self.particles * math.pi*2 + self.speed
love.graphics.line(self.x + math.cos(theta) * dist1, self.y + math.sin(theta) * dist1,
self.x + math.cos(theta) * dist2, self.y + math.sin(theta) * dist2)
end
end
---
-- BulletImpact:destroy
-- Destroys the effect.
--
function BulletImpact:destroy()
game.particles[self.particleid] = nil
self = nil
end