X Tutup
Skip to content

Commit a63ce00

Browse files
committed
more hud
1 parent 85b0d20 commit a63ce00

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

main.moon

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require "guns"
88
require "tank"
99
require "enemies"
1010
require "pickup"
11+
require "ui"
1112

1213
require "lovekit.screen_snap"
1314

@@ -24,6 +25,23 @@ export sprite, dispatch, sfx
2425
local snapper
2526
local Game
2627

28+
box_text = (msg, x, y, center=true) ->
29+
msg = msg\lower!
30+
31+
w, h = fonts.main\getWidth(msg), fonts.main\getHeight!
32+
g.push!
33+
34+
if center
35+
g.translate x - w/2, y - h/2
36+
else
37+
g.translate x, y - h/2
38+
39+
g.setColor 255,255,255
40+
g.rectangle "fill", 0,0,w,h
41+
g.setColor 0,0,0
42+
g.print msg, 0,0
43+
g.pop!
44+
2745
class World
2846
disable_project: false
2947
energy_count: 0
@@ -62,6 +80,8 @@ class World
6280
}, 0.05
6381
@flare = (...) => sprite\draw "48,32,32,32", ...
6482

83+
@level_progress = HorizBar 80, 10
84+
6585
draw_background: =>
6686
g.push!
6787
g.scale @viewport.screen.scale
@@ -121,6 +141,19 @@ class World
121141
g.setColor 255,255,255,255
122142
g.pop!
123143

144+
g.push!
145+
g.scale @viewport.screen.scale
146+
147+
w = w/3
148+
h = h/3
149+
150+
box_text "Energy: #{@player.energy_count or 0}", 10, 10, false
151+
box_text "Score: #{@player.score or 0}", 10, 20, false
152+
153+
@level_progress\draw w - 10 - @level_progress.w, 7
154+
g.pop!
155+
156+
124157
draw: =>
125158
@viewport\center_on_pt @player.x, @player.y, @map_box
126159

@@ -129,19 +162,23 @@ class World
129162
if @disable_project
130163
@draw_ground!
131164
@draw_entities!
132-
-- @draw_hud!
165+
@draw_hud!
133166
else
167+
@colors.factor = 50
134168
@colors\render ->
135169
@ground_project\render -> @draw_ground!
136170
@entity_project\render -> @draw_entities!
137171

138-
@draw_hud!
172+
@colors.factor = 200
173+
@colors\render ->
174+
@draw_hud!
175+
139176

140177
g.setColor 255,255,255
141178

142179
g.scale 2
143-
p tostring(timer.getFPS!), 2, 2
144-
p "Energy: #{@energy_count}", 2, 12
180+
-- p tostring(timer.getFPS!), 2, 2
181+
-- p "Energy: #{@energy_count}", 2, 12
145182

146183
update: (dt) =>
147184
@viewport\update dt

ui.moon

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
{graphics: g} = love
4+
5+
export *
6+
7+
class HorizBar
8+
color: { 255, 128, 128, 128 }
9+
border: true
10+
padding: 1
11+
12+
new: (@w, @h, @value=0.5)=>
13+
14+
draw: (x, y) =>
15+
g.push!
16+
g.setColor 255,255,255
17+
18+
if @border
19+
g.setLineWidth 0.6
20+
g.rectangle "line", x, y, @w, @h
21+
22+
g.setColor @color
23+
w = @value * (@w - @padding*2)
24+
25+
g.rectangle "fill", x + @padding, y + @padding, w, @h - @padding*2
26+
else
27+
g.setColor @color
28+
w = @value * @w
29+
g.rectangle "fill", x, y, w, @h
30+
31+
g.pop!
32+
g.setColor 255,255,255,255

0 commit comments

Comments
 (0)
X Tutup