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}muevenaves();DrawScene(screen);// ¿vida extra?if (score % 2000 == 0 && score > 0) {score+=10;jugador.vidas++;}// <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] && jugador.activo!=0) {creadisparo();}while (<strong>SDL</strong>_PollEvent(&event)) {}// evento <strong>de</strong>l boton <strong>de</strong>l joystickif (event.type ==<strong>SDL</strong>_JOYBUTTONDOWN && jugador.activo != 0) {creadisparo();}// evento <strong>de</strong> cierre <strong>de</strong>l programaif (event.type == <strong>SDL</strong>_QUIT) {done=0;}// evento pulsación <strong>de</strong> teclaif (event.type == <strong>SDL</strong>_KEYDOWN) {}if (event.key.keysym.sym == <strong>SDL</strong>K_ESCAPE) {estado=0;}// Esperamos a que transcurran al menos 30 ms para// generar el siguiente frame, y evitar así// que el juego se acelere en máquinas muy rápidas.do {frametime=CurrentTime();} while (frametime

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

Saved successfully!

Ooh no, something went wrong!