From ad03a0b0812bb8e15e5aa078d7c01eef5ebbdf2e Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 7 Apr 2022 22:22:00 +0100 Subject: restructure --- src/player.fnl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/player.fnl') 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} -- cgit v1.2.3