move fog_of_war to seprate file

This commit is contained in:
Travis Shears 2026-04-27 13:27:51 +02:00
parent 5592b286cf
commit c10c03add0
Signed by: travisshears
GPG key ID: CB9BF1910F3F7469
2 changed files with 36 additions and 34 deletions

View file

@ -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})
]
})]

View file

@ -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