forked from Shirakumo/kandria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedium.lisp
38 lines (28 loc) · 852 Bytes
/
medium.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
(in-package #:org.shirakumo.fraf.kandria)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defclass medium ()
())
(defgeneric gravity (medium))
(defgeneric drag (medium))
(defgeneric submerged (thing medium))
(defmethod (setf medium) :around (new object)
(let ((old (medium object)))
(unless (eq new old)
(leave object old)
(call-next-method)
(enter object new))
new))
(defmethod submerged ((entity entity) (medium medium)))
(defmethod enter (object (medium medium)))
(defmethod leave (object (medium medium)))
(defclass air (medium)
())
(defmethod drag ((air air))
1.0)
(defmethod gravity ((air air))
(vec 0 -15))
(defclass vacuum (air)
())
(defmethod gravity ((vacuum vacuum))
(vec 0 0)))
(define-global +default-medium+ (make-instance 'air))