Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include "LevelMAPmatrice.hpp"
  5.  
  6. #define LARGEUR_FENETRE 1360
  7. #define HAUTEUR_FENETRE 800
  8. #define NB_CASE_LAGEUR 32
  9. #define NB_CASE_HAUTEUR 18
  10. #define TAILLE_CASE 40
  11.  
  12. using namespace sf ;
  13.  
  14. typedef struct
  15. {
  16. int x, y ;
  17. } Point ;
  18. typedef struct
  19. {
  20. int l, h ;
  21. } Size ;
  22. typedef struct
  23. {
  24. int r, g, b ;
  25. } CodeRGB ;
  26. typedef struct
  27. {
  28. char name[20] ;
  29. Size t /* t = taille */;
  30. Point p /* p = position */;
  31. CodeRGB couleur ;
  32. } Button ;
  33.  
  34. void level ( int numeroLvl) ;
  35. void afficheCaseLvl ( RenderWindow * fenetre, int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] ) ;
  36. void CopyMatrice(int m1[NB_CASE_HAUTEUR][NB_CASE_LAGEUR], int m2[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] ) ;
  37. void Viseur(Point * PosVis, Event evenement);
  38. void Deplacement(Point * PosPla, Event evenement);
  39. //void Tir(RenderWindow * fenetre,Point * z, Event evenement);
  40. void affichageViseur(RenderWindow * fenetre, Point PosVis );
  41. void affichagePlayer(RenderWindow * fenetre, Point PosPla);
  42.  
  43. int main()
  44. {
  45.  
  46. int niv ;
  47. printf("Choisissez un level : ");
  48. scanf("%i", &niv);
  49. level(niv) ;
  50. return 0;
  51. }
  52.  
  53. void level(int numeroLvl)
  54. {
  55. Texture curseur;
  56. if (!curseur.loadFromFile("viseur.png"))
  57. printf("PB de chargement de curseur !\n");
  58. Sprite viseur;
  59. viseur.setTexture(curseur);
  60. viseur.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
  61.  
  62. Texture perso;
  63. if (!perso.loadFromFile("player.png"))
  64. printf("PB de chargement de player !\n");
  65. Sprite player;
  66. player.setTexture(perso);
  67. player.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
  68.  
  69.  
  70. Texture background ;
  71. background.loadFromFile("bordure.png");
  72. Sprite fond ;
  73. fond.setTexture(background);
  74. char nomLvl[10] ;
  75. int /*i, j,*/ matrice[NB_CASE_HAUTEUR][NB_CASE_LAGEUR];
  76. Point PosVis ={0,0};
  77.  
  78. Point PosPla ={0,500};
  79.  
  80.  
  81. {/* Selection du niveau selon le chiffre */
  82. sprintf(nomLvl, "Niveau %i", numeroLvl) ;
  83. switch (numeroLvl)
  84. {
  85. case 1 :
  86. CopyMatrice(matrice,LEVELTUTO1) ;
  87. break ;
  88. case 2 :
  89. CopyMatrice(matrice,LEVELTUTO2) ;
  90. break ;
  91. case 3 :
  92. CopyMatrice(matrice,LEVEL3) ;
  93. break ;
  94. case 4 :
  95. CopyMatrice(matrice,LEVEL4) ;
  96. break ;
  97. case 5 :
  98. CopyMatrice(matrice,LEVEL5) ;
  99. break ;
  100. case 6 :
  101. CopyMatrice(matrice,LEVEL6) ;
  102. break ;
  103. case 7 :
  104. CopyMatrice(matrice,LEVEL7) ;
  105. break ;
  106. }
  107. /*fin de selection*/}
  108.  
  109.  
  110. {/* Fenetre du niveau */
  111. RenderWindow fenetre(VideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE), nomLvl);
  112.  
  113. while (fenetre.isOpen())
  114. {
  115. Event event;
  116. while (fenetre.pollEvent(event))
  117. {
  118. if (event.type == Event::Closed)
  119. fenetre.close();
  120. Deplacement(&PosPla, event);
  121. Viseur(&PosVis, event);
  122. }
  123.  
  124. fenetre.clear();
  125. fenetre.draw(fond);
  126. afficheCaseLvl( &fenetre, matrice );
  127.  
  128. /* C'EST ICI QU'IL FAUT RAJOUTER VOS FONCTIONS QUI AFFICHENT DE NOUVEAU SPRITE SUR LA FENETRE /!\ NE RIEN MODIFIER AILLEURS !!! */
  129. affichageViseur(&fenetre,PosVis);
  130. affichagePlayer(&fenetre,PosPla);
  131. /* fin */
  132.  
  133. fenetre.display();
  134. }
  135. /*fin fenetre*/}
  136. }
  137.  
  138.  
  139.  
  140. /* PAS TOUCHE A MES FONCTIONS S'IL VOUS PLAIT */
  141.  
  142. // Fonction qui permet d'afficher chaque case en fonction de son nombre dans la matrice
  143. void afficheCaseLvl ( RenderWindow * fenetre, int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] )
  144. {
  145. Texture vide ;
  146. vide.loadFromFile("vide.png");
  147. Texture blocNon ;
  148. blocNon.loadFromFile("blockNon.png");
  149. Texture blocOui ;
  150. blocOui.loadFromFile("blockOui.png");
  151. Texture mort ;
  152. mort.loadFromFile("deathBlock.png");
  153. Texture barrier ;
  154. barrier.loadFromFile("barrier.png");
  155. Texture bouton ;
  156. bouton.loadFromFile("bouton.png");
  157. Texture fin ;
  158. fin.loadFromFile("fin.png");
  159. Texture spawn ;
  160. spawn.loadFromFile("spawn.png");
  161. Texture lave ;
  162. lave.loadFromFile("lave.png");
  163. int i, j, nb ;
  164. for (i=0 ; i<NB_CASE_HAUTEUR; i++)
  165. {
  166. for (j=0 ; j<NB_CASE_LAGEUR ; j++)
  167. {
  168. Sprite carre ;
  169. carre.setPosition((j+1)*40,(i+1)*40) ;
  170. if ( matCases[i][j]==0 )
  171. carre.setTexture(vide);
  172. else if ( matCases[i][j]==1 )
  173. carre.setTexture(blocNon);
  174. else if ( matCases[i][j]==2 )
  175. carre.setTexture(blocOui);
  176. else if ( matCases[i][j]==3 )
  177. carre.setTexture(mort);
  178. else if ( matCases[i][j]==4 )
  179. carre.setTexture(barrier);
  180. else if ( matCases[i][j]==5 )
  181. carre.setTexture(bouton);
  182. else if ( matCases[i][j]==6 )
  183. carre.setTexture(fin);
  184. else if ( matCases[i][j]==7 )
  185. carre.setTexture(spawn);
  186. else if ( matCases[i][j]==9 )
  187. carre.setTexture(lave);
  188. fenetre->draw(carre);
  189. }
  190. }
  191. }
  192.  
  193. /* Liste des def de blocs
  194. 0=bloc null
  195. 1=bloc sans portail
  196. 2=bloc portail
  197. 3=kill
  198. 4=bloc reset portail
  199. 5=bouton
  200. 6=arrivee
  201. 7=spawn
  202. 9=cubeLave
  203. */
  204.  
  205. // Fonction qui permet de copier une matrice dans une autre
  206. void CopyMatrice(int m1[NB_CASE_HAUTEUR][NB_CASE_LAGEUR], int m2[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] )
  207. {
  208. int i, j ;
  209. for (i=0 ; i<NB_CASE_HAUTEUR ; i++)
  210. {
  211. for (j=0 ; j<NB_CASE_LAGEUR ; j++)
  212. {
  213. m1[i][j]=m2[i][j];
  214. }
  215. }
  216. }
  217.  
  218. void Viseur(Point * PosVis, Event evenement)
  219. {
  220. PosVis->x=evenement.mouseMove.x;
  221. PosVis->y=evenement.mouseMove.y;
  222. }
  223.  
  224. void Deplacement(Point * PosPla, Event evenement)
  225. {
  226. if (evenement.key.code == Keyboard::Left)
  227. {
  228. PosPla->x-=5;
  229. printf("RECULE");
  230.  
  231. }
  232. if (evenement.key.code == Keyboard::Right)
  233. {
  234. PosPla->x+=5;
  235. printf("AVANCE");
  236. }
  237. }
  238.  
  239. void affichageViseur(RenderWindow * fenetre, Point PosVis)
  240. {
  241. Texture curseur;
  242. if (!curseur.loadFromFile("viseur.png"))
  243. printf("PB de chargement de curseur !\n");
  244. Sprite viseur;
  245. viseur.setTexture(curseur);
  246. viseur.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
  247.  
  248. viseur.setPosition(PosVis.x,PosVis.y);
  249. fenetre->draw(viseur);
  250. }
  251. void affichagePlayer(RenderWindow * fenetre, Point PosPla)
  252. {
  253. Texture perso;
  254. if (!perso.loadFromFile("player.png"))
  255. printf("PB de chargement de player !\n");
  256. Sprite player;
  257. player.setTexture(perso);
  258. player.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
  259.  
  260. player.setPosition(PosPla.x,50);
  261. fenetre->draw(player);
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement