move hud logic to system
This commit is contained in:
parent
84db41dc51
commit
45bfeb5eb5
5 changed files with 69 additions and 72 deletions
|
|
@ -45,7 +45,8 @@
|
|||
(set self.y y))
|
||||
(if (> self.battery 0)
|
||||
(set self.battery (- self.battery (* dt 2))))))
|
||||
(beholder.trigger "PLAYER.POS" self.x self.y))
|
||||
(beholder.trigger "PLAYER.POS" self.x self.y)
|
||||
(beholder.trigger "PLAYER.BATTERY" self.battery))
|
||||
|
||||
(fn player.load [self]
|
||||
(set self.battery 100)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
(local beholder (require "libs/beholder"))
|
||||
(local player (require "src/entities/player.fnl"))
|
||||
(local walls (require "src/systems/walls.fnl"))
|
||||
(local hud (require "src/systems/hud.fnl"))
|
||||
|
||||
; (local colliders {
|
||||
; :added {}
|
||||
|
|
@ -42,6 +43,7 @@
|
|||
(nata:oop)
|
||||
camera
|
||||
walls
|
||||
(hud {: screen})
|
||||
]
|
||||
})]
|
||||
(pool:queue (player {:bump-world bump-world :level-key :tutorial}))
|
||||
|
|
|
|||
|
|
@ -16,10 +16,11 @@
|
|||
(set self.x (- x (/ screen.canvas-w 2)))
|
||||
(set self.y (- y (/ screen.canvas-h 2)))))))
|
||||
|
||||
(fn camera.draw89 [self]
|
||||
(love.graphics.pop)) ; undo camera translation
|
||||
|
||||
(fn camera.draw99 [self]
|
||||
(let [screen self.pool.data.screen canvas self.pool.data.canvas]
|
||||
(love.graphics.pop) ; undo camera translation
|
||||
(love.graphics.setCanvas) ; reset to root canvas
|
||||
(color:reset-color)
|
||||
(love.graphics.draw canvas 0 0 0 screen.scale screen.scale)))
|
||||
|
|
|
|||
62
two_player_cleaning_game/src/systems/hud.fnl
Normal file
62
two_player_cleaning_game/src/systems/hud.fnl
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
(local beholder (require "libs/beholder"))
|
||||
(local assets (require "src/assets.fnl"))
|
||||
(local color (require "src/colors.fnl"))
|
||||
|
||||
(var screen nil)
|
||||
(local hud {
|
||||
:player-battery 0
|
||||
})
|
||||
|
||||
(fn hud.load [self]
|
||||
(set self.font (love.graphics.newFont 10))
|
||||
(set self.font-small (love.graphics.newFont 6))
|
||||
|
||||
(beholder.observe "PLAYER.BATTERY" (lambda [bat]
|
||||
(set self.player-battery bat))))
|
||||
|
||||
(lambda draw-header [self]
|
||||
(color.set-color :cream)
|
||||
(love.graphics.rectangle "fill" 0 0 screen.canvas-w 20)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.line 0 20 screen.canvas-w 20))
|
||||
|
||||
(lambda draw-side-walls [self]
|
||||
(color.set-color :cream)
|
||||
(love.graphics.rectangle "fill" 0 0 20 screen.canvas-h)
|
||||
(love.graphics.rectangle "fill" (- screen.canvas-w 20) 0 20 screen.canvas-h)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.line 20 0 20 screen.canvas-w)
|
||||
(love.graphics.line (- screen.canvas-w 20) 0 (- screen.canvas-w 20) screen.canvas-w))
|
||||
|
||||
(lambda draw-footer [self]
|
||||
(love.graphics.push)
|
||||
(love.graphics.translate 0 400)
|
||||
(color.set-color :cream)
|
||||
(love.graphics.rectangle "fill" 0 0 screen.canvas-w 100)
|
||||
(color.reset-color)
|
||||
(love.graphics.draw assets.battery-bar-sprite 78 8)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.setFont self.font)
|
||||
(love.graphics.print (.. "Battery: " (string.format "%d" self.player-battery) "%") 6 7)
|
||||
(color.set-color :light-blue)
|
||||
(love.graphics.rectangle "fill" 80 12 (* 152 (/ self.player-battery 100)) 4)
|
||||
(love.graphics.setFont self.font-small)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.print "100%" 229 2)
|
||||
(color.set-color :light-pink)
|
||||
(love.graphics.print "125%" 267 2)
|
||||
(love.graphics.print "125%" 306 2)
|
||||
(love.graphics.print "150%" 345 2)
|
||||
(love.graphics.print "200%" 382 2)
|
||||
(color.set-color :dark-purple)
|
||||
(love.graphics.line 0 0 screen.canvas-w 0)
|
||||
(love.graphics.pop))
|
||||
|
||||
(fn hud.draw90 [self]
|
||||
(draw-side-walls self)
|
||||
(draw-footer self)
|
||||
(draw-header self))
|
||||
|
||||
(lambda [{:screen s}]
|
||||
(set screen s)
|
||||
hud)
|
||||
Loading…
Add table
Add a link
Reference in a new issue