1 ;;; Copyright 2009 Christoph Senjak
3 (in-package :uxul-world)
5 ;; as many game-objects do have an animation related to them, instead
6 ;; of just having a draw-method which will manually draw anything, we
7 ;; declare a standard-class for that, with some useful methods.
9 (defclass game-object-with-animation (game-object)
10 ((animation-translation :initarg :animation-translation
11 :accessor animation-translation
12 :initform (make-xy 0 0)
13 :documentation "The translation of the animation")
14 (animation :initarg :animation
16 :documentation "The animation of this object")))
18 (defmethod (setf animation) ((newval animation) (obj game-object-with-animation))
19 "Sets the animation and x and y-coordinates. Wont rewind the animation."
20 (setf (slot-value obj 'animation) newval)
21 (setf (x obj) (x obj))
22 (setf (y obj) (y obj))
23 (setf (visible obj) (visible obj)))
25 (defmethod (setf x) (newval (obj game-object-with-animation))
27 (setf (x (animation obj)) (+ (x obj) (x (animation-translation obj)))))
29 (defmethod (setf y) (newval (obj game-object-with-animation))
31 (setf (y (animation obj)) (+ (y obj) (y (animation-translation obj)))))
33 (defmethod (setf visible) (newval (obj game-object-with-animation))
35 (setf (visible (animation obj)) newval))
37 (defun rectangle-in-screen (obj)
42 (+ (x obj) (width obj) 50)
43 (+ (y obj) (height obj) 50)
44 *current-translation-x*
45 *current-translation-y*
46 (- +screen-width+ *current-translation-x*)
47 (- +screen-height+ *current-translation-y*)))
51 (defmethod draw ((obj game-object-with-animation))
52 ;(if (rectangle-in-screen obj)
53 (draw (animation obj))
57 (defmethod shared-initialize :after ((instance game-object-with-animation) spam &rest
58 initargs &key &allow-other-keys)
59 (declare (ignore initargs))
60 (declare (ignore spam))
61 "Set the x and y-Coordinates in the drawable and the rectangle (this
62 had to be done by hand before)"
63 ; (write (x instance))
64 ; (write (y instance))
65 (setf (x instance) (x instance))
66 (setf (y instance) (y instance))
67 (setf (visible instance) (visible instance)))