From 1e7b0d68120c965b814f365b30236d92a5eea67a Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Fri, 8 May 2026 20:27:41 +0200 Subject: [PATCH] use player vision for fog_of_war --- game/main.fnl | 2 +- game/src/entities/player.fnl | 20 +------------------- game/src/systems/fog_of_war.fnl | 24 +++++++----------------- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/game/main.fnl b/game/main.fnl index b85be45..2876e73 100644 --- a/game/main.fnl +++ b/game/main.fnl @@ -9,7 +9,7 @@ (local dev (require "src/levels/dev.fnl")) (local level dev) -(local debug true) +(local debug false) (var pool nil) diff --git a/game/src/entities/player.fnl b/game/src/entities/player.fnl index 576e284..7db5761 100644 --- a/game/src/entities/player.fnl +++ b/game/src/entities/player.fnl @@ -86,9 +86,7 @@ (do (table.insert poly-pts (. pt 1)) (table.insert poly-pts (. pt 2)))))) - (set self.vision-pts poly-pts) - ; (utils.debug-print {: poly-pts}) )) @@ -121,6 +119,7 @@ (if (> self.battery 0) (set self.battery (- self.battery (* dt 2)))))) (beholder.trigger "PLAYER.POS" self.x self.y) + (beholder.trigger "PLAYER.VISION" self.vision-pts) (beholder.trigger "PLAYER.BATTERY" self.battery)) (fn player.load [self] @@ -157,26 +156,9 @@ (lambda player.draw-vision-debug [self] "draw debug lines and points for player vision" (color.set-color :black) - ; (love.graphics.setPointSize 2) - ; (utils.debug-print {:pts self.vision-pts :player {:x self.x :y self.y}}) - ; (each [_ pt (pairs self.vision-pts)] - ; (love.graphics.points (unpack pt))) (when (> (length self.vision-pts) 2) (love.graphics.polygon "line" self.vision-pts)) - ; (love.graphics.push) - ; (let [ox (+ self.x (/ width 2)) - ; oy (+ self.y (/ height 2)) - ; steps 20 - ; vision-step (/ (/ math.pi 2) steps)] ; 90 deg / 20 - ; (love.graphics.translate ox oy) - ; (love.graphics.rotate (- self.rot (/ (* steps vision-step) 2))) - ; (for [i 1 steps] - ; (love.graphics.rotate vision-step) - ; (love.graphics.line 0 0 50 0)) - ; (love.graphics.pop))) ) -; local items, len = world:querySegment(x1,y1,x2,y2,filter) - (fn player.draw-debug [self] "draw player hitbox and direction line" (color.set-color :black) diff --git a/game/src/systems/fog_of_war.fnl b/game/src/systems/fog_of_war.fnl index 6c17635..84f19fb 100644 --- a/game/src/systems/fog_of_war.fnl +++ b/game/src/systems/fog_of_war.fnl @@ -5,30 +5,19 @@ (local fow { - :player-x 0 - :player-y 0 + :player-vision-pts [] :font nil :canvas nil }) (lambda fow.load [self] (set self.font (love.graphics.newFont 10)) (set self.canvas (love.graphics.newCanvas 1000 1000)) - (beholder.observe "PLAYER.POS" (lambda [x y] - (set self.player-x x) - (set self.player-y y))) - ; (let [tiles (. levels :levels self.pool.data.level-key :tiles) - ; ; rows (length tiles) - ; ; cols (length (. tiles 1)) - ; ; x 0 - ; ; y 0 - ; ; w (* 25 cols) ; width of the level in pixels - ; ; h (* 25 rows) ; height of the level in pixels - ; previousCanvas (love.graphics.getCanvas) - ; ] - (let [ previousCanvas (love.graphics.getCanvas)] + (beholder.observe "PLAYER.VISION" (lambda [pts] + (set self.player-vision-pts pts))) + (let [previousCanvas (love.graphics.getCanvas)] (love.graphics.setCanvas self.canvas) (color.set-color :dark-purple) - ; (love.graphics.rectangle "fill" 0 0 1000 1000) + (love.graphics.rectangle "fill" 0 0 1000 1000) (love.graphics.setCanvas previousCanvas) )) @@ -41,7 +30,8 @@ (love.graphics.setCanvas self.canvas) (love.graphics.setBlendMode "replace") (love.graphics.setColor 0 0 0 0) ; transparent - (love.graphics.circle "fill" (+ (/ 19 2) x) (+ (/ 15 2) y) 20) + (when (> (length self.player-vision-pts) 2) + (love.graphics.polygon "fill" self.player-vision-pts)) (love.graphics.setBlendMode previousBlendMode) (love.graphics.setCanvas previousCanvas) ))