Works again.
[uxul-world.git] / small-classes.lisp
1 ;;; Copyright 2009-2011 Christoph Senjak
2
3 (in-package :uxul-world)
4
5 (defclass anchor (game-object)
6   ((dungeon :initform nil
7             :initarg :dungeon
8             :accessor dungeon))
9    (:documentation "This object ist just to make it easier to handle
10    positions in the game, i.e. for bounding-rects for
11    burning-marshmallows, etc."))
12
13 (defclass leaf (bottom)
14   ((animation :initarg :animation
15               :accessor animation
16               :initform (make-animation 0 |leaf|))
17    (width :initarg :width
18           :accessor :width
19           :initform 128)
20    (height :initarg :height
21            :accessor :height
22            :initform 3)
23    (animation-translation :initarg :animation-translation
24                           :accessor animation-translation
25                           :initform (make-xy -7 -30))
26    ))
27
28 (defclass tulip (standing-item)
29   ((animation :initarg :animation
30               :accessor animation
31               :initform (make-animation 10 |tulip| |tulip2| |tulip| |tulip3|))
32    (width :initarg :width
33           :accessor :width
34           :initform 128)
35    (height :initarg :height
36            :accessor :height
37            :initform 128)))
38
39 (defclass key (standing-item)
40   ((animation :initarg :animation
41               :accessor animation
42               :initform (make-animation 0 |key|))
43    (width :initarg :width
44           :accessor width
45           :initform 128)
46    (height :initarg :height
47            :accessor height
48            :initform 128)
49    (dungeon :initarg :dungeon
50             :accessor dungeon
51             :initform nil
52             :documentation "To provide information in which rooms this key can be used.")))
53
54 (defclass door (stone)
55   ((animation :initarg :animation
56               :accessor animation
57               :initform (make-animation 0 |door|))
58    (width :initarg :width
59           :accessor width
60           :initform 128)
61    (height :initarg :height
62            :accessor height
63            :initform 128)
64    (dungeon :initarg :dungeon
65             :accessor dungeon
66             :initform nil
67             :documentation "To provide information in which room this door is.")))
68
69 (defclass teleporter (game-object-with-animation)
70   ((animation :initarg :animation
71               :accessor :animation
72               :initform (make-animation 0 |teleporter|))
73    (width :initarg :width
74           :accessor width
75           :initform 128)
76    (height :initarg :height
77            :accessor height
78            :initform 128)
79    (next-room-function :initarg :next-room-function
80                        :accessor next-room-function
81                        :initform (lambda () *current-room*))))
82
83 (defmethod invoke ((obj teleporter))
84   (let
85       ((player (car (get-objects *current-room* 'player))))
86     (cond
87       ((rectangles-overlap (x obj) (y obj)
88                            (+ (x obj) (width obj))
89                            (+ (y obj) (height obj))
90                            (x player) (y player)
91                            (+ (x player) (width player))
92                            (+ (y player) (height player)))
93        (if (key-pressed-up player)
94            ;; change the room
95            (setf *current-room* (funcall (next-room-function obj)))))
96       (T (setf (active obj) nil)))))