;; corridor ;; maybe make this generic enough to have multiple ;; corridors with the same code, eventually (local player (require :src.player)) (fn clamp [x min max] (if (< x min) min (> x max) max x)) (fn camera-trans-amt [player-x] (- (clamp (- player-x 320) 0 400))) (fn centre-pos [player-x] ; a bit hacky (+ 320 (- (camera-trans-amt player-x)))) (local window-depth-x 15) (local window-depth-y 10) (local window-prlx-fact 0.04) (fn draw-window [x y w h cpos] (love.graphics.setColor 0.9 0.9 0.9) (love.graphics.rectangle :fill x y w h) (love.graphics.setColor 0 0 0) (love.graphics.setLineWidth 4) (love.graphics.rectangle :line x y w h) (let [centre (+ x (/ w 2)) offset (- centre cpos) movt (* offset window-prlx-fact) left* (+ movt x window-depth-x) right* (+ movt (- (+ x w) window-depth-x)) left (math.max left* x) right (math.min right* (+ x w))] (love.graphics.rectangle :line left (+ window-depth-y y) (- right left) (- h (* 2 window-depth-y))))) ;(love.graphics.rectangle :line ; (+ (* left-offset window-depth-x) x) ; (+ window-depth-y y) ; (- w (* 2 (* right-offset window-depth-x))) ; (- h (* 2 window-depth-y)))) (fn make [font] (local title (love.graphics.newText font :corridor)) (local player (player.make)) (fn draw [] (love.graphics.setColor 0 0 0) (love.graphics.print (.. :+px " " player.x "\n" :-px " " (- 320 player.x) "\n" :cta " " (camera-trans-amt player.x) "\n" :cps " " (centre-pos player.x)) 6 20) (love.graphics.translate (camera-trans-amt player.x) 0) (love.graphics.setColor 0.8 0.8 0.8) (love.graphics.setLineWidth 10) (love.graphics.rectangle :line 30 250 980 200) (let [c (centre-pos player.x)] (draw-window 300 100 300 80 c) (draw-window 630 100 300 80 c)) ;(love.graphics.draw title (- 610 (title:getWidth)) -10) (player:draw)) (fn update [dt] (player:update dt)) {: draw : update}) {: make}