1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (eval-when (compile load eval)
19 (when (not (find-package 'gacela)) (make-package 'gacela :nicknames '(gg) :use '(lisp)))
20 (in-package 'gacela :nicknames '(gg) :use '(lisp)))
25 (defun load-sound (filename &key static)
26 (let ((key (make-resource-sound :filename filename)))
27 (cond ((get-resource key) key)
28 (t (true-load-sound filename static)))))
30 (defun true-load-sound (filename static)
32 (let ((key (make-resource-sound :filename filename))
33 (sound (Mix_LoadWAV filename)))
37 (lambda () (true-load-sound filename static))
38 (lambda () (Mix_FreeChunk sound))
42 (defun play-sound (sound &optional (loops 0))
43 (let ((id-sound (getf (get-resource sound) :id-sound)))
44 (/= (Mix_PlayChannel -1 id-sound loops) -1)))
49 (defun load-music (filename &key static)
50 (let ((key (make-resource-music :filename filename)))
51 (cond ((get-resource key) key)
52 (t (true-load-music filename static)))))
54 (defun true-load-music (filename static)
56 (let ((key (make-resource-music :filename filename))
57 (music (Mix_LoadMUS filename)))
61 (lambda () (true-load-music filename static))
62 (lambda () (Mix_FreeMusic music))
66 (defun playing-music? ()
67 (/= (Mix_PlayingMusic) 0))
69 (defun paused-music? ()
70 (/= (Mix_PausedMusic) 0))
72 (defun play-music (music &optional (loops -1))
73 (cond ((not (playing-music?))
74 (let ((id-music (getf (get-resource music) :id-music)))
75 (/= (Mix_PlayMusic id-music loops) -1)))))
78 (cond ((and (playing-music?) (not (paused-music?)))
82 (defun resume-music ()
83 (cond ((and (playing-music?) (paused-music?))
88 (cond ((playing-music?)