diff options
Diffstat (limited to 'src/corridor.fnl')
-rw-r--r-- | src/corridor.fnl | 77 |
1 files changed, 52 insertions, 25 deletions
diff --git a/src/corridor.fnl b/src/corridor.fnl index d6aef59..5363434 100644 --- a/src/corridor.fnl +++ b/src/corridor.fnl @@ -3,6 +3,7 @@ ;; corridors with the same code, eventually (local player (require :src.player)) +(local bump (require :vendor.bump)) (fn clamp [x min max] (if (< x min) min @@ -19,7 +20,7 @@ (local HALFWIDTH (/ WIDTH 2)) (local border-left -30) -(local border-right 1520) +(local border-right 1230) (fn effective-ppos-x [player-x] (let [threshold-left (+ border-left HALFWIDTH) @@ -31,26 +32,58 @@ (- HALFWIDTH eff))) -(fn draw-stars [] +(fn draw-stars [cpos] (love.graphics.setColor 0.05 0.05 0.2) (love.graphics.rectangle :fill border-left 0 (- border-right border-left) 480) - (math.randomseed 69420) + (math.randomseed 62869420) (love.graphics.setColor 1 1 1) (for [i 1 200] (let [sz (math.random 3 10) x (math.random border-left border-right) y (math.random 0 480) - c (- 0.7 (* 0.3 (math.random)))] + c (- 0.7 (* 0.3 (math.random))) + d (+ 0.5 (math.random))] (love.graphics.setColor 1 1 c) - (love.graphics.rectangle :fill x y sz sz)))) + (love.graphics.rectangle :fill (+ x (* 0.1 d cpos)) y sz sz)))) + +(fn add-rect-bounds [world x1 y1 x2 y2 ?inset ?prefix ?thickness] + (let [w (- x2 x1) + h (- y2 y1) + prefix (or ?prefix "") + thickness (or ?thickness 10) + inset (or ?inset 0) + Lu (.. prefix :-Wu) + Ld (.. prefix :-Wd) + Ll (.. prefix :-Wl) + Lr (.. prefix :-Wr)] + (print thickness) + (world:add Lu x1 (- y1 thickness) w (+ thickness inset)) + (world:add Ld x1 (- y2 inset) w (+ thickness inset)) + (world:add Ll (- x1 thickness) y1 (+ thickness inset) h) + (world:add Lr (- x2 inset) y1 (+ thickness inset) h))) + + +(fn dbg-world [world] + (love.graphics.setLineWidth 1) + (love.graphics.setColor 1 0 0) + (let [items (world:getItems)] + (each [_ item (pairs items)] + (let [(x y w h) (world:getRect item)] + (love.graphics.rectangle :line x y w h) + (if (= (type item) :string) + (love.graphics.print item x y)))))) + (fn make [font] - (local title (love.graphics.newText font "corridor A2")) - (local player (player.make)) + (local title (love.graphics.newText font "Corridor A2")) + (local player (player.make 100 340)) (local windows [[10 100 400 80] [600 100 400 80] [1050 50 800 300]]) - + (local world (bump.newWorld)) + (world:add :player player.x player.y 30 30) + (add-rect-bounds world 0 250 1000 450 5) + (fn draw-windows [] (love.graphics.stencil (fn [] @@ -58,11 +91,12 @@ (love.graphics.rectangle :fill x y w h)) :replace 1)) (love.graphics.setStencilTest :greater 0) - ; stil hacky + (love.graphics.push) (let [cpos (trans-amt-x player.x)] - (love.graphics.translate (* -0.75 cpos) 0)) - (draw-stars) + (love.graphics.origin) + (love.graphics.translate (* 0.25 cpos) 0) + (draw-stars cpos)) (love.graphics.pop) (love.graphics.setStencilTest) @@ -87,30 +121,23 @@ (love.graphics.print txt 6 28) (love.graphics.print txt 500 400))) - (dbg-print - :x player.x - :y player.y) - - + ;(dbg-print + ; :x player.x + ; :y player.y) - - - (love.graphics.translate (trans-amt-x player.x) 0) - (love.graphics.setColor 0.8 0.8 0.8) (love.graphics.setLineWidth 10) (draw-rectangle :line 0 250 1000 450) - (draw-windows) - (love.graphics.draw title 0 10) + (player:draw) - - (player:draw)) + ;(dbg-world world) + ) (fn update [dt] - (player:update dt)) + (player:update dt world)) {: draw : update}) |