switch repo to just cleaning game focus
This commit is contained in:
parent
276c7c562b
commit
6d5406c6c5
49 changed files with 0 additions and 150 deletions
58
game/src/systems/walls.fnl
Normal file
58
game/src/systems/walls.fnl
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
(local assets (require "src/assets.fnl"))
|
||||
(local levels (require "levels.fnl"))
|
||||
(local color (require "src/colors.fnl"))
|
||||
|
||||
(local walls {
|
||||
:quads []
|
||||
:batch nil
|
||||
:collider-debug-boxes []
|
||||
})
|
||||
|
||||
(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 walls.load [self]
|
||||
(set self.batch (love.graphics.newSpriteBatch assets.walls-sprite 2500))
|
||||
;; load quads
|
||||
(let [(w h) (assets.walls-sprite:getDimensions)]
|
||||
(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)]
|
||||
(let [
|
||||
x tile.x
|
||||
y tile.y
|
||||
id tile.tile-id
|
||||
colliders tile.colliders]
|
||||
(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)]
|
||||
(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)
|
||||
(table.insert
|
||||
self.collider-debug-boxes
|
||||
{:x collider-x :y collider-y :width mirrored-collider.width :height mirrored-collider.height})))))))))
|
||||
|
||||
(fn walls.draw49 [self]
|
||||
(color.reset-color)
|
||||
(love.graphics.draw self.batch))
|
||||
|
||||
(fn walls.draw-debug [self]
|
||||
"draw collider debug boxes"
|
||||
(color.set-color :black)
|
||||
(each [_ collider (pairs self.collider-debug-boxes)]
|
||||
(love.graphics.rectangle "line" collider.x collider.y collider.width collider.height)))
|
||||
|
||||
walls
|
||||
Loading…
Add table
Add a link
Reference in a new issue