-
Notifications
You must be signed in to change notification settings - Fork 0
/
crate.lua
64 lines (49 loc) · 1.65 KB
/
crate.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
math = require "math"
utils = require "utils"
flammable_module = require "flammable"
sprite = require "sprite"
local flammable = flammable_module.flammable
module(..., package.seeall)
--a list of all crates
crates = {}
crates.size = 0
--animations for crate
crate_burning_sheet = sprite.newSpriteSheet("crate_burning.png", 150, 150)
crate_burning_set = sprite.newSpriteSet(crate_burning_sheet, 1, 8)
--the crate class
crate = {}
setmetatable(crate, {__index = flammable})
function crate:new(x, y)
local crateImage = sprite.newSprite(crate_burning_set)--display.newRect(x, y, 50, 50)
crateImage.x = x
crateImage.y = y
local instance = flammable:new(crateImage, {density=5})
mainDisplay.mainDisplay:insert(crateImage)
instance.flash_point = instance.flash_point - 3
instance.heat_increase_rate = instance.heat_increase_rate + 4
instance.health = 200
setmetatable(instance, {__index = crate})
local frame_count = 8
instance.frames_per_health_lost = (frame_count - 1) / instance.health
return instance
end
function crate:animate()
if self.current_heat >= self.flash_point then
self.body.currentFrame = 1 + math.ceil((200-self.health) * self.frames_per_health_lost)
end
end
function crate:on_enter_frame(elapsed_time)
flammable.on_enter_frame(self, elapsed_time)
if self.health > 0 then
self:animate()
end
end
function crate:burn_up()
table.remove(crates, utils.index_of(crates, self))
crates.size = crates.size -1
flammable.burn_up(self)
end
function spawn_crate(x, y)
crates[crates.size + 1] = crate:new(x, y)
crates.size = crates.size + 1
end