`(kakko ,man)

Find a guide into tomorrow by taking lessons from the past

Lisp Game Programming <Step5-2>

ゲームのスコアを表示させるパネルをウィンドウの右側に配置

追加するプログラムは以下

;; step5 <Score panel>
;; -----------------------------------------------------------------------------------------------
(defvar *score* 0) ; score
(defvar *highscore* 5000) ; highscore
(defvar *n-ship* 3) ; ship counter

(defun Score-panel (obj) ; score panel message
  "draw score and ships of rest"
  (sdl:draw-box-* 480 0 160 480 :color (sdl:color :r 64 :g 64 :b 64))
  (sdl:draw-string-solid-* (format nil "SCORE:") 496 32 :color sdl:*white* :font *menu-font*)
  (sdl:draw-string-solid-* (format nil "HIGH-SCORE:") 496 72 :color sdl:*white* :font *menu-font*)
  (sdl:draw-string-solid-* (format nil "~7,'0d" *score*) 512 52 :color sdl:*white* :font *menu-font*)
  (sdl:draw-string-solid-* (format nil "~7,'0d" *highscore*) 512 92 :color sdl:*white* :font *menu-font*)
  (dotimes (i (- *n-ship* 1))
    (setf (x obj) (+ 496 (* 40 i)))
    (Draw obj)))

メインルーチンは以下

(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 - 5
  (let ((ship (make-instance 'entity :imageid 0 :id 0 :x 224 :y 416
                                                     :width 32 :height 32 :dx 4 :dy 4 :state 1))
        (score-ship (make-instance 'object :imageid 0 :id 0 :x 496 :y 128))
        (mapchip (make-instance 'object :imageid 1 :id 0)))

  (sdl:update-display)
  (sdl:with-events (:poll)
  (:quit-event ()
  ; step 2
    (Stop-sound) ; sample and music stop
    (Close-sound) ; close audio
      t)

    (:idle ()
    ; Game body
    ; step 4

    (Scroll mapchip) ; scroll background
    ; step 3
    (when (= (state ship) 1)
      (Draw ship)) ; draw ship
    ; step 
 
   (Score-panel score-ship) ; draw score panel

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

 こんな感じでスコアパネルを右側に表示できた

f:id:tomekame0126:20140705022322p:plain