diff --git a/game/src/levels/dev.fnl b/game/src/levels/dev.fnl index 10ce7b4..3f8c095 100644 --- a/game/src/levels/dev.fnl +++ b/game/src/levels/dev.fnl @@ -8,6 +8,7 @@ (local walls (require "src/systems/walls.fnl")) (local hud (require "src/systems/hud.fnl")) (local levels (require "levels.fnl")) +(local fog-of-war (require "src/systems/fog_of_war.fnl")) (local info-pad (require "src/entities/info-pad.fnl")) ; TODO: refactor the args away. create a load method and get them from self.pool @@ -24,39 +25,6 @@ (when (= group-name :hitbox) (self.pool.data.bump-world:add entity (unpack entity.hitbox)))) -(lambda fog-on-war [] - (local system { - :cells [] - }) - (lambda system.load [self] - (let [tiles (. levels :levels self.pool.data.level-key :tiles) - rows-of-tiles (length tiles) - cols-of-tiles (length (. tiles 1)) - rows (+ 200 rows-of-tiles) ; 100 rows of padding above the tiles - cols (+ 200 cols-of-tiles) ; 100 cols of padding on the sides - x (- 0 (* 25 100)) ; offset 100 tiles left - y (- 0 (* 25 100)) ; offset 100 tiles up - ] - (for [row 0 rows] - (for [col 0 cols] - (table.insert self.cells {:x (+ x (* col 25)) :y (+ y (* row 25))}))) - - (each [_ cell (pairs self.cells)] - (set cell.hit false) - (lambda cell.on-hit [cell-self] - (set cell-self.hit true)) - (self.pool.data.bump-world:add cell cell.x cell.y 25 25)))) - - (lambda system.draw80 [self] - (color.set-color :dark-purple) - (each [_ cell (pairs self.cells)] - (when (= cell.hit false) - (love.graphics.rectangle :fill cell.x cell.y 25 25)))) - - - system) - - ; (lambda register-notifications [] ; (beholder.observe "PLAYER.HIT" (lambda [other] ; (when (= other.object-type :info-pad) @@ -91,7 +59,7 @@ collider-manager camera walls - (fog-on-war) + fog-of-war (hud {: screen}) ] })] diff --git a/game/src/systems/fog_of_war.fnl b/game/src/systems/fog_of_war.fnl new file mode 100644 index 0000000..0644c3f --- /dev/null +++ b/game/src/systems/fog_of_war.fnl @@ -0,0 +1,34 @@ +(local color (require "src/colors.fnl")) +(local utils (require "src/utils.fnl")) +; (local beholder (require "libs/beholder")) +(local levels (require "levels.fnl")) + +(local fow + { :cells [] }) + +(lambda fow.load [self] + (let [tiles (. levels :levels self.pool.data.level-key :tiles) + rows-of-tiles (length tiles) + cols-of-tiles (length (. tiles 1)) + rows (+ 200 rows-of-tiles) ; 100 rows of padding above the tiles + cols (+ 200 cols-of-tiles) ; 100 cols of padding on the sides + x (- 0 (* 25 100)) ; offset 100 tiles left + y (- 0 (* 25 100)) ; offset 100 tiles up + ] + (for [row 0 rows] + (for [col 0 cols] + (table.insert self.cells {:x (+ x (* col 25)) :y (+ y (* row 25))}))) + + (each [_ cell (pairs self.cells)] + (set cell.hit false) + (lambda cell.on-hit [cell-self] + (set cell-self.hit true)) + (self.pool.data.bump-world:add cell cell.x cell.y 25 25)))) + +(lambda fow.draw80 [self] + (color.set-color :dark-purple) + (each [_ cell (pairs self.cells)] + (when (= cell.hit false) + (love.graphics.rectangle :fill cell.x cell.y 25 25)))) + +fow