get circle fog_of_war working

This commit is contained in:
Travis Shears 2026-05-03 20:36:38 +02:00
parent cffdeda2e9
commit ddc6c6da5d
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
3 changed files with 44 additions and 46 deletions

View file

@ -9,7 +9,7 @@
(local dev (require "src/levels/dev.fnl")) (local dev (require "src/levels/dev.fnl"))
(local level dev) (local level dev)
(local debug true) (local debug false)
(var pool nil) (var pool nil)

View file

@ -5,8 +5,8 @@
(local camera {:x 0 :y 0}) (local camera {:x 0 :y 0})
(fn camera.draw2 [self] (fn camera.draw10 [self]
(love.graphics.push) (love.graphics.origin)
(love.graphics.translate (* -1 self.x) (* -1 self.y))) (love.graphics.translate (* -1 self.x) (* -1 self.y)))
(fn camera.load [self] (fn camera.load [self]
@ -17,7 +17,7 @@
(set self.y (- y (/ screen.canvas-h 2))))))) (set self.y (- y (/ screen.canvas-h 2)))))))
(fn camera.draw89 [self] (fn camera.draw89 [self]
(love.graphics.pop)) ; undo camera translation (love.graphics.origin)) ; reset camera translation
(fn camera.draw99 [self] (fn camera.draw99 [self]
(let [screen self.pool.data.screen canvas self.pool.data.canvas] (let [screen self.pool.data.screen canvas self.pool.data.canvas]

View file

@ -1,55 +1,53 @@
(local color (require "src/colors.fnl")) (local color (require "src/colors.fnl"))
(local utils (require "src/utils.fnl")) (local utils (require "src/utils.fnl"))
; (local beholder (require "libs/beholder")) (local beholder (require "libs/beholder"))
(local levels (require "levels.fnl")) (local levels (require "levels.fnl"))
(local fow (local fow
{ :cells [] :canvas nil }) {
:player-x 0
:player-y 0
:font nil
:canvas nil })
(lambda fow.load [self] (lambda fow.load [self]
(set self.canvas (love.graphics.newCanvas 100 100)) (set self.font (love.graphics.newFont 10))
(let [tiles (. levels :levels self.pool.data.level-key :tiles) (set self.canvas (love.graphics.newCanvas 1000 1000))
rows (length tiles) (beholder.observe "PLAYER.POS" (lambda [x y]
cols (length (. tiles 1)) (set self.player-x x)
x 0 (set self.player-y y)))
y 0 ; (let [tiles (. levels :levels self.pool.data.level-key :tiles)
w (* 25 cols) ; width of the level in pixels ; ; rows (length tiles)
h (* 25 rows) ; height of the level in pixels ; ; cols (length (. tiles 1))
] ; ; x 0
(utils.debug-print {:rows rows :cols cols :x x :y y :w w :h h}) ; ; y 0
(set self.x x) ; ; w (* 25 cols) ; width of the level in pixels
(set self.y y) ; ; h (* 25 rows) ; height of the level in pixels
(love.graphics.setCanvas self.canvas) ; previousCanvas (love.graphics.getCanvas)
(color.set-color :dark-purple) ; ]
(love.graphics.rectangle "fill" x y w h) (let [ previousCanvas (love.graphics.getCanvas)]
(love.graphics.setCanvas))) (love.graphics.setCanvas self.canvas)
(color.set-color :dark-purple)
(love.graphics.rectangle "fill" 0 0 1000 1000)
(love.graphics.setCanvas previousCanvas)
))
; (for [row 0 rows] (lambda fow.draw9 [self]
; (for [col 0 cols] (let [
; (table.insert self.cells {:x (+ x (* col 25)) :y (+ y (* row 25))}))) previousCanvas (love.graphics.getCanvas)
previousBlendMode (love.graphics.getBlendMode)
; (each [_ cell (pairs self.cells)] x self.player-x
; (set cell.hit false) y self.player-y]
; (lambda cell.on-hit [cell-self] (love.graphics.setCanvas self.canvas)
; (set cell-self.hit true)) (love.graphics.setBlendMode "replace")
; (self.pool.data.bump-world:add cell cell.x cell.y 25 25)))) (love.graphics.setColor 0 0 0 0) ; transparent
(love.graphics.circle "fill" (+ (/ 19 2) x) (+ (/ 15 2) y) 20)
(love.graphics.setBlendMode previousBlendMode)
(love.graphics.setCanvas previousCanvas)
))
(lambda fow.draw80 [self] (lambda fow.draw80 [self]
; (love.graphics.push)
; (love.graphics.origin)
; (love.graphics.setCanvas self.canvas)
; (color.set-color :dark-purple)
; (love.graphics.rectangle "fill" 0 0 250 250)
; (love.graphics.setColor 0 0 0 0)
; (love.graphics.setBlendMode "replace")
; (love.graphics.circle "fill" 25 25 20)
; (love.graphics.setBlendMode "alpha")
; (love.graphics.setCanvas self.pool.data.canvas)
(color.reset-color) (color.reset-color)
; (love.graphics.draw self.canvas self.x self.y ) (love.graphics.draw self.canvas 0 0))
(love.graphics.draw self.canvas self.x self.y 0 2 2)
; (love.graphics.pop)
)
fow fow