読者です 読者をやめる 読者になる 読者になる

`(kakko ,man)

Find a guide into tomorrow by taking lessons from the past

Lisp Game Programming <Step9-1>

最初はクラスfoeを作成し、enemyの移動と種類による移動方向の設定をプログラム

id2=enemy1、id3=enemy2、id4=enemy3

enemy1は下降した着地点がshipより右であれば左にー2、左であれば右に2上昇しながら移動するようにdx、dyを設定

enemy1、2、3、は画面の外にでたらstateを0に設定

;; step9 <Move Enemy>
;; -----------------------------------------------------------------------------------------------
(defparameter *graphic-height* 480)
(defparameter *graphic-width* 480)

(defclass foe ()
  ((%enemy-list :initarg :enemy-list :initform nil :accessor enemy-list)
   (%enemy-shot-list :initarg :enemy-shot-list :initform nil :accessor enemy-shot-list))
  (:documentation "The foe Class"))

(defgeneric Move-enemy (ship foe))

(defmethod Move-enemy (ship foe)
  (dolist (enemy (enemy-list foe))
    (when (= (state enemy) 1)
      (incf (x enemy) (dx enemy))
      (incf (y enemy) (dy enemy))
      (incf (move-cnt enemy) 1)
        (ecase (id enemy)
          (2 (progn ; enemy type1
            (when (> (y enemy) (- *graphic-height* 32))
              (if (> (x enemy) (x ship))
                (setf (dx enemy) -2)
                (setf (dx enemy) 2))
                (setf (dy enemy) -2))
            (when (or (< (x enemy) -32)
                            (> (x enemy) *graphic-width*))
              (setf (state enemy) 0))))
          (3 (progn ; enemy type2
            (when (or (< (x enemy) -32)
                            (> (x enemy) *graphic-width*))
              (setf (state enemy) 0))))
          (4 (progn ; enemy type3
            (when (and (< (x enemy) -32)
                       (= (dx enemy) -3))
              (setf (state enemy) 0))
            (when (and (> (x enemy) *graphic-width*)
                               (= (dx enemy) 3))
(setf (state enemy) 0))))))))