mirror collider box
This commit is contained in:
parent
e00250fd84
commit
ffe9d8226d
1 changed files with 19 additions and 6 deletions
|
|
@ -53,7 +53,7 @@
|
||||||
:scale scale
|
:scale scale
|
||||||
:canvas nil}))
|
:canvas nil}))
|
||||||
(local camera {:x 0 :y 0})
|
(local camera {:x 0 :y 0})
|
||||||
(local debug false)
|
(local debug true)
|
||||||
(lambda debug-print [obj]
|
(lambda debug-print [obj]
|
||||||
(print (fennel.view obj)))
|
(print (fennel.view obj)))
|
||||||
|
|
||||||
|
|
@ -64,6 +64,16 @@
|
||||||
(var bump-world nil)
|
(var bump-world nil)
|
||||||
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 })
|
(local player { :x 50 :y 50 :w 25 :h 25 :speed 80 :battery 100 :rot 0 })
|
||||||
|
|
||||||
|
(lambda mirror-collider [collider]
|
||||||
|
"Mirror a collider box horizontally within a 25-unit tile (center is at 12.5)
|
||||||
|
Transforms collider positions so they're reflected across the vertical center line."
|
||||||
|
{
|
||||||
|
:x (- 25 collider.x collider.width)
|
||||||
|
:y collider.y
|
||||||
|
:width collider.width
|
||||||
|
:height collider.height
|
||||||
|
})
|
||||||
|
|
||||||
(fn load-walls []
|
(fn load-walls []
|
||||||
(set walls.batch (love.graphics.newSpriteBatch walls.sprite 2500))
|
(set walls.batch (love.graphics.newSpriteBatch walls.sprite 2500))
|
||||||
;; load quads
|
;; load quads
|
||||||
|
|
@ -83,11 +93,14 @@
|
||||||
; (print (fennel.view {:quad (. walls.quads id) : x : y : id}))
|
; (print (fennel.view {:quad (. walls.quads id) : x : y : id}))
|
||||||
(walls.batch:add (. walls.quads id) (if tile.h-flip (+ x 25) x) y 0 (if tile.h-flip -1 1) 1)
|
(walls.batch:add (. walls.quads id) (if tile.h-flip (+ x 25) x) y 0 (if tile.h-flip -1 1) 1)
|
||||||
(each [_ collider (pairs colliders)]
|
(each [_ collider (pairs colliders)]
|
||||||
(bump-world:add {: x : y :name :wall :behavior :block} (+ x collider.x) (+ y collider.y) collider.width collider.height)
|
(let [
|
||||||
|
mirrored-collider (if tile.h-flip (mirror-collider collider) collider)
|
||||||
|
collider-x (+ x mirrored-collider.x)
|
||||||
|
collider-y (+ y mirrored-collider.y)]
|
||||||
|
(bump-world:add {: x : y :name :wall :behavior :block} collider-x collider-y mirrored-collider.width mirrored-collider.height)
|
||||||
(table.insert
|
(table.insert
|
||||||
collider-debug-boxes
|
collider-debug-boxes
|
||||||
{:x (+ x collider.x) :y (+ y collider.y) :width collider.width :height collider.height}))
|
{:x collider-x :y collider-y :width mirrored-collider.width :height mirrored-collider.height})))))))))
|
||||||
))))))
|
|
||||||
|
|
||||||
(lambda create-charging-station [x y]
|
(lambda create-charging-station [x y]
|
||||||
(let [
|
(let [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue