-
Notifications
You must be signed in to change notification settings - Fork 10
/
explosion.lua
50 lines (35 loc) · 1.2 KB
/
explosion.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
explosion = class('explosion')
function explosion:initialize(world,x,y)
self.stage = 1
self.x = x
self.y = y
self.body = love.physics.newBody(world,self.x,self.y,'dynamic')
self.shape = love.physics.newPolygonShape(self:plotExplosion(self.stage))
self.fixture = love.physics.newFixture(self.body, self.shape, 1.0)
end
function explosion:update()
if self.stage == 75 then
self.body:destroy()
return false
elseif self.stage < 75 then
self.stage = self.stage + 1
self.shape = love.physics.newPolygonShape(self:plotExplosion(self.stage))
return true
end
end
function explosion:draw()
love.graphics.setColor(math.random(0,255),math.random(0,255),math.random(0,255))
love.graphics.polygon('fill', self.shape:getPoints())
end
function explosion:plotExplosion(stage)
x = 0
y = 0
if stage < 15 then
padding = stage * 2
elseif stage > 15 and stage < 50 then
padding = 45
elseif stage >= 50 then
padding = 80 - stage
end
return self.x,self.y - padding, self.x + padding, self.y, self.x, self.y + padding, self.x - padding, self.y
end