Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <stdio.h>
- #include <time.h>
- #include "LevelMAPmatrice.hpp"
- #define LARGEUR_FENETRE 1360
- #define HAUTEUR_FENETRE 800
- #define NB_CASE_LAGEUR 32
- #define NB_CASE_HAUTEUR 18
- #define TAILLE_CASE 40
- #define NOMBRE_TEXTURE 15
- #define PAS 5
- using namespace sf ;
- typedef struct
- {
- int x, y ;
- } Point ;
- typedef struct
- {
- int l, h ;
- } Size ;
- typedef struct
- {
- int r, g, b ;
- } CodeRGB ;
- typedef struct
- {
- char name[20] ;
- Size t /* t = taille */;
- Point p /* p = position */;
- CodeRGB couleur ;
- } Button ;
- void importTexture(Texture tab[NOMBRE_TEXTURE]) ;
- void level ( int numeroLvl, Texture t[NOMBRE_TEXTURE]) ;
- void afficheCaseLvl ( RenderWindow * fenetre, int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR], Texture t[NOMBRE_TEXTURE] ) ;
- void CopyMatrice(int m1[NB_CASE_HAUTEUR][NB_CASE_LAGEUR], int m2[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] ) ;
- void afficheObjet (RenderWindow * fenetre, Point p, Texture t[NOMBRE_TEXTURE] ) ;
- void Viseur(Point * PosVis, Event evenement);
- void Deplacement(Point * PosPla, Event evenement);
- void affichageViseur(RenderWindow * fenetre, Point PosVis, Texture t[]);
- void affichagePlayer(RenderWindow * fenetre, Point PosPla, Texture t[]);
- void tombe(int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR],Point * PosPla);
- void spawn(int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR],Point * PosPla );
- void mur(int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR],Point * PosPla);
- int main()
- {
- int niv ;
- Texture texture[NOMBRE_TEXTURE] ;
- importTexture(texture);
- printf("Choisissez un level : ");
- scanf("%i", &niv);
- level(niv, texture) ;
- return 0;
- }
- void level(int numeroLvl, Texture t[NOMBRE_TEXTURE])
- {
- Point posObj= {500,160}, posVis = {0,0}, posPla ;
- Sprite fond ;
- fond.setTexture(t[8]);
- char nomLvl[10] ;
- int matrice[NB_CASE_HAUTEUR][NB_CASE_LAGEUR];
- {
- /* Selection du niveau selon le chiffre */
- sprintf(nomLvl, "Niveau %i", numeroLvl) ;
- switch (numeroLvl)
- {
- case 1 :
- CopyMatrice(matrice,LEVELTUTO1) ;
- break ;
- case 2 :
- CopyMatrice(matrice,LEVELTUTO2) ;
- break ;
- case 3 :
- CopyMatrice(matrice,LEVEL3) ;
- break ;
- case 4 :
- CopyMatrice(matrice,LEVEL4) ;
- break ;
- case 5 :
- CopyMatrice(matrice,LEVEL5) ;
- break ;
- case 6 :
- CopyMatrice(matrice,LEVEL6) ;
- break ;
- case 7 :
- CopyMatrice(matrice,LEVEL7) ;
- break ;
- }
- /*fin de selection*/
- }
- spawn(matrice,&posPla );
- {
- /* Fenetre du niveau */
- RenderWindow app(VideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE), nomLvl);
- app.setMouseCursorVisible(false);
- while (app.isOpen())
- {
- Event event;
- while (app.pollEvent(event))
- {
- if (event.type == Event::Closed)
- app.close();
- Deplacement(&posPla, event);
- Viseur(&posVis, event);
- }
- mur(matrice,&posPla);
- tombe(matrice,&posPla);
- tombe(matrice,&posObj);
- app.clear();
- app.draw(fond);
- afficheCaseLvl( &app, matrice, t );
- /* C'EST ICI QU'IL FAUT RAJOUTER VOS FONCTIONS QUI AFFICHENT DE NOUVEAU SPRITE SUR LA FENETRE /!\ NE RIEN MODIFIER AILLEURS !!! */
- afficheObjet(&app,posObj,t);
- affichagePlayer(&app,posPla,t);
- affichageViseur(&app,posVis,t);
- /* fin */
- app.display();
- }
- /*fin fenetre*/
- }
- }
- /* PAS TOUCHE A MES FONCTIONS S'IL VOUS PLAIT */
- // Fonction qui permet d'afficher chaque case en fonction de son nombre dans la matrice
- void afficheCaseLvl ( RenderWindow * fenetre, int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR], Texture t[NOMBRE_TEXTURE] )
- {
- int i, j, nb ;
- for (i=0 ; i<NB_CASE_HAUTEUR; i++)
- {
- for (j=0 ; j<NB_CASE_LAGEUR ; j++)
- {
- Sprite carre ;
- carre.setPosition((j+1)*TAILLE_CASE,(i+1)*TAILLE_CASE) ;
- switch ( matCases[i][j] )
- {
- case 0 :
- carre.setTexture(t[0]);
- break ;
- case 1 :
- carre.setTexture(t[1]);
- break ;
- case 2 :
- carre.setTexture(t[2]);
- break ;
- case 3 :
- carre.setTexture(t[3]);
- break ;
- case 4 :
- carre.setTexture(t[4]);
- break ;
- case 5 :
- carre.setTexture(t[5]);
- break ;
- case 6 :
- carre.setTexture(t[6]);
- break ;
- case 7 :
- carre.setTexture(t[7]);
- break ;
- case 9 :
- carre.setTexture(t[9]);
- break ;
- }
- fenetre->draw(carre);
- }
- }
- }
- /* Liste des def de blocs
- 0=bloc null
- 1=bloc sans portail
- 2=bloc portail
- 3=kill
- 4=bloc reset portail
- 5=bouton
- 6=arrivee
- 7=spawn
- 9=cubeLave
- */
- // Fonction qui permet de copier une matrice dans une autre
- void CopyMatrice(int m1[NB_CASE_HAUTEUR][NB_CASE_LAGEUR], int m2[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] )
- {
- int i, j ;
- for (i=0 ; i<NB_CASE_HAUTEUR ; i++)
- {
- for (j=0 ; j<NB_CASE_LAGEUR ; j++)
- m1[i][j]=m2[i][j];
- }
- }
- void afficheObjet (RenderWindow * fenetre, Point p, Texture t[NOMBRE_TEXTURE] )
- {
- Sprite cube ;
- cube.setTexture(t[14]) ;
- cube.setOrigin(0,TAILLE_CASE-10);
- cube.setPosition(p.x,p.y);
- fenetre->draw(cube);
- }
- void importTexture(Texture tab[NOMBRE_TEXTURE])
- {
- tab[0].loadFromFile("vide.png");
- tab[1].loadFromFile("blockNon.png");
- tab[2].loadFromFile("blockOui.png");
- tab[3].loadFromFile("deathBlock.png");
- tab[4].loadFromFile("barrier.png");
- tab[5].loadFromFile("bouton.png");
- tab[6].loadFromFile("fin.png");
- tab[7].loadFromFile("spawn.png");
- tab[8].loadFromFile("bordure.png");
- tab[9].loadFromFile("lave.png");
- tab[10].loadFromFile("curseur.png");
- tab[11].loadFromFile("player.png");
- tab[12].loadFromFile("TirV.png");
- tab[13].loadFromFile("TirR.png");
- tab[14].loadFromFile("cube.png");
- }
- void Viseur(Point * PosVis, Event evenement)
- {
- if (evenement.type == Event::MouseMoved)
- {
- PosVis->x=evenement.mouseMove.x;
- PosVis->y=evenement.mouseMove.y;
- }
- }
- void Deplacement(Point * PosPla, Event evenement)
- {
- if (evenement.key.code == Keyboard::Left)
- PosPla->x-=PAS;
- if (evenement.key.code == Keyboard::Right)
- PosPla->x+=PAS;
- }
- void affichageViseur(RenderWindow * fenetre, Point PosVis, Texture t[])
- {
- Sprite viseur;
- viseur.setTexture(t[10]);
- viseur.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
- viseur.setPosition(PosVis.x,PosVis.y);
- fenetre->draw(viseur);
- }
- void affichagePlayer(RenderWindow * fenetre, Point PosPla, Texture t[])
- {
- Sprite player;
- player.setTexture(t[11]);
- player.setOrigin(0,TAILLE_CASE*2);
- player.setPosition(PosPla.x,PosPla.y);
- fenetre->draw(player);
- }
- void tombe(int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR],Point * PosPla)
- {
- Point positionMap ;
- positionMap.x = PosPla->x/40;
- positionMap.y = PosPla->y/40;
- if ((matCases[positionMap.y-1][positionMap.x] == 0 && matCases[positionMap.y-1][positionMap.x-1] == 0) || (matCases[positionMap.y-1][positionMap.x-1]==7))
- PosPla->y++;
- }
- void spawn(int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR],Point * PosPla )
- {
- int i, j ;
- for (i=0 ; i<NB_CASE_HAUTEUR; i++)
- {
- for (j=0 ; j<NB_CASE_LAGEUR ; j++)
- {
- if ( matCases[i][j]==7)
- {
- PosPla->x=((j+1)*40)+20;
- PosPla->y=((i+1)*40);
- }
- }
- }
- }
- //COLLISIONS MUR
- void mur(int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR],Point * PosPla)
- {
- Point positionMap ;
- positionMap.x = PosPla->x/40;
- positionMap.y = PosPla->y/40;
- if ((matCases[positionMap.y-2][positionMap.x-1] != 0) && (matCases[positionMap.y-2][positionMap.x-1] != 7) && (matCases[positionMap.y-2][positionMap.x-1] != 5))
- PosPla->x++;
- if ((matCases[positionMap.y-2][positionMap.x] != 0) && (matCases[positionMap.y-2][positionMap.x] != 7) && (matCases[positionMap.y-2][positionMap.x] != 5))
- PosPla->x--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement