From: Christoph Senjak Date: Thu, 20 Aug 2009 14:07:53 +0000 (+0200) Subject: added doors and keys. X-Git-Url: http://uxul.de/gitweb/?a=commitdiff_plain;h=75a52aa3b1969c6e02e417f90dada2db744a1c37;p=uxul-world.git added doors and keys. --- diff --git a/door.png b/door.png new file mode 100644 index 0000000..cc4f01a Binary files /dev/null and b/door.png differ diff --git a/on-collision.lisp b/on-collision.lisp index 9f9f329..8fbaf2a 100755 --- a/on-collision.lisp +++ b/on-collision.lisp @@ -24,6 +24,25 @@ ) (collide-blocks moving-rectangle standing-rectangle collision)) +(defmethod on-collision + ((moving-rectangle player) + (standing-rectangle door) + (collision collision)) + + (cond ((find (dungeon standing-rectangle) (keys moving-rectangle)) + (setf (keys moving-rectangle) (delete (dungeon standing-rectangle) (keys moving-rectangle) :count 1)) + (setf (visible standing-rectangle) nil) + (setf (active standing-rectangle) nil) + (setf (colliding standing-rectangle) nil)) + ((eql (direction collision) :DOWN) + ;; "bottom" - allow jumping again + (setf (mayjump moving-rectangle) T)) + ;; "ceiling" - dont allow continuing jump + ((eql (direction collision) :UP) + (setf (maycontjump moving-rectangle) nil))) + (collide-blocks moving-rectangle standing-rectangle collision)) + + (defmethod on-collision ((moving-rectangle player) (standing-rectangle tulip) diff --git a/player.lisp b/player.lisp index bbfb7d1..9e56626 100755 --- a/player.lisp +++ b/player.lisp @@ -75,10 +75,12 @@ :documentation "after hit by an enemy you wont be wounded by another enemy for that ammount of frames.") - (keys :initform 0 + (keys :initform nil + :initarg :keys :accessor keys - :documentation "Number of keys for doors") - )) + :documentation "List of Key-Dungeons of keys (i.e. for every + key its key-dungeon is pushed on that list, for every door, its + removed again).") )) ;; Interaction with enemies @@ -118,6 +120,12 @@ (class-name (class-of item)) (class-name (class-of player)))) +(defmethod item-catch ((item key) (player player) &rest args) + (declare (ignore args)) + (push (dungeon item) (keys player)) + (setf (visible item) nil) + (setf (colliding item) nil)) + (defmethod (setf animation) ((new-value animation) (object player)) (setf (x new-value) (+ (x object) (x(animation-translation object)))) (setf (y new-value) (+ (y object) (y(animation-translation object)))) diff --git a/small-classes.lisp b/small-classes.lisp index a78c607..6470951 100755 --- a/small-classes.lisp +++ b/small-classes.lisp @@ -26,4 +26,34 @@ :initform 128) (height :initarg :height :accessor :height - :initform 128))) \ No newline at end of file + :initform 128))) + +(defclass key (standing-item) + ((animation :initarg :animation + :accessor animation + :initform (make-animation 0 |key|)) + (width :initarg :width + :accessor width + :initform 128) + (height :initarg :height + :accessor height + :initform 128) + (dungeon :initarg :dungeon + :accessor dungeon + :initform nil + :documentation "To provide information in which rooms this key can be used."))) + +(defclass door (stone) + ((animation :initarg :animation + :accessor animation + :initform (make-animation 0 |door|)) + (width :initarg :width + :accessor width + :initform 128) + (height :initarg :height + :accessor height + :initform 128) + (dungeon :initarg :dungeon + :accessor dungeon + :initform nil + :documentation "To provide information in which room this door is."))) \ No newline at end of file diff --git a/testing-room.lisp b/testing-room.lisp index b9e4649..a65e9db 100755 --- a/testing-room.lisp +++ b/testing-room.lisp @@ -38,6 +38,14 @@ level-editor instead!" :visible t :redraw t) ret) +;;*************************** + (add-object (make-instance 'key + :x (* 128 56) + :y (* 128 8) + :dungeon :testing-room + :visible t + :redraw t) ret) + (add-object (make-instance 'burning-marshmallow :x (* 128 60) @@ -282,6 +290,20 @@ level-editor instead!" (add-object (make-instance 'flying-nasobem :x (* 128 87) :y (* 128 2)) ret) + ;;******************************* + (add-object (make-instance 'door + :x (* 128 87) + :y (* 128 1) + :dungeon :testing-room + :visible t + :redraw t) ret) + (add-object (make-instance 'door + :x (* 128 89) + :y (* 128 1) + :dungeon :testing-room + :visible t + :redraw t) ret) + (add-object (make-instance 'flying-nasobem :x (* 128 110) :y (* 128 4)) ret)