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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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_1(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 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 don<strong>de</strong> dibujaremos el gráfico// y lo copiamos a la pantalla.<strong>de</strong>st.x = 100;<strong>de</strong>st.y = 100;<strong>de</strong>st.w = image->w;<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;29

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

Saved successfully!

Ooh no, something went wrong!