Lisp Game Programming <Step3-1>
step3の最初はイメージデータの読み込みとID番号の付与
3つのイメージデータを読み込んでそのデータそれぞれにidを付与し、またそのデータの中のキャラクタ個々にもidを付与する
たとえば *image0* の中のキャラクタへidの付与は(0 0 32 32) ⇒ id 0, (32 0 32 32)⇒id 1, (64 0 32 32)⇒id 2, (96 0 32 32)⇒id 3, (128 0 32 32)⇒id 4 のようになるから、以下のようなidが各イメージデータに付与される
id 0-4 (0:ship,1:shot,2:enemy1,3:enemy2,4:enemy3) ⇒ *image0*
id 0-2 (0:mapchip,1:enemy-explosion,2:my-explosion) ⇒ *image1*
id 0-1 (0:pointer, 1:enemy-shot) ⇒ *image2*
color-key(sdl:color :r 0 :g 0 :b 0)は、イメージデータが重畳したときに透過する色として設定している
ここを参照
https://code.google.com/p/lispbuilder/wiki/UsingLispbuilderSDL#Sprite_Sheets
;; step3 <Sprite sheets>
;; -----------------------------------------------------------------------------------------------
(defparameter *path-size32* "C:\\work\\graphics\\size32.bmp") ; set path to size32.bmp
(defparameter *path-size64* "C:\\work\\graphics\\size64.bmp") ; set path to size64.bmp
(defparameter *path-size16* "C:\\work\\graphics\\size16.bmp") ; set path to size16.bmp
(defvar *image0*)
(defvar *image1*)
(defvar *image2*)
(defun Set-imageid ()
"load image data and set id"
(setf *image0* (sdl:load-image *path-size32* :color-key(sdl:color :r 0 :g 0 :b 0))
*image1* (sdl:load-image *path-size64* :color-key(sdl:color :r 0 :g 0 :b 0))
*image2* (sdl:load-image *path-size16* :color-key(sdl:color :r 0 :g 0 :b 0)))
(let ((temp0 (append (loop for x from 0 to 128 by 32
collect (list x 0 32 32))))
(temp1 (append (loop for x from 0 to 128 by 64
collect (list x 0 64 64))))
(temp2 (append (loop for x from 0 to 16 by 16
collect (list x 0 16 16)))))
(setf (sdl:cells *image0*) temp0 ; id 0-4 ship,shot,enemy1,enemy2,enemy3
(sdl:cells *image1*) temp1 ; id 0-2 mapchip,enemy-explosion,my-explosion
(sdl:cells *image2*) temp2))) ; id 0-1 pointer,enemy-shot