Works again.
[uxul-world.git] / simple-enemy.lisp
1 ;;; Copyright 2009-2011 Christoph Senjak
2
3 (in-package :uxul-world)
4
5 (defclass simple-enemy (moving-enemy)
6   ((animation :initarg :animation
7               :initform
8               (make-animation 3 |nasobem| |nasobem2|)
9               :accessor animation)
10    (animation-translation :accessor animation-translation
11                           :initarg :animation-translation
12                           :initform (make-xy -100 -50))
13    (flat-animation :accessor flat-animation
14                    :initform (make-animation 0 |nasobem3|))
15    (dont-ignore :accessor dont-ignore :initform t)
16    (activated :accessor activated :initform nil)
17    (width :initarg :width :initform 64 :accessor width)
18    (active :initarg :active :initform t :accessor active)
19    (height :initarg :height :initform 64 :accessor height)
20    (direction :initarg :direction :initform :left :accessor direction)))
21
22 (defmethod invoke ((obj simple-enemy))
23   "Move the object down-left if direction is :left"
24   (cond
25     ((activated obj) (move-about obj (make-xy
26                                       (if (eql (direction obj) :left)
27                                           -10
28                                           10) 10)))
29     (T
30      (dolist (player (get-objects *current-room* 'player))
31        (if (and
32             (< (abs (- (x player) (x obj))) (+ +screen-width+ 300))
33             (< (abs (- (y player) (y obj))) (+ +screen-height+ 300)))
34            (setf (activated obj) T))))))
35
36 (defun simple-enemy-and-player (player enemy)
37   (decf (power player)))
38
39 (defmethod player-hits-enemy ((player player) (enemy simple-enemy) &rest args)
40   (cond
41     ((eql (direction (car args)) :DOWN)
42      (setf (animation enemy) (flat-animation enemy))
43      (setf (active enemy) nil)
44      (setf (colliding enemy) nil)
45      (setf (listen-to player) (remove enemy (listen-to player))))
46     (T
47      (simple-enemy-and-player player enemy))))
48
49 (defmethod enemy-hits-player ((enemy simple-enemy) (player player) &rest args)
50     (declare (ignore args))
51     (simple-enemy-and-player player enemy))