-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.lisp
43 lines (39 loc) · 1.28 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
(in-package #:rougespace)
(defclass player (drawable object)
((symbol :initform 64)
(can-share :initform t)
(in-world :accessor player-in-world
:initform nil
:initarg :in-world)
(pos :accessor player-pos
:initform nil
:initarg :pos)))
(defmethod player-move ((p Player) dx dy)
(if (and (world-edge-check (player-in-world p)
(+ (pos-x (player-pos p)) dx)
(+ (pos-y (player-pos p)) dy))
(can-share (aref (world-array (player-in-world p))
(+ (pos-x (player-pos p)) dx)
(+ (pos-y (player-pos p)) dy))))
(progn
;move player in world
(remove p (aref (world-array (player-in-world p))
(pos-x (player-pos p))
(pos-y (player-pos p))))
(cons (aref (world-array (player-in-world p))
(+ (pos-x (player-pos p)) dx)
(+ (pos-y (player-pos p)) dy)) p)
;update player pos
(setf (pos-x (player-pos p))
(+ (pos-x (player-pos p)) dx))
(setf (pos-y (player-pos p))
(+ (pos-y (player-pos p)) dy))
;return this list
(list (+ (pos-x (player-pos p)) dx)
(+ (pos-y (player-pos p)) dy))
)
;else
(list (pos-x (player-pos p))
(pos-y (player-pos p)))))
(defun can-share (cell)
(every #'(lambda (n) (object-can-share n)) cell))