-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventoryHandler.lua
50 lines (41 loc) · 1.05 KB
/
inventoryHandler.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
local gui = require "lib.Gspot"
function setupInventory()
inventory = {}
hunger = 0
bmi = 20
end
function inventoryAdd(item)
inventory[#inventory+1] = item
inventoryDraw()
end
function inventoryRemove(idx)
love.audio.play(love.audio.newSource("assets/sounds/eatingnoise.wav", "stream"))
hunger = math.max(hunger - 1, 0)
if inventory[idx] == "Maple syrup" then
bmi = bmi + 1
if bmi >= 26.5 then
gamePhase = "gameover"
end
end
local n = #inventory
inventory[idx] = nil
for i=idx,n-1 do
inventory[i] = inventory[i+1]
end
inventory[n] = nil
inventoryDraw()
end
function inventoryDraw()
gui:clear()
love.graphics.setFont(font10)
for i, item in pairs(inventory) do
local icon = love.graphics.newImage("assets/ui/food/"..item:gsub('%W', ''):lower()..".png")
local button = gui:imgbutton(nil, {x = icon:getWidth() * i + (i*5) - icon:getWidth(), y = 5, w = icon:getWidth(), h = icon:getHeight()}, nil, icon)
button.click = function(this, x, y)
inventoryRemove(i)
end
button.tip = item
end
love.graphics.setFont(font14)
gui:draw()
end