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

`(kakko ,man)

Find a guide into tomorrow by taking lessons from the past

Lisp Game Programming <Step10-3>

3番目はenemy-shotのstateが0(dead)になったものをenemy-shot-listからdeleteするプログラム

;; Step10 <Remove Dead Enemy Shot>
;; -----------------------------------------------------------------------------------------------
(defgeneric Remove-dead-enemy-shot (foe))

(defmethod Remove-dead-enemy-shot (foe)
  "dead enemy shot remove from list"
  (setf (enemy-shot-list foe)
    (delete-if #'(lambda (enemy-shot) (= (state enemy-shot) 0)) (enemy-shot-list foe))))

 

メインルーチンは以下

(defun Common-shooter ()
  "main routine"
  (sdl:with-init (sdl:sdl-init-video sdl:sdl-init-audio) ; use video and audio
  (sdl:window 640 480 :position #(192 50) ; size 640*480, position x(192) y(50)
                                    :title-caption "THE SHOOTER"
                                    :icon-caption "THE SHOOTER"
                                    :double-buffer T)
                                  ; :fullscreen T)
  ; step 3
  (Initialize) ; graphics initialize
  ; step 5
  (Set-font) ; set font
  ; step 2
  (Open-sound) ; open audio and load sound data
  ; step 2
  (Play-music *bg-music*) ; play music
  ; step 3 - 9
  (let((ship (make-instance 'entity :imageid 0 :id 0 :x 224 :y 416 :width 32 :height 32 :dx 4 :dy 4 :state 1))
        (mapchip (make-instance 'object :imageid 1 :id 0))
        (timing (make-instance 'timing)) ; step4 add sentence
        (score-ship (make-instance 'object :imageid 0 :id 0 :x 496 :y 128)) ;step5 add sentence
        (score (make-instance 'score)) ; step5 add sentence
        (keystate (make-instance 'keystate)) ; step6 add sentence
        (game-field (make-instance 'game-field)) ; step7 add sentence
        (shot (make-instance 'entity :imageid 0 :height 32 :dy 16 :id 1 :state 0)) ; step8 add sentence
        (foe (make-instance 'foe))) ; step9 add sentence

  (sdl:update-display)
  (sdl:with-events (:poll)
    (:quit-event ()
    ; step 2
    (Stop-sound) ; sample and music stop
    (Close-sound) ; close audio
      t)
    ; step 6
    (:key-down-event (:key key)
      (if (sdl:key= key :SDL-KEY-ESCAPE)
          (sdl:push-quit-event)
      (Update-keystate key t keystate)))
    (:key-up-event (:key key)
      (Update-keystate key nil keystate))

    (:idle ()
      ; Game body
  
   ; step 6
      (Move-ship ship keystate)
      ; step 7
      (Fix-ship-position ship game-field)
      ; step 8
      (Move-shot shot)
      (Set-shot shot ship keystate)
      ; step 4
      (Scroll-background mapchip timing) ; scroll background
  
   ; step 3
      (when (= (state ship) 1)
        (Draw ship)) ; draw ship
  
   ; step 8
      (when (= (state shot) 1)
        (Draw shot)) ; draw shot

      ; step 9
      (Move-enemy ship foe)
      (Set-enemy timing foe)
      (dolist (enemy (enemy-list foe))
        (when (= (state enemy) 1)
          (Draw enemy))) ; draw enemy
      (Remove-dead-enemy foe)
      ; step 10
      (Move-enemy-shot foe)
      (Set-enemy-shot foe)
      (dolist (enemy-shot (enemy-shot-list foe))
      (when (= (state enemy-shot) 1)
        (Draw enemy-shot))) ; draw enemy shot
      (Remove-dead-enemy-shot foe)
      ; step 5
      (Score-panel score score-ship) ; draw score panel
      ; step 4

      (Scroll-counter timing)

(sdl:update-display))))))

f:id:tomekame0126:20140714035604p:plain