10.07.2015 Views

[ebook]Programacion de videojuegos con SDL

[ebook]Programacion de videojuegos con SDL

[ebook]Programacion de videojuegos con SDL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

P R O G R A M A C I Ó N D E V I D E O J U E G O S C O N S D L/***************************************************************************Ejemplo4_4(C) 2003 by Alberto Garcia SerranoProgramación <strong>de</strong> vi<strong>de</strong>ojuegos <strong>con</strong> <strong>SDL</strong>***************************************************************************/#inclu<strong>de</strong> #inclu<strong>de</strong> #inclu<strong>de</strong> #inclu<strong>de</strong> "<strong>SDL</strong>_mixer.h"int main(int argc, char *argv[]) {<strong>SDL</strong>_Surface *screen;<strong>SDL</strong>_Event event;Mix_Music *musica;int done = 0;int canal;atexit(<strong>SDL</strong>_Quit);// Iniciar <strong>SDL</strong>if (<strong>SDL</strong>_Init(<strong>SDL</strong>_INIT_VIDEO|<strong>SDL</strong>_INIT_AUDIO) < 0) {printf("No se pudo iniciar <strong>SDL</strong>: %s\n",<strong>SDL</strong>_GetError());exit(1);}// Activamos modo <strong>de</strong> vi<strong>de</strong>oscreen = <strong>SDL</strong>_SetVi<strong>de</strong>oMo<strong>de</strong>(640,480,24,<strong>SDL</strong>_HWSURFACE);if (screen == NULL) {printf("No se pue<strong>de</strong> inicializar el modo gráfico: %s \n",<strong>SDL</strong>_GetError());exit(1);}// Inicializamos <strong>SDL</strong>_mixerif(Mix_OpenAudio(22050, AUDIO_S16, 2, 4096)) {printf("No se pue<strong>de</strong> inicializar <strong>SDL</strong>_mixer %s\n",Mix_GetError());exit(1);}atexit(Mix_CloseAudio);// Cargamos la músicamusica = Mix_LoadMUS("musica.mid");if ( musica == NULL ) {printf("No pu<strong>de</strong> cargar musica: %s\n", Mix_GetError());exit(1);}// Reproducción la música.// Esta función <strong>de</strong>vuelve el canal por el que se reproduce la músicacanal = Mix_PlayMusic(musica, -1);// Esperamos la pulsación <strong>de</strong> una tecla para salirwhile(done == 0) {while ( <strong>SDL</strong>_PollEvent(&event) ) {if ( event.type == <strong>SDL</strong>_KEYDOWN )done = 1;}}// paramos la músicaMix_HaltMusic();// liberamos recursosMix_FreeMusic(musica);}return 0;75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!