(defun make-resource-font (&key filename encoding)
`(:type font :filename ,filename :enconding ,encoding))
+(defun make-resource-sound (&key filename)
+ `(:type sound :filename ,filename))
+
(defmacro get-rtime (key)
`(resource-time (gethash ,key resources-table)))
:static static)
key)))))))
-(defun draw-image-function (filename)
+(defun draw-image (filename &ptional (zoom 1))
(let ((texture (load-texture filename)))
- (lambda (&optional (f 1))
- (cond (texture
- (let ((width (getf (get-resource texture) :width))
- (height (getf (get-resource texture) :height)))
- (draw-rectangle (* f width) (* f height) :texture texture)))))))
+ (cond (texture (draw-texture texture zoom)))))
+
+(defun draw-texture (texture &optional (zoom 1))
+ (cond (texture
+ (let ((width (getf (get-resource texture) :width))
+ (height (getf (get-resource texture) :height)))
+ (draw-rectangle (* zoom width) (* zoom height) :texture texture)))))
(defun draw-quad (v1 v2 v3 v4 &key texture)
(let ((id-texture (getf (get-resource texture) :id-texture)))
(in-package 'gacela :nicknames '(gg) :use '(lisp)))
+(defun load-sound (filename &key static)
+ (let ((key (make-resource-sound :filename filename)))
+ (cond ((get-resource key) key)
+ (t (true-load-sound filename static)))))
+
+(defun true-load-sound (filename static)
+ (init-audio)
+ (let ((key (make-resource-sound :filename filename))
+ (sound (Mix_LoadWAV filename)))
+ (cond ((/= sound 0)
+ (set-resource key
+ `(:id-sound ,sound)
+ (lambda () (true-load-sound filename static))
+ (lambda () (Mix_FreeChunk sound))
+ :static static)
+ key))))
+
(next (random-tetramine))
(timer (make-timer))
(grid (make-list 20 :initial-element (make-list 14)))
- (background (draw-image-function "fondo_tetris.png"))
-; (background (draw-image-function "../../nehe/lesson06/data/nehe.bmp"))
+ (background (load-texture "fondo_tetris.png"))
+; (background (load-texture "../../nehe/lesson06/data/nehe.bmp"))
(font (load-font "lazy.ttf" :size 20))
(game-over))
(cond ((collide-grids tetramine grid x y) (setq game-over t)))
(setq next (random-tetramine)))
(t (incf y) (start-timer timer)))))
- (funcall background)
+ (draw-texture background)
(translate -288 218)
(draw-grid (join-grids tetramine grid x y))
(translate 440 440)