Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. #include "Pantalla.h"
  2. #include "time.h"
  3. #include "stdlib.h"
  4. #include "stdio.h"
  5. #include "Personaje.h"
  6. #include "Enemigo.h"
  7.  
  8. int main(int argc, char **argv)
  9. {
  10. srand(time(NULL));
  11. Pantalla_Crea("Ejemplo3", 640, 480);
  12. int terminado=0;
  13. int tiempofinal;
  14. Imagen fondo =Pantalla_ImagenLee("fondo1.bmp", 1);
  15. while (Pantalla_Activa() && !terminado)
  16. {
  17. if (Pantalla_TeclaPulsada(SDL_SCANCODE_RETURN)) terminado=1;
  18. Pantalla_DibujaImagen(fondo, 0, 0, Pantalla_Anchura(), Pantalla_Altura());
  19. Pantalla_ColorTrazo(255,255,255,255);
  20. Pantalla_DibujaTexto("Pulsa RETURN para comenzar", 220, 200);
  21. Pantalla_Actualiza();
  22. Pantalla_Espera(40);
  23. }
  24. Pantalla_ImagenLibera(fondo);
  25. terminado=0;
  26. Imagen fondo2 =Pantalla_ImagenLee("grieta.bmp", 0);
  27.  
  28. Imagen ei = Pantalla_ImagenLee("enemigonashor.bmp",255);
  29. int ew = 100;
  30. int eh = 100;
  31. int ex = rand()%(Pantalla_Anchura()-ew);
  32. int ey = 0;
  33. int evx = 20;
  34. int evy = 20;
  35. Enemigo e = EnemigoCrea(ei,ex,ey,ew,eh,evx,evy);
  36.  
  37.  
  38. Imagen pi = Pantalla_ImagenLee("personaje.bmp", 255);
  39. int pw = 100;
  40. int ph = 100;
  41. int px = rand()%(Pantalla_Anchura()-pw);
  42. int py = Pantalla_Altura()-ph;
  43. Personaje p = PersonajeCrea(pi,px,py,pw,ph);
  44.  
  45. int tini=time(NULL);
  46.  
  47. while (Pantalla_Activa() && !terminado)
  48. {
  49. if (Pantalla_TeclaPulsada(SDL_SCANCODE_ESCAPE)) terminado=1;
  50. if (Pantalla_TeclaPulsada(SDL_SCANCODE_LEFT)) PersonajeMueve(p,-20,0);
  51. if (Pantalla_TeclaPulsada(SDL_SCANCODE_RIGHT)) PersonajeMueve(p,20,0);
  52. if (Pantalla_TeclaPulsada(SDL_SCANCODE_UP)) PersonajeMueve(p,0,-20);
  53. if (Pantalla_TeclaPulsada(SDL_SCANCODE_DOWN)) PersonajeMueve(p,0,20);
  54.  
  55.  
  56.  
  57. int tfin=time(NULL);
  58. int tiempo=tfin-tini;
  59. char texto[100];
  60. sprintf(texto,"Tiempo: %d",tiempo);
  61. tiempofinal=tiempo;
  62.  
  63. Pantalla_DibujaImagen(fondo2,0,0,Pantalla_Anchura(),Pantalla_Altura());
  64. Pantalla_ColorTrazo(255,255,255,255);
  65. Pantalla_DibujaTexto("Pulsa ESCAPE para continuar", 30,30);
  66. Pantalla_DibujaTexto(texto,100,100);
  67. PersonajeDibuja(p);
  68. EnemigoDibuja(e);
  69. EnemigoMueve(e);
  70. Pantalla_Actualiza();
  71. Pantalla_Espera(40);
  72.  
  73. }
  74.  
  75. Pantalla_ImagenLibera(fondo);
  76. terminado=0;
  77. Imagen pantallafinal =Pantalla_ImagenLee("pantalla_final.bmp", 0);
  78. FILE * f = fopen("resultado.txt","r");
  79. int tiempomax;
  80. fscanf(f,"%d",&tiempomax);
  81. fclose(f);
  82. if (tiempomax < tiempofinal)
  83. {
  84. FILE * f = fopen("resultado.txt","w");
  85. fprintf(f,"%d",tiempofinal);
  86. fclose(f);
  87.  
  88. }
  89.  
  90. while (Pantalla_Activa() && !terminado)
  91.  
  92. {
  93. if (Pantalla_TeclaPulsada(SDL_SCANCODE_RETURN)) terminado=1;
  94. Pantalla_DibujaImagen(pantallafinal, 0, 0, Pantalla_Anchura(), Pantalla_Altura());
  95. Pantalla_DibujaTexto("Pulsa RETURN para finalizar",30,30);
  96. Pantalla_ColorTrazo(255,255,255,255);
  97. char texto[100];
  98. if (tiempomax<tiempofinal)
  99. {
  100.  
  101. sprintf(texto,"Enhorabuena, has conseguido establecer un nuevo record : %d",tiempofinal);
  102. }
  103.  
  104. else
  105. {
  106. sprintf(texto,"Tu tiempo ha sido: %d. No has conseguido el record que es: %d", tiempofinal,tiempomax);
  107. }
  108. Pantalla_DibujaTexto(texto,75,75);
  109. Pantalla_Actualiza();
  110. Pantalla_Espera(40);
  111. PersonajeLibera(p);
  112. EnemigoLibera(e);
  113.  
  114. }
  115. Pantalla_ImagenLibera(pantallafinal);
  116. Pantalla_Libera();
  117. return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement