-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.lua
73 lines (59 loc) · 1.61 KB
/
ui.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
require "constant"
function UIImage(img, x, y)
local u = {}
u.img = img
u.x = x
u.y = y
function u:update()
end
function u:draw()
love.graphics.setColor(1, 1, 1)
love.graphics.draw(self.img, self.x, self.y)
end
return u
end
function UIBar(x, y, resource_type, col)
local b = {}
b.x = x
b.y = y
b.type = resource_type
b.col = col
b.value = 0
b.max = 0
function b:update()
self.value = resources[self.type].value
self.max = resources[self.type].max
end
function b:draw()
-- love.graphics.setColor(0.8, 0.8, 0.8)
-- love.graphics.rectangle("fill", self.x, self.y, self.max, 4)
love.graphics.setColor(self.col)
love.graphics.rectangle("fill", self.x, self.y, self.value, 4)
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle("fill", self.x+self.max, self.y, 2, 4)
love.graphics.setColor(1, 1, 1)
end
return b
end
function initUI()
power_bar = UIBar(64, 18, "power", COLORS["power"])
food_bar = UIBar(64, 34, "food", COLORS["food"])
oxygen_bar = UIBar(64, 50, "oxygen", COLORS["oxygen"])
ui_elements = {
UIImage(love.graphics.newImage("images/ui/main/power.png"), 16, 16),
UIImage(love.graphics.newImage("images/ui/main/food.png"), 16, 32),
UIImage(love.graphics.newImage("images/ui/main/oxygen.png"), 16, 48),
power_bar, food_bar, oxygen_bar
}
end
function updateUI()
for i=1, #ui_elements do
ui_elements[i]:update()
end
end
function drawUI()
for i=1, #ui_elements do
ui_elements[i]:draw()
end
builder:drawRoomType()
end