Lisp Game Programming <Step12-1>
step12の最初はEnemyにshotがhitしたかどうかを判断するプログラム
enemyのstateを2(explosion)、shotのstateを0(dead)、爆発カウンターを0にセットして起動し、scoreを+100して、もしhighscoreよりscoreが大きくなったら、highscoreにscoreをセット
;; Step12 <Judge Shot Hit>
;; -----------------------------------------------------------------------------------------------
(defgeneric Enemy-hit-p (shot score foe))
(defmethod Enemy-hit-p (shot score foe)
(when (= (state shot) 1) ; if shot state on
(dolist (enemy (enemy-list foe))
(when (and (= (state enemy) 1) ; if enemy is alive
(> (+ (x shot) 31) (x enemy))
(< (x shot) (+ (x enemy) 31))
(> (+ (y shot) 31) (y enemy))
(< (y shot) (+ (y enemy) 31)))
(setf (state enemy) 2 ; enemy explosion
(explode-cnt enemy) 0
(state shot) 0) ; set shot state off
(incf (score score) 100)))
(when (> (score score) (highscore score))
(setf (highscore score) (score score)))))