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 Lint main(int argc, char *argv[]) {<strong>SDL</strong>_Event event;Uint8 *keys;if (<strong>SDL</strong>_Init(<strong>SDL</strong>_INIT_VIDEO|<strong>SDL</strong>_INIT_JOYSTICK) < 0) {printf("No se pudo iniciar <strong>SDL</strong>: %s\n",<strong>SDL</strong>_GetError());return 1;}screen = <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());return 1;}atexit(<strong>SDL</strong>_Quit);inicializa();InitSprites();while (done == 0) {// movemos el avión enemigamuevenave();// movemos los disparosmuevebalas();// dibujamos el frameDrawScene(screen);// <strong>con</strong>sultamos el estado <strong>de</strong>l tecladokeys=<strong>SDL</strong>_GetKeyState(NULL);// <strong>con</strong>sultamos el estado <strong>de</strong>l joystick<strong>SDL</strong>_JoystickUpdate();joyx = <strong>SDL</strong>_JoystickGetAxis(joystick, 0);joyy = <strong>SDL</strong>_JoystickGetAxis(joystick, 1);if ((keys[<strong>SDL</strong>K_UP] || joyy < -10) && (jugador.y > 0)) {jugador.y=jugador.y-(5);}if ((keys[<strong>SDL</strong>K_DOWN] || joyy > 10) && (jugador.y < 460)) {jugador.y=jugador.y+(5);}if ((keys[<strong>SDL</strong>K_LEFT] || joyx < -10) && (jugador.x > 0)) {jugador.x=jugador.x-(5);}if ((keys[<strong>SDL</strong>K_RIGHT] || joyx > 10) && (jugador.x < 620)) {jugador.x=jugador.x+(5);}if (keys[<strong>SDL</strong>K_LSHIFT]) {creadisparo();}while (<strong>SDL</strong>_PollEvent(&event)) {if (event.type == <strong>SDL</strong>_QUIT) {done=1;}if (event.type == <strong>SDL</strong>_KEYDOWN || event.type == <strong>SDL</strong>_JOYBUTTONDOWN) {}if (event.key.keysym.sym == <strong>SDL</strong>K_ESCAPE) {done=1;}}}finaliza();}return 0;116

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

Saved successfully!

Ooh no, something went wrong!