Permalink
Browse files

more hud

  • Loading branch information...
1 parent 85b0d20 commit a63ce004c646f5ce951aea4fe5b296d1cb006dab @leafo committed Dec 16, 2012
Showing with 73 additions and 4 deletions.
  1. +41 −4 main.moon
  2. +32 −0 ui.moon
View
@@ -8,6 +8,7 @@ require "guns"
require "tank"
require "enemies"
require "pickup"
+require "ui"
require "lovekit.screen_snap"
@@ -24,6 +25,23 @@ export sprite, dispatch, sfx
local snapper
local Game
+box_text = (msg, x, y, center=true) ->
+ msg = msg\lower!
+
+ w, h = fonts.main\getWidth(msg), fonts.main\getHeight!
+ g.push!
+
+ if center
+ g.translate x - w/2, y - h/2
+ else
+ g.translate x, y - h/2
+
+ g.setColor 255,255,255
+ g.rectangle "fill", 0,0,w,h
+ g.setColor 0,0,0
+ g.print msg, 0,0
+ g.pop!
+
class World
disable_project: false
energy_count: 0
@@ -62,6 +80,8 @@ class World
}, 0.05
@flare = (...) => sprite\draw "48,32,32,32", ...
+ @level_progress = HorizBar 80, 10
+
draw_background: =>
g.push!
g.scale @viewport.screen.scale
@@ -121,6 +141,19 @@ class World
g.setColor 255,255,255,255
g.pop!
+ g.push!
+ g.scale @viewport.screen.scale
+
+ w = w/3
+ h = h/3
+
+ box_text "Energy: #{@player.energy_count or 0}", 10, 10, false
+ box_text "Score: #{@player.score or 0}", 10, 20, false
+
+ @level_progress\draw w - 10 - @level_progress.w, 7
+ g.pop!
+
+
draw: =>
@viewport\center_on_pt @player.x, @player.y, @map_box
@@ -129,19 +162,23 @@ class World
if @disable_project
@draw_ground!
@draw_entities!
- -- @draw_hud!
+ @draw_hud!
else
+ @colors.factor = 50
@colors\render ->
@ground_project\render -> @draw_ground!
@entity_project\render -> @draw_entities!
- @draw_hud!
+ @colors.factor = 200
+ @colors\render ->
+ @draw_hud!
+
g.setColor 255,255,255
g.scale 2
- p tostring(timer.getFPS!), 2, 2
- p "Energy: #{@energy_count}", 2, 12
+ -- p tostring(timer.getFPS!), 2, 2
+ -- p "Energy: #{@energy_count}", 2, 12
update: (dt) =>
@viewport\update dt
View
@@ -0,0 +1,32 @@
+
+
+{graphics: g} = love
+
+export *
+
+class HorizBar
+ color: { 255, 128, 128, 128 }
+ border: true
+ padding: 1
+
+ new: (@w, @h, @value=0.5)=>
+
+ draw: (x, y) =>
+ g.push!
+ g.setColor 255,255,255
+
+ if @border
+ g.setLineWidth 0.6
+ g.rectangle "line", x, y, @w, @h
+
+ g.setColor @color
+ w = @value * (@w - @padding*2)
+
+ g.rectangle "fill", x + @padding, y + @padding, w, @h - @padding*2
+ else
+ g.setColor @color
+ w = @value * @w
+ g.rectangle "fill", x, y, w, @h
+
+ g.pop!
+ g.setColor 255,255,255,255

0 comments on commit a63ce00

Please sign in to comment.