move fog_of_war to seprate file
This commit is contained in:
parent
5592b286cf
commit
c10c03add0
2 changed files with 36 additions and 34 deletions
|
|
@ -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})
|
||||
]
|
||||
})]
|
||||
|
|
|
|||
34
game/src/systems/fog_of_war.fnl
Normal file
34
game/src/systems/fog_of_war.fnl
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue