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 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/main.fnl | 12 +++++++++++ src/player.fnl | 3 +-- src/rooms.fnl | 22 ------------------- 4 files changed, 73 insertions(+), 28 deletions(-) create mode 100644 src/main.fnl delete mode 100644 src/rooms.fnl (limited to 'src') 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] diff --git a/src/main.fnl b/src/main.fnl new file mode 100644 index 0000000..448e0a5 --- /dev/null +++ b/src/main.fnl @@ -0,0 +1,12 @@ +(local corridor (require :src.corridor)) + +(local font (love.graphics.newFont :assets/APL333.ttf 72)) +(local current-room (corridor.make font)) + + +(fn love.update [dt] + (current-room.update dt)) +(fn love.draw [] + (love.graphics.clear 1 1 1) + (current-room.draw)) + diff --git a/src/player.fnl b/src/player.fnl index 68d4f27..9ba457a 100644 --- a/src/player.fnl +++ b/src/player.fnl @@ -5,7 +5,6 @@ (set C.__index C) (fn C.update [self dt ?world] - (print ((. (require :vendor.fennel) :view) self)) (let [speed (if (love.keyboard.isScancodeDown :lshift :rshift) SPRINT-SPEED SPEED) up (if (love.keyboard.isScancodeDown :w :up) 1 0) @@ -16,7 +15,7 @@ vx (- right left) sf (math.sqrt (+ (* vx vx) (* vy vy))) world (if ?world ?world - {:move (fn move [_2 tx ty] (values tx ty))})] + {:move (fn move [_1 _2 tx ty] (values tx ty))})] (when (not= sf 0) (let [vx (/ vx sf) vy (/ vy sf) diff --git a/src/rooms.fnl b/src/rooms.fnl deleted file mode 100644 index a343a79..0000000 --- a/src/rooms.fnl +++ /dev/null @@ -1,22 +0,0 @@ -(local corridor (require :src.corridor)) -(local fennel (require :vendor.fennel)) - -(local state {}) - -(fn theload [] - (set state.font (love.graphics.newFont :assets/APL333.ttf 72)) - (set state.cur-room (corridor.make state))) - -(fn update [dt] - (state.cur-room.update dt)) - -(fn draw [...] - (local b [...]) - (print (fennel.view b)) - (state.cur-room.draw)) - -{:load theload - : update - : draw} - - -- cgit v1.2.3