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
|
local heartTypes = require "data.heartTypes"
local Loot = {}
Loot.__index = Loot
function Loot:new(name, x, y)
local obj = {
objectType = "loot",
x = x or nil,
y = y or nil,
type = name,
r = config.lootSize
}
setmetatable(obj, Loot)
G.BodyLifeCycleManager:create(obj, config.lootSize, "static", true)
return obj
end
function Loot:random(x, y)
local type = utils.any(heartTypes)
return Loot:new(type, x, y)
end
function Loot:onContact(other)
local loots = G.currentRoom.objects.loots
if other.objectType == "player" then
local pickedLoot = table.remove(loots, utils.indexof(loots, self))
G.player:gainHeart(pickedLoot.type)
G.BodyLifeCycleManager:destroy(self.physicsBody)
end
end
function Loot:placeInRoom()
G.BodyLifeCycleManager:create(self, config.lootSize, "static", true)
end
function Loot:update(dt)
-- nothing yet
end
return Loot
|