-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.lua
More file actions
53 lines (43 loc) · 1.15 KB
/
items.lua
File metadata and controls
53 lines (43 loc) · 1.15 KB
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
local player = require("player")
local ui = require("ui")
local items = {}
items.transparency = 0
items.medipacks = {}
function items.SpawnMedipack(x, y)
local mp = {}
mp.x = x
mp.y = y
mp.png = love.graphics.newImage("images/medipack.png")
mp.isCollected = false
table.insert(items.medipacks, mp)
end
function items.Update(dt)
for i = 1, #items.medipacks do
if player.Distance(player, items.medipacks[i]) <= 50 then
if ui.lifeManager.currentLife == ui.maxLife then
break
else
items.medipacks[i].isCollected = true
ui.lifeManager.currentLife = ui.lifeManager.currentLife + 1
end
end
end
if items.transparency <= 1 then
items.transparency = items.transparency + dt
elseif items.transparency > 1 then
items.transparency = 0
end
for i = #items.medipacks, 1, -1 do
if items.medipacks[i].isCollected == true then
table.remove(items.medipacks, i)
end
end
end
function items.Draw()
for i = 1, #items.medipacks do
love.graphics.setColor(1, 1, 1, items.transparency)
love.graphics.draw(items.medipacks[i].png, items.medipacks[i].x, items.medipacks[i].y)
end
love.graphics.setColor(1, 1, 1, 1)
end
return items