From 5d4256607358f78f54bb6958e572ef028d2e1c59 Mon Sep 17 00:00:00 2001 From: jsancho Date: Mon, 25 Oct 2010 23:43:42 +0000 Subject: [PATCH] --- gacela.lisp | 3 +++ gacela_draw.lisp | 14 ++++++++------ gacela_sound.lisp | 17 +++++++++++++++++ gacela_tetris.lisp | 6 +++--- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/gacela.lisp b/gacela.lisp index 31fe8ab..f174a48 100644 --- a/gacela.lisp +++ b/gacela.lisp @@ -154,6 +154,9 @@ (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))) diff --git a/gacela_draw.lisp b/gacela_draw.lisp index 559412b..8cff747 100644 --- a/gacela_draw.lisp +++ b/gacela_draw.lisp @@ -112,13 +112,15 @@ :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))) diff --git a/gacela_sound.lisp b/gacela_sound.lisp index ae9b72b..e0cdf56 100644 --- a/gacela_sound.lisp +++ b/gacela_sound.lisp @@ -20,3 +20,20 @@ (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)))) + diff --git a/gacela_tetris.lisp b/gacela_tetris.lisp index 9d67a1d..5435e96 100644 --- a/gacela_tetris.lisp +++ b/gacela_tetris.lisp @@ -119,8 +119,8 @@ (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)) @@ -156,7 +156,7 @@ (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) -- 2.39.5