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/player.fnl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/player.fnl') 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