move camera into a system module
This commit is contained in:
parent
f69f08f656
commit
77dccc9e6f
2 changed files with 45 additions and 38 deletions
36
two_player_cleaning_game/src/systems/camera.fnl
Normal file
36
two_player_cleaning_game/src/systems/camera.fnl
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
(local beholder (require "libs/beholder"))
|
||||
(local color (require "src/colors.fnl"))
|
||||
|
||||
;; Camera System
|
||||
|
||||
(local camera {:x 0 :y 0})
|
||||
|
||||
(fn camera.draw2 [self]
|
||||
(love.graphics.push)
|
||||
(love.graphics.translate (* -1 self.x) (* -1 self.y)))
|
||||
|
||||
(fn camera.load [self]
|
||||
(let [screen self.pool.data.screen]
|
||||
(beholder.observe "PLAYER.POS" (lambda [x y]
|
||||
;; Update camera to follow player (keep player centered on screen)
|
||||
(set self.x (- x (/ screen.canvas-w 2)))
|
||||
(set self.y (- y (/ screen.canvas-h 2)))))))
|
||||
|
||||
|
||||
(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)))
|
||||
|
||||
(fn camera.draw1 [self]
|
||||
(let [screen self.pool.data.screen canvas self.pool.data.canvas]
|
||||
; use canvas
|
||||
(love.graphics.setCanvas canvas)
|
||||
; clear the screen
|
||||
(love.graphics.clear)
|
||||
(color.set-color :cream)
|
||||
(love.graphics.rectangle "fill" 0 0 screen.canvas-w screen.canvas-h)))
|
||||
|
||||
camera
|
||||
Loading…
Add table
Add a link
Reference in a new issue