scale up window and add battery indicator to hud
This commit is contained in:
parent
e0d19d5d61
commit
50c3e41f0c
3 changed files with 93 additions and 33 deletions
|
|
@ -2,20 +2,50 @@
|
|||
(local levels (. (require "levels.fnl") :levels))
|
||||
(local bump (require "bump"))
|
||||
|
||||
;; colors
|
||||
(lambda color [full-r full-g full-b]
|
||||
(let [(r g b) (love.math.colorFromBytes full-r full-g full-b)]
|
||||
[r g b]
|
||||
))
|
||||
(local color-pallet {
|
||||
:cream (color 255 238 204)
|
||||
:dark-purple (color 70 66 94)
|
||||
:dark-pink (color 255 105 115)
|
||||
:dark-blue (color 21 120 140)
|
||||
:light-blue (color 0 185 190)
|
||||
:light-pink (color 255 176 163)
|
||||
:black [0 0 0]
|
||||
:black-half-tone [0 0 0 0.25]
|
||||
})
|
||||
|
||||
(fn reset-color []
|
||||
"reset color to white (no tinting)"
|
||||
(love.graphics.setColor 1 1 1))
|
||||
|
||||
(lambda set-color [color]
|
||||
"set color to the given color from the color pallet"
|
||||
(love.graphics.setColor (unpack (. color-pallet color))))
|
||||
|
||||
;; global vars
|
||||
(var player-art nil) ; 25x50 pixels each player is 25x25
|
||||
(var dust-sprite nil) ; 35x35 pixels
|
||||
(var ui-bg nil)
|
||||
(var walls-sprite nil)
|
||||
(var walls-batch nil)
|
||||
(var wall-quads nil)
|
||||
(local screen
|
||||
(let [scale 2 canvas-w 800 canvas-h 450]
|
||||
{ :screen-w (* canvas-w scale)
|
||||
:screen-h (* canvas-h scale)
|
||||
:canvas-w canvas-w
|
||||
:canvas-h canvas-h
|
||||
:scale scale
|
||||
:canvas nil}))
|
||||
(local camera {:x 0 :y 0})
|
||||
(local debug true)
|
||||
(local debug false)
|
||||
(local collider-debug-boxes [])
|
||||
(local bump-world (bump.newWorld 25))
|
||||
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 })
|
||||
;; Screen Size
|
||||
(local screen-width 800)
|
||||
(local screen-height 600)
|
||||
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 })
|
||||
; 16:9 (Modern Widescreen - Recommended)**
|
||||
; - **640x360** ← Best middle ground
|
||||
; - 800x450
|
||||
|
|
@ -28,18 +58,20 @@
|
|||
; - 1024x768
|
||||
|
||||
(fn love.load []
|
||||
(love.window.setMode screen-width screen-height)
|
||||
(love.window.setMode screen.screen-w screen.screen-h)
|
||||
(tset screen :canvas (love.graphics.newCanvas screen.canvas-w screen.canvas-h))
|
||||
(bump-world:add player player.x player.y player.w player.h)
|
||||
|
||||
;; load world images
|
||||
(set walls-sprite (love.graphics.newImage "assets/walls.png"))
|
||||
(set walls-batch (love.graphics.newSpriteBatch walls-sprite 2500))
|
||||
(set ui-bg (love.graphics.newImage "assets/ui.png"))
|
||||
|
||||
;; load wall quads
|
||||
(set wall-quads [])
|
||||
(let [(h w) (: walls-sprite :getDimensions)]
|
||||
(let [(w h) (: walls-sprite :getDimensions)]
|
||||
(for [i 0 19 1]
|
||||
(table.insert wall-quads (love.graphics.newQuad (* i 25) 0 25 25 h w))))
|
||||
(table.insert wall-quads (love.graphics.newQuad (* i 25) 0 25 25 w h))))
|
||||
;; load tiles
|
||||
(each [_ row (pairs (. levels :level01 :tiles))]
|
||||
(each [_ tile (pairs row)]
|
||||
|
|
@ -75,19 +107,15 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
|||
(print (if ok (fennel.view val) val))))
|
||||
|
||||
;; drawing
|
||||
(lambda color [full-r full-g full-b]
|
||||
(let [(r g b) (love.math.colorFromBytes full-r full-g full-b)]
|
||||
[r g b]
|
||||
))
|
||||
|
||||
(local off-white (color 237 230 200))
|
||||
(local black [0 0 0])
|
||||
(local black-half-tone [0 0 0 0.25])
|
||||
|
||||
(fn draw-world []
|
||||
(love.graphics.setColor 1 1 1) ; reset color to white (no tinting)
|
||||
(reset-color)
|
||||
(love.graphics.draw walls-batch)
|
||||
)
|
||||
;; draw collider debug boxes
|
||||
(when debug
|
||||
(set-color :black)
|
||||
(each [_ collider (pairs collider-debug-boxes)]
|
||||
(love.graphics.rectangle "line" collider.x collider.y collider.width collider.height))))
|
||||
|
||||
(fn love.update [dt]
|
||||
(let [deltas { :dx 0 :dy 0}]
|
||||
|
|
@ -106,32 +134,64 @@ while 1 do love.event.push('stdin', io.read('*line')) end") :start))
|
|||
(tset player :y y))))
|
||||
|
||||
;; Update camera to follow player (keep player centered on screen)
|
||||
(tset camera :x (- player.x (/ screen-width 2)))
|
||||
(tset camera :y (- player.y (/ screen-height 2)))
|
||||
(tset camera :x (- player.x (/ screen.canvas-w 2)))
|
||||
(tset camera :y (- player.y (/ screen.canvas-h 2)))
|
||||
)
|
||||
|
||||
(fn draw-ui []
|
||||
(love.graphics.push)
|
||||
(love.graphics.translate 0 400)
|
||||
(let [font (love.graphics.newFont 10) font-small (love.graphics.newFont 6)]
|
||||
(set-color :cream)
|
||||
(love.graphics.rectangle "fill" 0 0 screen.canvas-w 100)
|
||||
(reset-color)
|
||||
(love.graphics.draw ui-bg 0 0)
|
||||
(set-color :dark-purple)
|
||||
(love.graphics.setFont font)
|
||||
(love.graphics.print "Battery:" 20 6)
|
||||
(set-color :light-blue)
|
||||
(love.graphics.rectangle "fill" 72 12 (* 152 (/ player.battery 100)) 4)
|
||||
(love.graphics.setFont font-small)
|
||||
(set-color :dark-purple)
|
||||
(love.graphics.print "100%" 229 2)
|
||||
(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)
|
||||
(set-color :dark-purple)
|
||||
(love.graphics.line 0 0 screen.canvas-w 0)
|
||||
)
|
||||
(love.graphics.pop)
|
||||
)
|
||||
|
||||
(fn love.draw []
|
||||
(love.graphics.clear)
|
||||
(love.graphics.translate (* -1 camera.x) (* -1 camera.y))
|
||||
(draw-world)
|
||||
;; draw player
|
||||
(fn draw-player []
|
||||
"draw player sprite and hitbox"
|
||||
(reset-color)
|
||||
(love.graphics.draw
|
||||
(. player-art :player-sprite)
|
||||
(. player-art :player1-quad)
|
||||
player.x player.y)
|
||||
;; draw player hitbox
|
||||
(when debug
|
||||
(love.graphics.setColor (unpack black)) ; reset color to white (no tinting)
|
||||
(love.graphics.rectangle "line" player.x player.y player.w player.h))
|
||||
(set-color :black)
|
||||
(love.graphics.rectangle "line" player.x player.y player.w player.h)))
|
||||
|
||||
|
||||
;; draw collider debug boxes
|
||||
(when debug
|
||||
(love.graphics.setColor (unpack black)) ; reset color to white (no tinting)
|
||||
(each [_ collider (pairs collider-debug-boxes)]
|
||||
(love.graphics.rectangle "line" collider.x collider.y collider.width collider.height)))
|
||||
)
|
||||
(fn love.draw []
|
||||
(love.graphics.setCanvas screen.canvas)
|
||||
(love.graphics.clear)
|
||||
(set-color :cream)
|
||||
(love.graphics.rectangle "fill" 0 0 screen.canvas-w screen.canvas-h)
|
||||
(love.graphics.push) ; stores the default coordinate system
|
||||
(love.graphics.translate (* -1 camera.x) (* -1 camera.y))
|
||||
(draw-world)
|
||||
(draw-player)
|
||||
(love.graphics.pop)
|
||||
(draw-ui)
|
||||
(love.graphics.setCanvas)
|
||||
(reset-color)
|
||||
(love.graphics.draw screen.canvas 0 0 0 screen.scale screen.scale))
|
||||
; (love.graphics.print "Hello from Fennel!\nPress any key to quit" 10 10))
|
||||
|
||||
(fn love.keypressed [key] nil )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue