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/*******************************************Ejemplo3_2(C) 2003 by Alberto García 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> int main(int argc, char *argv[]) {<strong>SDL</strong>_Surface *image, *screen;<strong>SDL</strong>_Rect <strong>de</strong>st;<strong>SDL</strong>_Event event;int i, done = 0;atexit(<strong>SDL</strong>_Quit);// Iniciar <strong>SDL</strong>if (<strong>SDL</strong>_Init(<strong>SDL</strong>_INIT_VIDEO) < 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: \n",<strong>SDL</strong>_GetError());exit(1);}// Cargamos gráficoimage = <strong>SDL</strong>_LoadBMP("nave.bmp");if ( image == NULL ) {printf("No pu<strong>de</strong> cargar gráfico: %s\n", <strong>SDL</strong>_GetError());exit(1);}// Definimos color para la transparencia<strong>SDL</strong>_SetColorKey(image,<strong>SDL</strong>_SRCCOLORKEY|<strong>SDL</strong>_RLEACCEL,<strong>SDL</strong>_MapRGB(image->format,255,0,0));// Vamos a dibujar 100 graficosfor (i=1 ; iw;<strong>de</strong>st.h = image->h;<strong>SDL</strong>_BlitSurface(image, NULL, screen, &<strong>de</strong>st);// Mostramos la pantalla<strong>SDL</strong>_Flip(screen);// liberar superficie<strong>SDL</strong>_FreeSurface(image);// 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;}}}return 0;34

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

Saved successfully!

Ooh no, something went wrong!