-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhud.lua
54 lines (42 loc) · 1.46 KB
/
hud.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
local HUD = {}
HUD.__index = HUD
local img_healthbar_base = love.graphics.newImage('assets/ui/healthbar-base.png')
local img_healthbar_tic = love.graphics.newImage('assets/ui/healthbar-tic.png')
local img_healthbar_tags = { }
local healthbar_w = img_healthbar_base:getWidth()
local healthbar_h = img_healthbar_base:getHeight()
function HUD.new(...) -- takes a list of up to 4 player objects
local self = setmetatable({}, HUD)
local xo, yo = 8, 8
self._coords = {
{view:lefttop(xo, yo, healthbar_w, healthbar_h)},
{view:righttop(xo, yo, healthbar_w, healthbar_h)},
{view:leftbottom(xo, yo, healthbar_w, healthbar_h)},
{view:rightbottom(xo, yo, healthbar_w, healthbar_h)}
}
self._players = {}
for i = 1,4 do self._players[i] = select(i, ...) end
for i, v in ipairs(self._players) do
local name = v.get('name')
img_healthbar_tags[i] = love.graphics.newImage('assets/ui/healthbar-p_'..name..'.png')
end
return self
end
function HUD:update(dt)
--No-op
end
function HUD:draw()
local max = math.max
for i, player in ipairs(self._players) do
local hp = player.get("hp")
local x, y = unpack(self._coords[i])
love.graphics.draw(img_healthbar_base, x, y)
love.graphics.draw(img_healthbar_tags[i], x, y)
while hp > 0 do
love.graphics.draw(img_healthbar_tic, x, y, 0, 1, 1, 0, (2 * hp - 2))
hp = hp -1
end
end
end
--
return HUD