summaryrefslogtreecommitdiff
path: root/src/corridor.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'src/corridor.fnl')
-rw-r--r--src/corridor.fnl64
1 files changed, 60 insertions, 4 deletions
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]