Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Pantalla.h"
- #include "time.h"
- #include "stdlib.h"
- #include "stdio.h"
- #include "Personaje.h"
- #include "Enemigo.h"
- int main(int argc, char **argv)
- {
- srand(time(NULL));
- Pantalla_Crea("Ejemplo3", 640, 480);
- int terminado=0;
- int tiempofinal;
- Imagen fondo =Pantalla_ImagenLee("fondo1.bmp", 1);
- while (Pantalla_Activa() && !terminado)
- {
- if (Pantalla_TeclaPulsada(SDL_SCANCODE_RETURN)) terminado=1;
- Pantalla_DibujaImagen(fondo, 0, 0, Pantalla_Anchura(), Pantalla_Altura());
- Pantalla_ColorTrazo(255,255,255,255);
- Pantalla_DibujaTexto("Pulsa RETURN para comenzar", 220, 200);
- Pantalla_Actualiza();
- Pantalla_Espera(40);
- }
- Pantalla_ImagenLibera(fondo);
- terminado=0;
- Imagen fondo2 =Pantalla_ImagenLee("grieta.bmp", 0);
- Imagen ei = Pantalla_ImagenLee("enemigonashor.bmp",255);
- int ew = 100;
- int eh = 100;
- int ex = rand()%(Pantalla_Anchura()-ew);
- int ey = 0;
- int evx = 20;
- int evy = 20;
- Enemigo e = EnemigoCrea(ei,ex,ey,ew,eh,evx,evy);
- Imagen pi = Pantalla_ImagenLee("personaje.bmp", 255);
- int pw = 100;
- int ph = 100;
- int px = rand()%(Pantalla_Anchura()-pw);
- int py = Pantalla_Altura()-ph;
- Personaje p = PersonajeCrea(pi,px,py,pw,ph);
- int tini=time(NULL);
- while (Pantalla_Activa() && !terminado)
- {
- if (Pantalla_TeclaPulsada(SDL_SCANCODE_ESCAPE)) terminado=1;
- if (Pantalla_TeclaPulsada(SDL_SCANCODE_LEFT)) PersonajeMueve(p,-20,0);
- if (Pantalla_TeclaPulsada(SDL_SCANCODE_RIGHT)) PersonajeMueve(p,20,0);
- if (Pantalla_TeclaPulsada(SDL_SCANCODE_UP)) PersonajeMueve(p,0,-20);
- if (Pantalla_TeclaPulsada(SDL_SCANCODE_DOWN)) PersonajeMueve(p,0,20);
- int tfin=time(NULL);
- int tiempo=tfin-tini;
- char texto[100];
- sprintf(texto,"Tiempo: %d",tiempo);
- tiempofinal=tiempo;
- Pantalla_DibujaImagen(fondo2,0,0,Pantalla_Anchura(),Pantalla_Altura());
- Pantalla_ColorTrazo(255,255,255,255);
- Pantalla_DibujaTexto("Pulsa ESCAPE para continuar", 30,30);
- Pantalla_DibujaTexto(texto,100,100);
- PersonajeDibuja(p);
- EnemigoDibuja(e);
- EnemigoMueve(e);
- Pantalla_Actualiza();
- Pantalla_Espera(40);
- }
- Pantalla_ImagenLibera(fondo);
- terminado=0;
- Imagen pantallafinal =Pantalla_ImagenLee("pantalla_final.bmp", 0);
- FILE * f = fopen("resultado.txt","r");
- int tiempomax;
- fscanf(f,"%d",&tiempomax);
- fclose(f);
- if (tiempomax < tiempofinal)
- {
- FILE * f = fopen("resultado.txt","w");
- fprintf(f,"%d",tiempofinal);
- fclose(f);
- }
- while (Pantalla_Activa() && !terminado)
- {
- if (Pantalla_TeclaPulsada(SDL_SCANCODE_RETURN)) terminado=1;
- Pantalla_DibujaImagen(pantallafinal, 0, 0, Pantalla_Anchura(), Pantalla_Altura());
- Pantalla_DibujaTexto("Pulsa RETURN para finalizar",30,30);
- Pantalla_ColorTrazo(255,255,255,255);
- char texto[100];
- if (tiempomax<tiempofinal)
- {
- sprintf(texto,"Enhorabuena, has conseguido establecer un nuevo record : %d",tiempofinal);
- }
- else
- {
- sprintf(texto,"Tu tiempo ha sido: %d. No has conseguido el record que es: %d", tiempofinal,tiempomax);
- }
- Pantalla_DibujaTexto(texto,75,75);
- Pantalla_Actualiza();
- Pantalla_Espera(40);
- PersonajeLibera(p);
- EnemigoLibera(e);
- }
- Pantalla_ImagenLibera(pantallafinal);
- Pantalla_Libera();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement