render radar boxes
This commit is contained in:
parent
bd12a4d504
commit
925d375313
4 changed files with 59 additions and 21 deletions
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
(local camera {:x 0 :y 0})
|
(local camera {:x 0 :y 0})
|
||||||
|
|
||||||
(fn camera.draw10 [self]
|
(fn camera.draw25 [self]
|
||||||
(love.graphics.origin)
|
(love.graphics.origin)
|
||||||
(love.graphics.translate (* -1 self.x) (* -1 self.y)))
|
(love.graphics.translate (* -1 self.x) (* -1 self.y)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@
|
||||||
:player-vision-pts []
|
:player-vision-pts []
|
||||||
:player-pos [0 0]
|
:player-pos [0 0]
|
||||||
:font nil
|
:font nil
|
||||||
:canvas nil })
|
:canvas nil
|
||||||
|
:main-canvas nil
|
||||||
|
})
|
||||||
|
|
||||||
(lambda fow.load [self]
|
(lambda fow.load [self]
|
||||||
(set self.canvas (love.graphics.newCanvas 1000 1000))
|
(set self.canvas (love.graphics.newCanvas 1000 1000))
|
||||||
|
|
@ -24,15 +26,18 @@
|
||||||
(love.graphics.setCanvas previousCanvas)
|
(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 [
|
(let [
|
||||||
previousCanvas (love.graphics.getCanvas)
|
|
||||||
previousBlendMode (love.graphics.getBlendMode)
|
previousBlendMode (love.graphics.getBlendMode)
|
||||||
[x y] self.player-pos]
|
[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.setBlendMode "replace")
|
||||||
(love.graphics.setColor 0 0 0 0) ; transparent
|
(love.graphics.setColor 0 0 0 0) ; transparent
|
||||||
(love.graphics.push)
|
(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.polygon "fill" 3 11 3 17 7 21 17 21 21 17 21 11 17 7 7 7)
|
||||||
(love.graphics.pop)
|
(love.graphics.pop)
|
||||||
; draw the vision cone
|
; draw the vision cone
|
||||||
(when (> (length self.player-vision-pts) 2)
|
(when (> (length self.player-vision-pts) 2)
|
||||||
(love.graphics.polygon "fill" self.player-vision-pts))
|
(love.graphics.polygon "fill" self.player-vision-pts))
|
||||||
(love.graphics.setBlendMode previousBlendMode)
|
(love.graphics.setBlendMode previousBlendMode))
|
||||||
(love.graphics.setCanvas previousCanvas)))
|
(love.graphics.setCanvas self.main-canvas))
|
||||||
|
|
||||||
(lambda fow.draw80 [self]
|
(lambda fow.draw80 [self]
|
||||||
(color.reset-color)
|
(color.reset-color)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@
|
||||||
{ :x 0
|
{ :x 0
|
||||||
:y 0
|
:y 0
|
||||||
:rot 0
|
:rot 0
|
||||||
|
:debug-pt [0 0]
|
||||||
|
:boxes {}
|
||||||
|
:size 150
|
||||||
:speed 4 })
|
:speed 4 })
|
||||||
|
|
||||||
(lambda radar.load [self]
|
(lambda radar.load [self]
|
||||||
|
|
@ -16,18 +19,45 @@
|
||||||
(set self.x x)
|
(set self.x x)
|
||||||
(set self.y y)))))
|
(set self.y y)))))
|
||||||
|
|
||||||
|
(lambda vision-bump-filter [other]
|
||||||
|
(= other.behavior "block"))
|
||||||
|
|
||||||
|
|
||||||
(lambda radar.update [self dt]
|
(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]
|
(lambda radar.draw81 [self]
|
||||||
(color.set-color :dark-pink)
|
(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.push)
|
||||||
(love.graphics.translate self.x self.y)
|
(love.graphics.translate self.x self.y)
|
||||||
(love.graphics.rotate self.rot)
|
(love.graphics.rotate self.rot)
|
||||||
(love.graphics.setPointSize 2)
|
|
||||||
(love.graphics.points 0 0)
|
(love.graphics.points 0 0)
|
||||||
(love.graphics.circle "line" 0 0 150)
|
(love.graphics.circle "line" 0 0 self.size)
|
||||||
(love.graphics.line 0 0 0 150)
|
(love.graphics.line 0 0 0 self.size)
|
||||||
(love.graphics.pop))
|
(love.graphics.pop))
|
||||||
|
|
||||||
radar
|
radar
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@
|
||||||
(love.graphics.line x1 y1 x1 (+ y1 1000))
|
(love.graphics.line x1 y1 x1 (+ y1 1000))
|
||||||
(love.graphics.print (.. (string.format "%d" x1) "," (string.format "%d" y1)) (+ x1 3) (+ y1 3)))))))
|
(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]
|
(fn walls.load [self]
|
||||||
(set self.batch (love.graphics.newSpriteBatch assets.walls-sprite 2500))
|
(set self.batch (love.graphics.newSpriteBatch assets.walls-sprite 2500))
|
||||||
;; load quads
|
;; load quads
|
||||||
|
|
@ -37,8 +40,8 @@
|
||||||
(for [i 0 19 1]
|
(for [i 0 19 1]
|
||||||
(table.insert self.quads (love.graphics.newQuad (* i 25) 0 25 25 w h))))
|
(table.insert self.quads (love.graphics.newQuad (* i 25) 0 25 25 w h))))
|
||||||
;; fill batch
|
;; fill batch
|
||||||
(each [_ row (pairs (. levels :levels self.pool.data.level-key :tiles))]
|
(each [row-key row (pairs (. levels :levels self.pool.data.level-key :tiles))]
|
||||||
(each [_ tile (pairs row)]
|
(each [tile-key tile (pairs row)]
|
||||||
(let [
|
(let [
|
||||||
x tile.x
|
x tile.x
|
||||||
y tile.y
|
y tile.y
|
||||||
|
|
@ -47,12 +50,12 @@
|
||||||
(if (and (> id 0) (< id 21)) ;; 1-20 are wall tiles
|
(if (and (> id 0) (< id 21)) ;; 1-20 are wall tiles
|
||||||
(do
|
(do
|
||||||
(self.batch:add (. self.quads id) (if tile.h-flip (+ x 25) x) y 0 (if tile.h-flip -1 1) 1)
|
(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 [
|
(let [
|
||||||
mirrored-collider (if tile.h-flip (mirror-collider collider) collider)
|
mirrored-collider (if tile.h-flip (mirror-collider collider) collider)
|
||||||
collider-x (+ x mirrored-collider.x)
|
collider-x (+ x mirrored-collider.x)
|
||||||
collider-y (+ y mirrored-collider.y)]
|
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
|
(table.insert
|
||||||
self.collider-debug-boxes
|
self.collider-debug-boxes
|
||||||
{:x collider-x :y collider-y :width mirrored-collider.width :height mirrored-collider.height}))))))))
|
{: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)
|
(color.reset-color)
|
||||||
(love.graphics.draw self.batch))
|
(love.graphics.draw self.batch))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue