-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.lisp
55 lines (48 loc) · 1.22 KB
/
player.lisp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(in-package :crawl)
(defclass player (mob)
((spd :initform 20 :accessor spd)
)
)
(defmethod walk-left ((player player))
(setf (anim player) 'walk-left)
(setf (vx player) -1.0)
)
(defmethod walk-right ((player player))
(setf (anim player) 'walk-right)
(setf (vx player) 1.0)
)
(defmethod walk-up ((player player))
(setf (anim player) 'walk-up)
(setf (vy player) 1.0)
)
(defmethod walk-down ((player player))
(setf (anim player) 'walk-down)
(setf (vy player) -1.0)
)
(defmethod idle ((player player))
(setf (anim player) 'idle)
(setf (vx player) 0)
(setf (vy player) 0)
)
(defmethod update ((player player) ticks)
(with-accessors ((pos pos) (vx vx) (vy vy)) player
(if (input :walk-up)
(if (input :walk-down)
(setf vy 0)
(walk-up player))
(if (input :walk-down)
(walk-down player)
(setf vy 0)))
(if (input :walk-left)
(if (input :walk-right)
(setf vx 0)
(walk-left player))
(if (input :walk-right)
(walk-right player)
(setf vx 0)))
(if (= 0 vx vy) (idle player))
(setf pos (add pos (mult (vec2 vx vy) (spd player) ticks)))
(setf (x pos) (round (x pos)))
(setf (y pos) (round (y pos)))
)
)