diff --git a/game/src/systems/camera.fnl b/game/src/systems/camera.fnl index 74e92af..de895f8 100644 --- a/game/src/systems/camera.fnl +++ b/game/src/systems/camera.fnl @@ -5,7 +5,7 @@ (local camera {:x 0 :y 0}) -(fn camera.draw10 [self] +(fn camera.draw25 [self] (love.graphics.origin) (love.graphics.translate (* -1 self.x) (* -1 self.y))) diff --git a/game/src/systems/fog_of_war.fnl b/game/src/systems/fog_of_war.fnl index d702587..ebd0a2d 100644 --- a/game/src/systems/fog_of_war.fnl +++ b/game/src/systems/fog_of_war.fnl @@ -9,7 +9,9 @@ :player-vision-pts [] :player-pos [0 0] :font nil - :canvas nil }) + :canvas nil + :main-canvas nil + }) (lambda fow.load [self] (set self.canvas (love.graphics.newCanvas 1000 1000)) @@ -24,15 +26,18 @@ (love.graphics.setCanvas previousCanvas) )) -(lambda fow.draw9 [self] +(lambda fow.draw10 [self] + (set self.main-canvas (love.graphics.getCanvas)) + (love.graphics.setCanvas self.canvas) + (love.graphics.clear) + (color.set-color :dark-purple) + (love.graphics.rectangle "fill" 0 0 1000 1000)) + + +(lambda fow.draw15 [self] (let [ - previousCanvas (love.graphics.getCanvas) previousBlendMode (love.graphics.getBlendMode) [x y] self.player-pos] - (love.graphics.setCanvas self.canvas) - (love.graphics.clear) - (color.set-color :dark-purple) - (love.graphics.rectangle "fill" 0 0 1000 1000) (love.graphics.setBlendMode "replace") (love.graphics.setColor 0 0 0 0) ; transparent (love.graphics.push) @@ -40,10 +45,10 @@ (love.graphics.polygon "fill" 3 11 3 17 7 21 17 21 21 17 21 11 17 7 7 7) (love.graphics.pop) ; draw the vision cone - (when (> (length self.player-vision-pts) 2) - (love.graphics.polygon "fill" self.player-vision-pts)) - (love.graphics.setBlendMode previousBlendMode) - (love.graphics.setCanvas previousCanvas))) + (when (> (length self.player-vision-pts) 2) + (love.graphics.polygon "fill" self.player-vision-pts)) + (love.graphics.setBlendMode previousBlendMode)) + (love.graphics.setCanvas self.main-canvas)) (lambda fow.draw80 [self] (color.reset-color) diff --git a/game/src/systems/radar.fnl b/game/src/systems/radar.fnl index bca255f..9506ae4 100644 --- a/game/src/systems/radar.fnl +++ b/game/src/systems/radar.fnl @@ -8,6 +8,9 @@ { :x 0 :y 0 :rot 0 + :debug-pt [0 0] + :boxes {} + :size 150 :speed 4 }) (lambda radar.load [self] @@ -16,18 +19,45 @@ (set self.x x) (set self.y y))))) +(lambda vision-bump-filter [other] + (= other.behavior "block")) + + (lambda radar.update [self dt] - (set self.rot (+ self.rot (* (/ dt self.speed))))) + (set self.rot (+ self.rot (* (/ dt self.speed)))) + ; if we are over the limit of radar boxes the oldest out + (let [ + ox self.x + oy self.y + x ox + y (- oy self.size) + (tip-x tip-y) (utils.rotate-pt x y ox oy (+ self.rot utils.deg-90)) + items (self.pool.data.bump-world:querySegment ox oy tip-x tip-y vision-bump-filter)] + (when (> (length items) 0) + (each [_ item (ipairs items)] + (set item.lase-seen dt) + (tset self.boxes item item))) + + (set self.debug-pt [tip-x tip-y]))) + +(lambda radar.draw11 [self] + (color.set-color :light-pink) + (each [_ box (pairs self.boxes)] + (love.graphics.rectangle "line" box.x box.y box.w box.h) + (love.graphics.line box.x box.y (+ box.x box.w) (+ box.y box.h)) + (love.graphics.line (+ box.x box.w) box.y box.x (+ box.y box.h)))) (lambda radar.draw81 [self] (color.set-color :dark-pink) + (love.graphics.setPointSize 4) + (love.graphics.points (unpack self.debug-pt)) + (love.graphics.line self.x self.y (. self.debug-pt 1) (. self.debug-pt 2)) (love.graphics.push) (love.graphics.translate self.x self.y) (love.graphics.rotate self.rot) - (love.graphics.setPointSize 2) (love.graphics.points 0 0) - (love.graphics.circle "line" 0 0 150) - (love.graphics.line 0 0 0 150) + (love.graphics.circle "line" 0 0 self.size) + (love.graphics.line 0 0 0 self.size) (love.graphics.pop)) radar diff --git a/game/src/systems/walls.fnl b/game/src/systems/walls.fnl index e6a007b..071a19f 100644 --- a/game/src/systems/walls.fnl +++ b/game/src/systems/walls.fnl @@ -30,6 +30,9 @@ (love.graphics.line x1 y1 x1 (+ y1 1000)) (love.graphics.print (.. (string.format "%d" x1) "," (string.format "%d" y1)) (+ x1 3) (+ y1 3))))))) +; (lambda gen-wall-collider-box [x y width height] +; ) + (fn walls.load [self] (set self.batch (love.graphics.newSpriteBatch assets.walls-sprite 2500)) ;; load quads @@ -37,8 +40,8 @@ (for [i 0 19 1] (table.insert self.quads (love.graphics.newQuad (* i 25) 0 25 25 w h)))) ;; fill batch - (each [_ row (pairs (. levels :levels self.pool.data.level-key :tiles))] - (each [_ tile (pairs row)] + (each [row-key row (pairs (. levels :levels self.pool.data.level-key :tiles))] + (each [tile-key tile (pairs row)] (let [ x tile.x y tile.y @@ -47,12 +50,12 @@ (if (and (> id 0) (< id 21)) ;; 1-20 are wall tiles (do (self.batch:add (. self.quads id) (if tile.h-flip (+ x 25) x) y 0 (if tile.h-flip -1 1) 1) - (each [_ collider (pairs colliders)] + (each [collider-key collider (pairs colliders)] (let [ mirrored-collider (if tile.h-flip (mirror-collider collider) collider) collider-x (+ x mirrored-collider.x) collider-y (+ y mirrored-collider.y)] - (self.pool.data.bump-world:add {: x : y :name :wall :behavior :block} collider-x collider-y mirrored-collider.width mirrored-collider.height) + (self.pool.data.bump-world:add {:id (.. row-key tile-key collider-key) : x : y :name :wall :behavior :block :w mirrored-collider.width :h mirrored-collider.height} collider-x collider-y mirrored-collider.width mirrored-collider.height) (table.insert self.collider-debug-boxes {:x collider-x :y collider-y :width mirrored-collider.width :height mirrored-collider.height})))))))) @@ -65,7 +68,7 @@ ) -(fn walls.draw49 [self] +(fn walls.draw40 [self] (color.reset-color) (love.graphics.draw self.batch))