summaryrefslogtreecommitdiff
path: root/src/player.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.fnl')
-rw-r--r--src/player.fnl29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/player.fnl b/src/player.fnl
new file mode 100644
index 0000000..a429282
--- /dev/null
+++ b/src/player.fnl
@@ -0,0 +1,29 @@
+(local player { :x 250 :y 250 })
+
+(local SPEED 170)
+(local SPRINT-SPEED 280)
+
+(fn player.move [self dt world]
+ (let [speed (if (love.keyboard.isScancodeDown :lshift :rshift)
+ SPRINT-SPEED SPEED)
+ up (if (love.keyboard.isScancodeDown :w :up) 1 0)
+ down (if (love.keyboard.isScancodeDown :s :down) 1 0)
+ left (if (love.keyboard.isScancodeDown :a :left) 1 0)
+ right (if (love.keyboard.isScancodeDown :d :right) 1 0)
+ vy (- down up)
+ vx (- right left)
+ sf (math.sqrt (+ (* vx vx) (* vy vy)))]
+ (when (not= sf 0)
+ (let [vx (/ vx sf)
+ vy (/ vy sf)
+ tx (+ self.x (* vx dt speed))
+ ty (+ self.y (* vy dt speed))
+ (ax ay) (world:move :player tx ty)]
+ (tset self :x ax)
+ (tset self :y ay)))))
+
+(fn player.draw [self]
+ (love.graphics.setColor 0.91 0.62 0)
+ (love.graphics.rectangle :fill self.x self.y 10 10))
+
+player