-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplosion.lua
78 lines (63 loc) · 2.16 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
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
-- Copyright (C) 2023 Alessandro Amatucci Girlanda
-- This file is part of Invaders in Space.
-- Invaders in Space is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
-- Invaders in Space is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with Invaders in Space. If not, see <https://www.gnu.org/licenses/>.
Explosion = Entity:extend()
function Explosion:new(image, x, y)
Explosion.super.new(self, image, x, y)
self.width = PLAYER_WIDTH
self.height = PLAYER_HEIGHT
self:setQuads()
self.current_texture = 1
self.texture = self.quads[1]
self.texture_change = 0.1
self.texture_timer = 0
self.exploded = false
end
function Explosion:update(dt)
self:textureUpdate(dt)
end
function Explosion:tutorialUpdate(dt)
if self.exploded then
self.current_texture = 1
self.exploded = false
else
self:textureUpdate(dt)
end
end
function Explosion:draw()
love.graphics.draw(self.image, self.texture, self.x, self.y)
end
function Explosion:textureChange()
self.texture = self.quads[self.current_texture]
end
function Explosion:textureUpdate(dt)
if (self.texture_timer >= self.texture_change) then
-- Change current texture/frame with the following one
self.current_texture = self.current_texture + 1
if (self.current_texture > #self.quads) then
self.exploded = true
else
self:textureChange()
end
-- Update timer
self.texture_timer = self.texture_timer - self.texture_change
else
-- Increase timer
self.texture_timer = self.texture_timer + dt
end
end
function Explosion:done()
if (self.exploded) then
return true
end
return false
end