add basic fog of war system
This commit is contained in:
parent
1d6b2f5337
commit
d0a9b04a80
2 changed files with 39 additions and 4 deletions
|
|
@ -10,6 +10,7 @@
|
|||
(local levels (require "levels.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
|
||||
(lambda load-objects [level-key pool]
|
||||
(each [_ object (pairs (. levels :levels level-key :objects))]
|
||||
; (debug-print object)
|
||||
|
|
@ -19,12 +20,45 @@
|
|||
)
|
||||
|
||||
(lambda collider-manager [bump-world]
|
||||
(local collider-manager {})
|
||||
(lambda collider-manager.addToGroup [self group-name entity]
|
||||
(local manager {})
|
||||
(lambda manager.addToGroup [self group-name entity]
|
||||
(when (= group-name :hitbox)
|
||||
; (utils.debug-print {:adding entity})
|
||||
(bump-world:add entity (unpack entity.hitbox))))
|
||||
collider-manager)
|
||||
manager)
|
||||
|
||||
(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]
|
||||
|
|
@ -60,6 +94,7 @@
|
|||
(collider-manager bump-world)
|
||||
camera
|
||||
walls
|
||||
(fog-on-war)
|
||||
(hud {: screen})
|
||||
]
|
||||
})]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue