From d6faf9716c167906c45deb099808d4d568e34c0d Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 2 May 2022 01:05:25 +0100 Subject: idfk --- src/corridor.fnl | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'src/corridor.fnl') diff --git a/src/corridor.fnl b/src/corridor.fnl index 8f1a6a0..a0ad593 100644 --- a/src/corridor.fnl +++ b/src/corridor.fnl @@ -4,15 +4,71 @@ (local player (require :src.player)) -(fn make [state] - (local font state.font) +(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 80 580 370) - (love.graphics.draw title (- 610 (title:getWidth)) -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] -- cgit v1.2.3