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

`(kakko ,man)

Find a guide into tomorrow by taking lessons from the past

Lisp Game Programming <Step13>

step13は難易度を上げるステージの設定

;; Step13 <Stage Class>
;; -----------------------------------------------------------------------------------------------
(defclass stage ()
  ((%stage-flag :initarg :stage-flag :initform t :accessor stage-flag)
   (%stage-number :initarg :stage-number :initform 0 :accessor stage-number))
  (:documentation "The Stage Class"))

;; Step13 <Start Stage Message>
;; -----------------------------------------------------------------------------------------------
(defgeneric Stage-start-message (stage timing foe))

(defmethod Stage-start-message (stage timing foe) ; stage start message

  "Draw stage start message and set game parameters"
  (when (eql (stage-flag stage) t)
    (stop-sound) ; BGM stop
    (setf (stage-flag stage) nil)
    (incf (stage-number stage) 1)
    (sdl:clear-display sdl:*black*)
    (sdl:draw-string-solid-*
    (format nil "STAGE ~d" (stage-number stage)) 296 232 :color sdl:*white* :font *menu-font*)
    (sdl:update-display)
    (sleep 3)
    (Play-music *bg-music*) ; BGM start
    (setf (scroll timing) 0
    (enemy-list foe) nil
    (enemy-shot-list foe) nil)))

 

enemyの出現タイミングが変化する度にstageを変更するため、step4も変更する

;; Step 4 <Scroll Counter> <--------- step 13 correct
;; -----------------------------------------------------------------------------------------------
(defgeneric Scroll-counter (stage timing))

(defmethod Scroll-counter (stage timing)
(incf (scroll timing))
(when (= (scroll timing) 3072) ; mapchip 96 pieces move
   (when (> (interval timing) 32)
      (decf (interval timing) 32))
      (setf (stage-flag stage) t))) ; step 13 add sentence

 

メインルーチンの変更点

(let ((ship (make-instance 'entity :imageid 0 :id 0 :x 224 :y 416 :width 32 :height 32 :dx 4 :dy 4 :state 1))のプログラムに

(stage (make-instance 'stage))) ; step13 add sentenceを追加

 (:idle ()
; Game body のループに

; step 13
(Stage-start-message stage timing foe)を追加

f:id:tomekame0126:20140801171439p:plain