summaryrefslogtreecommitdiff
path: root/objects/Loot.lua
blob: 1e392110226e25bddeca8c7ee5fa2515b4aa380a (plain)
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
local physics = require "logic.physics"

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: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