-
Notifications
You must be signed in to change notification settings - Fork 0
/
HUD.lua
73 lines (62 loc) · 2.07 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function Bar(width, height, color, max)
return {
draw = function(self, x, y, val)
local frac = math.min(max, val or 0) / max
local fillwidth = frac * width
love.graphics.setColor(color[1], color[2], color[3])
love.graphics.rectangle("fill", x, y, fillwidth, height)
love.graphics.setColor(1, 1, 1)
love.graphics.rectangle("line", x, y, width, height)
end,
update = function(self, dt)
end,
}
end
function HUD()
ammoBar = Bar(200, 32, {1, 0, 0}, 100)
healthBar = Bar(200, 32, {0, 1, 0}, 10)
return {
x = 0,
y = 0,
width = love.graphics.getWidth(),
height = 40,
font = fonts.large,
update = function(self, dt)
end,
draw = function(self)
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
if player.ammo <= 10 then
love.graphics.setColor(1, 0, 0)
else
love.graphics.setColor(1, 1, 1)
end
love.graphics.printf("б/к:", self.font, self.x, self.y, 100, "right")
ammoBar:draw(self.x + 100, self.y + 4, player.ammo)
if player.health < 2 then
love.graphics.setColor(1, 0, 0)
else
love.graphics.setColor(1, 1, 1)
end
love.graphics.printf("живучесть:", self.font, self.x + 300, self.y, 200, "right")
healthBar:draw(self.x + 500, self.y + 4, player.health)
love.graphics.printf(
"сбито: " .. _G.kills,
self.font,
love.graphics.getWidth() - 400,
self.y,
200,
"left"
)
love.graphics.printf(
"потери: " .. _G.losses,
self.font,
love.graphics.getWidth() - 200,
self.y,
200,
"left"
)
end,
}
end
return HUD