blob: 9ba457a4320609cb8f75c7a217a8c1d98c31fdd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
(local SPEED 170)
(local SPRINT-SPEED 280)
(local C {})
(set C.__index C)
(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)
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)))
world (if ?world ?world
{:move (fn move [_1 _2 tx ty] (values tx ty))})]
(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 C.draw [self]
(love.graphics.setColor 0.91 0.62 0)
(love.graphics.rectangle :fill self.x self.y 10 10))
(fn make []
(let [s {:x 170 :y 150}]
(setmetatable s C)
s))
{: make}
|