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 level dev)
(local debug true)
(local debug false)
(var pool nil)

View file

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

View file

@ -1,55 +1,53 @@
(local color (require "src/colors.fnl"))
(local utils (require "src/utils.fnl"))
; (local beholder (require "libs/beholder"))
(local beholder (require "libs/beholder"))
(local levels (require "levels.fnl"))
(local fow
{ :cells [] :canvas nil })
{
:player-x 0
:player-y 0
:font nil
:canvas nil })
(lambda fow.load [self]
(set self.canvas (love.graphics.newCanvas 100 100))
(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
]
(utils.debug-print {:rows rows :cols cols :x x :y y :w w :h h})
(set self.x x)
(set self.y y)
(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)]
(love.graphics.setCanvas self.canvas)
(color.set-color :dark-purple)
(love.graphics.rectangle "fill" x y w h)
(love.graphics.setCanvas)))
(love.graphics.rectangle "fill" 0 0 1000 1000)
(love.graphics.setCanvas previousCanvas)
))
; (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.draw9 [self]
(let [
previousCanvas (love.graphics.getCanvas)
previousBlendMode (love.graphics.getBlendMode)
x self.player-x
y self.player-y]
(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)
(love.graphics.setBlendMode previousBlendMode)
(love.graphics.setCanvas previousCanvas)
))
(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)
; (love.graphics.draw self.canvas self.x self.y )
(love.graphics.draw self.canvas self.x self.y 0 2 2)
; (love.graphics.pop)
)
(love.graphics.draw self.canvas 0 0))
fow