-
Notifications
You must be signed in to change notification settings - Fork 0
/
heads_up_display.lua
112 lines (86 loc) · 3 KB
/
heads_up_display.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
local Component = require("component")
local HeadsUpDisplay = function ()
-- this needs to account for global.scale
local x = 70
local y = 44
local data = {
score = "00000",
items = "00",
item_type = "",
world = "",
timer = ""
}
local drawScore = function (x, y)
love.graphics.print(data["score"], x, y)
end
local drawTimer = function (x, y)
love.graphics.print("" .. data["timer"], x, y)
end
local drawWorld = function (x, y)
love.graphics.print(data["world"], x, y)
end
local drawItems = function (x, y)
image:setFilter("nearest", "nearest")
local sx, sy = global.scale, global.scale
local r, ox, oy = 0, 0, 0
local width = image:getWidth()
local height = image:getHeight()
love.graphics.draw(image, x + 5, y + 4, r, sx, sy, ox, oy)
love.graphics.print("x" .. data["items"], x + 23, y)
end
local setScore = function (score)
data["score"] = score
end
local setWorld = function (world)
data["world"] = world
end
-- TODO time should display leading zeroes
local setTimer = function (time)
data["timer"] = "" .. time
end
-- TODO items should have a coin or a flower
local setItems = function (items)
data["items"] = "" .. items
end
local setItemType = function (item_type)
data["item_type"] = item_type
if data["item_type"] == "coin" then image = "assets/images/coin_icon.png" end
if data["item_type"] == "flower" then image = "assets/images/flower_icon.png" end
image = love.graphics.newImage(image)
end
local component = Component(x, y,
Component(-1, 0, Component(0, 0, Component(0, 0, "MARIO"), Component(0, 24, drawScore))),
Component(194, 0, Component(0, 0, Component(0, 0, ""), Component(-2, 24, drawItems))),
Component(359, 0, Component(0, 0, Component(0, 0, "WORLD"), Component(24, 24, drawWorld))),
Component(527, 0, Component(0, 0, Component(0, 0, "TIME"), Component(25, 24, drawTimer)))
)
local current_component = component
local draw = function ()
component.draw(0, 0)
end
local incrementY = function ()
current_component.offset.y = current_component.offset.y + 1
end
local decrementY = function ()
current_component.offset.y = current_component.offset.y - 1
end
local incrementX = function ()
current_component.offset.x = current_component.offset.x + 1
end
local decrementX = function ()
current_component.offset.x = current_component.offset.x - 1
end
return {
draw = draw,
incrementY = incrementY,
decrementY = decrementY,
incrementX = incrementX,
decrementX = decrementX,
setScore = setScore,
setTimer = setTimer,
setWorld = setWorld,
setItems = setItems,
setItemType = setItemType
}
end
return HeadsUpDisplay