`(kakko ,man)

Find a guide into tomorrow by taking lessons from the past

Lisp Game Programming <Step14>

Step14はオープニングメッセージの表示

;; Step14 <Start Game Message>
;; -----------------------------------------------------------------------------------------------
(defgeneric Game-start-message (pointer stage keystate))

(defmethod Game-start-message (pointer stage keystate) ; game start message
  "Draw game opening message"
  (sdl:draw-string-solid-* "THE SHOOTER" 80 128 :color sdl:*cyan* :font *title-font*)
  (sdl:draw-string-solid-* "START" 288 320 :color sdl:*white* :font *menu-font*)
  (sdl:draw-string-solid-* "EXIT" 288 352 :color sdl:*white* :font *menu-font* )
  (cond ((up keystate)
               (decf (y pointer) 32)
               (setf (start stage) t)
               (when (< (y pointer) 320) ; y:320 is START position
                 (setf (y pointer) 320)))
             ((down keystate)
                (incf (y pointer) 32)
                (setf (start stage) nil)
      (when (> (y pointer) 352) ; y:352 is EXIT position
        (setf (y pointer) 352))))
  (Draw pointer)
  (sdl:update-display)
  (cond ((and (z keystate) (eql (start stage) t)) ; start position
               (setf (title-loop stage) nil)
               (setf (z keystate) nil)) ; z key state reset
             ((and (z keystate) (eql (start stage) nil)) ; exit position
               (sdl:push-quit-event))))

step13を以下に変更

;; Step13 <Stage Class> <----------- step 14 correct
;; -----------------------------------------------------------------------------------------------
(defclass stage ()
 ((%stage-flag :initarg :stage-flage :initform t :accessor stage-flag)
  (%stage-number :initarg :stage-number :initform 0 :accessor stage-number)
  (%title-loop :initarg :title-loop :initform t :accessor title-loop)
  (%start :initarg :start :initform t :accessor start))
 (:documentation "The Stage Class"))

 step11を以下に変更

;; Step11 <Game Over Message> <------ step 14 correct
;; -----------------------------------------------------------------------------------------------
(defgeneric Game-over-message (score stage timing ship foe))

(defmethod Game-over-message (score stage timing ship foe) ; message Draw
  "Draw game over message"
  (when (= (n-ship score) 0)
    (stop-sound) ; BGM stop
    (sdl:draw-string-solid-* "GAME OVER" 208 232 :color sdl:*white* :font *menu-font*)
    (sdl:update-display)
    (sleep 5)
    (setf (title-loop stage) t
            (stage-flag stage) t
            (stage-number stage) 0
            (score score) 0
          ; (highscore score) 5000
            (n-ship score) 3
           (interval timing) 128
           (state ship) 1
           (x ship) ( (- *graphic-width* 32) 2)
           (y ship) (- *graphic-height* 64)
           (enemy-list foe) nil
           (enemy-shot-list foe) nil)))

メインルーチン

let文に追加

(pointer (make-instance 'object :imageid 2 :id 0 :x 272 :y 320))) ; step 14 add sentence

:Game bodyに以下を追加

; step 14
(when (eql (title-loop stage) t) ; title loop
  (sdl:clear-display sdl:*black*)
  (Game-start-message pointer stage keystate))

; step 14
(when (eql (title-loop stage) nil) ; game loop
  (sdl:clear-display sdl:*black*)

f:id:tomekame0126:20140809110723p:plain