;; 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 draw-rectangle [mode x1 y1 x2 y2] ; instead of width and height (love.graphics.polygon mode x1 y1 x2 y1 x2 y2 x1 y2)) (local WIDTH 640) (local HALFWIDTH (/ WIDTH 2)) (local border-left -30) (local border-right 1520) (fn effective-ppos-x [player-x] (let [threshold-left (+ border-left HALFWIDTH) threshold-right (- border-right HALFWIDTH)] (clamp player-x threshold-left threshold-right))) (fn trans-amt-x [player-x] (let [eff (effective-ppos-x player-x)] (- HALFWIDTH eff))) (fn draw-stars [] (love.graphics.setColor 0.05 0.05 0.2) (love.graphics.rectangle :fill border-left 0 (- border-right border-left) 480) (math.randomseed 69420) (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)))] (love.graphics.setColor 1 1 c) (love.graphics.rectangle :fill x y sz sz)))) (fn make [font] (local title (love.graphics.newText font "corridor A2")) (local player (player.make)) (local windows [[10 100 400 80] [600 100 400 80] [1050 50 800 300]]) (fn draw-windows [] (love.graphics.stencil (fn [] (each [_ [x y w h] (pairs windows)] (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.pop) (love.graphics.setStencilTest) (love.graphics.setColor 0 0 0) (love.graphics.setLineWidth 7) (each [_ [x y w h] (pairs windows)] (love.graphics.rectangle :line x y w h))) (fn draw [] (love.graphics.setColor 0 0 0) (fn dbg-print [...] ; bad (var out {}) (for [i 1 (select :# ...) 2] (table.insert out (.. (select i ...) " " (select (+ i 1) ...)))) (let [txt (table.concat out "\n")] (love.graphics.print txt 6 28) (love.graphics.print txt 500 400))) (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)) (fn update [dt] (player:update dt)) {: draw : update}) {: make}