diff options
author | ubq323 <ubq323@ubq323.website> | 2022-04-07 22:22:00 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2022-04-07 22:22:00 +0100 |
commit | ad03a0b0812bb8e15e5aa078d7c01eef5ebbdf2e (patch) | |
tree | 3641114fa3e5d38d072c5a9cbfd8e871be0feeb1 /src/player.fnl | |
parent | 4ec2e421bd05fb178c5bf8317606b4fadd622b54 (diff) |
restructure
Diffstat (limited to 'src/player.fnl')
-rw-r--r-- | src/player.fnl | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/player.fnl b/src/player.fnl index a429282..68d4f27 100644 --- a/src/player.fnl +++ b/src/player.fnl @@ -1,9 +1,11 @@ -(local player { :x 250 :y 250 }) - (local SPEED 170) (local SPRINT-SPEED 280) -(fn player.move [self dt world] +(local C {}) +(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) @@ -12,7 +14,9 @@ right (if (love.keyboard.isScancodeDown :d :right) 1 0) vy (- down up) vx (- right left) - sf (math.sqrt (+ (* vx vx) (* vy vy)))] + sf (math.sqrt (+ (* vx vx) (* vy vy))) + world (if ?world ?world + {:move (fn move [_2 tx ty] (values tx ty))})] (when (not= sf 0) (let [vx (/ vx sf) vy (/ vy sf) @@ -22,8 +26,13 @@ (tset self :x ax) (tset self :y ay))))) -(fn player.draw [self] +(fn C.draw [self] (love.graphics.setColor 0.91 0.62 0) (love.graphics.rectangle :fill self.x self.y 10 10)) -player +(fn make [] + (let [s {:x 170 :y 150}] + (setmetatable s C) + s)) + +{: make} |