(defflavor moving-object ((x-position 0.0)
(y-position 0.0)
(x-velocity 4.0)
(y-velocity 3.0)
mass)
()
:gettable-instance-variables
:settable-instance-variables
:initable-instance-variables)
(defmethod (moving-object :speed) ()
(sqrt (+ (^ x-velocity 2)
(^ y-velocity 2))))
(defmethod (moving-object :direction) ()
(atan y-velocity x-velocity))
(defflavor ship (engine-power number-of-passengers name)
(moving-object)
:gettable-instance-variables)
(defflavor meteor (percent-iron)
(moving-object)
:initable-instance-variables)
(setq my-ship (make-instance 'ship 'mass 3.5))
(funcall my-ship ':set-x-position 3.0)
(funcall my-ship ':x-position)
==> 3.0
(funcall my-ship ':speed)
==> 5.0このページを編集 (2557 bytes)
| 以下の 2 ページから参照されています。 |
This page has been visited 4151 times.