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/***************************************************************************Ejemplo5_1(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> "csprite.h"<strong>SDL</strong>_Surface *screen;CFrame fnave;CFrame fmalo;CSprite nave(1);CSprite malo(1);<strong>SDL</strong>_Rect rectangulo;<strong>SDL</strong>_Joystick *joystick;int joyx, joyy;int done=0;// estructura que <strong>con</strong>tiene la información// <strong>de</strong> nuestro aviónstruct minave {int x,y;} jugador;// Estructura que <strong>con</strong>tiene información// <strong>de</strong>l avión enemigostruct naveenemiga {int x,y;} enemigo;// Dibuja los esprites en la pantallavoid DrawScene(<strong>SDL</strong>_Surface *screen) {// borramos el avión dibujado// en el frame anteriorrectangulo.x=nave.getx();rectangulo.y=nave.gety();rectangulo.w=nave.getw();rectangulo.h=nave.geth();<strong>SDL</strong>_FillRect(screen,&rectangulo,<strong>SDL</strong>_MapRGB(screen->format,0,0,0));// dibuja aviónnave.setx(jugador.x);nave.sety(jugador.y);nave.draw(screen);// Dibuja enemigomalo.setx(enemigo.x);malo.sety(enemigo.y);malo.draw(screen);// ¿ha colisionado <strong>con</strong> la nave?if (malo.colision(nave) == TRUE) {done=1;}}// Mostramos todo el frame<strong>SDL</strong>_Flip(screen);// Inicializamos estadosvoid inicializa() {jugador.x=300;jugador.y=300;enemigo.x=100;enemigo.y=100;}void finaliza() {87

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

Saved successfully!

Ooh no, something went wrong!