From 7e8a6f1b60d3d279a14f355e76e3b1e43c0e181a Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 6 May 2022 01:09:07 +0100 Subject: more paralax, and walls --- src/corridor.fnl | 77 ++++++++++++++++++++++++++++++++++++++------------------ src/player.fnl | 19 ++++++++------ 2 files changed, 64 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/corridor.fnl b/src/corridor.fnl index d6aef59..5363434 100644 --- a/src/corridor.fnl +++ b/src/corridor.fnl @@ -3,6 +3,7 @@ ;; corridors with the same code, eventually (local player (require :src.player)) +(local bump (require :vendor.bump)) (fn clamp [x min max] (if (< x min) min @@ -19,7 +20,7 @@ (local HALFWIDTH (/ WIDTH 2)) (local border-left -30) -(local border-right 1520) +(local border-right 1230) (fn effective-ppos-x [player-x] (let [threshold-left (+ border-left HALFWIDTH) @@ -31,26 +32,58 @@ (- HALFWIDTH eff))) -(fn draw-stars [] +(fn draw-stars [cpos] (love.graphics.setColor 0.05 0.05 0.2) (love.graphics.rectangle :fill border-left 0 (- border-right border-left) 480) - (math.randomseed 69420) + (math.randomseed 62869420) (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)))] + c (- 0.7 (* 0.3 (math.random))) + d (+ 0.5 (math.random))] (love.graphics.setColor 1 1 c) - (love.graphics.rectangle :fill x y sz sz)))) + (love.graphics.rectangle :fill (+ x (* 0.1 d cpos)) y sz sz)))) + +(fn add-rect-bounds [world x1 y1 x2 y2 ?inset ?prefix ?thickness] + (let [w (- x2 x1) + h (- y2 y1) + prefix (or ?prefix "") + thickness (or ?thickness 10) + inset (or ?inset 0) + Lu (.. prefix :-Wu) + Ld (.. prefix :-Wd) + Ll (.. prefix :-Wl) + Lr (.. prefix :-Wr)] + (print thickness) + (world:add Lu x1 (- y1 thickness) w (+ thickness inset)) + (world:add Ld x1 (- y2 inset) w (+ thickness inset)) + (world:add Ll (- x1 thickness) y1 (+ thickness inset) h) + (world:add Lr (- x2 inset) y1 (+ thickness inset) h))) + + +(fn dbg-world [world] + (love.graphics.setLineWidth 1) + (love.graphics.setColor 1 0 0) + (let [items (world:getItems)] + (each [_ item (pairs items)] + (let [(x y w h) (world:getRect item)] + (love.graphics.rectangle :line x y w h) + (if (= (type item) :string) + (love.graphics.print item x y)))))) + (fn make [font] - (local title (love.graphics.newText font "corridor A2")) - (local player (player.make)) + (local title (love.graphics.newText font "Corridor A2")) + (local player (player.make 100 340)) (local windows [[10 100 400 80] [600 100 400 80] [1050 50 800 300]]) - + (local world (bump.newWorld)) + (world:add :player player.x player.y 30 30) + (add-rect-bounds world 0 250 1000 450 5) + (fn draw-windows [] (love.graphics.stencil (fn [] @@ -58,11 +91,12 @@ (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.origin) + (love.graphics.translate (* 0.25 cpos) 0) + (draw-stars cpos)) (love.graphics.pop) (love.graphics.setStencilTest) @@ -87,30 +121,23 @@ (love.graphics.print txt 6 28) (love.graphics.print txt 500 400))) - (dbg-print - :x player.x - :y player.y) - - + ;(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) - - (player:draw)) + ;(dbg-world world) + ) (fn update [dt] - (player:update dt)) + (player:update dt world)) {: draw : update}) diff --git a/src/player.fnl b/src/player.fnl index 53ceb59..702d466 100644 --- a/src/player.fnl +++ b/src/player.fnl @@ -4,7 +4,7 @@ (local C {}) (set C.__index C) -(fn C.update [self dt ?world] +(fn C.update [self dt world] (let [speed (if (love.keyboard.isScancodeDown :lshift :rshift) SPRINT-SPEED SPEED) up (if (love.keyboard.isScancodeDown :w :up) 1 0) @@ -13,9 +13,9 @@ right (if (love.keyboard.isScancodeDown :d :right) 1 0) vy (- down up) vx (- right left) - sf (math.sqrt (+ (* vx vx) (* vy vy))) - world (if ?world ?world - {:move (fn move [_1 _2 tx ty] (values tx ty))})] + sf (math.sqrt (+ (* vx vx) (* vy vy)))] + ; world (if ?world ?world + ; {:move (fn move [_1 _2 tx ty] (values tx ty))})] (when (not= sf 0) (if (> vx 0) (set self.left false) (< vx 0) (set self.left true)) @@ -23,13 +23,16 @@ vy (/ vy sf) tx (+ self.x (* vx dt speed)) ty (+ self.y (* vy dt speed)) - (ax ay) (world:move :player tx ty)] + (ax ay) (if world + (world:move :player tx ty) + (values tx ty))] (set self.x ax) (set self.y ay))))) (fn C.draw [self] (love.graphics.push) (love.graphics.translate self.x self.y) + (love.graphics.translate 15 15) (if self.left (love.graphics.scale -1 1)) (love.graphics.scale 0.1) @@ -55,8 +58,10 @@ -(fn make [] - (let [s {:x 170 :y 150 :left false}] +(fn make [?x ?y] + (let [x (or ?x 170) + y (or ?y 150) + s {: x : y :left false}] (setmetatable s C) s)) -- cgit v1.2.3