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
- 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 level ( int numeroLvl) ;
- void afficheCaseLvl ( RenderWindow * fenetre, int matCases[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] ) ;
- void CopyMatrice(int m1[NB_CASE_HAUTEUR][NB_CASE_LAGEUR], int m2[NB_CASE_HAUTEUR][NB_CASE_LAGEUR] ) ;
- void Viseur(Point * PosVis, Event evenement);
- void Deplacement(Point * PosPla, Event evenement);
- //void Tir(RenderWindow * fenetre,Point * z, Event evenement);
- void affichageViseur(RenderWindow * fenetre, Point PosVis );
- void affichagePlayer(RenderWindow * fenetre, Point PosPla);
- int main()
- {
- int niv ;
- printf("Choisissez un level : ");
- scanf("%i", &niv);
- level(niv) ;
- return 0;
- }
- void level(int numeroLvl)
- {
- Texture curseur;
- if (!curseur.loadFromFile("viseur.png"))
- printf("PB de chargement de curseur !\n");
- Sprite viseur;
- viseur.setTexture(curseur);
- viseur.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
- Texture perso;
- if (!perso.loadFromFile("player.png"))
- printf("PB de chargement de player !\n");
- Sprite player;
- player.setTexture(perso);
- player.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
- Texture background ;
- background.loadFromFile("bordure.png");
- Sprite fond ;
- fond.setTexture(background);
- char nomLvl[10] ;
- int /*i, j,*/ matrice[NB_CASE_HAUTEUR][NB_CASE_LAGEUR];
- Point PosVis ={0,0};
- Point PosPla ={0,500};
- {/* 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*/}
- {/* Fenetre du niveau */
- RenderWindow fenetre(VideoMode(LARGEUR_FENETRE, HAUTEUR_FENETRE), nomLvl);
- while (fenetre.isOpen())
- {
- Event event;
- while (fenetre.pollEvent(event))
- {
- if (event.type == Event::Closed)
- fenetre.close();
- Deplacement(&PosPla, event);
- Viseur(&PosVis, event);
- }
- fenetre.clear();
- fenetre.draw(fond);
- afficheCaseLvl( &fenetre, matrice );
- /* C'EST ICI QU'IL FAUT RAJOUTER VOS FONCTIONS QUI AFFICHENT DE NOUVEAU SPRITE SUR LA FENETRE /!\ NE RIEN MODIFIER AILLEURS !!! */
- affichageViseur(&fenetre,PosVis);
- affichagePlayer(&fenetre,PosPla);
- /* fin */
- fenetre.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 vide ;
- vide.loadFromFile("vide.png");
- Texture blocNon ;
- blocNon.loadFromFile("blockNon.png");
- Texture blocOui ;
- blocOui.loadFromFile("blockOui.png");
- Texture mort ;
- mort.loadFromFile("deathBlock.png");
- Texture barrier ;
- barrier.loadFromFile("barrier.png");
- Texture bouton ;
- bouton.loadFromFile("bouton.png");
- Texture fin ;
- fin.loadFromFile("fin.png");
- Texture spawn ;
- spawn.loadFromFile("spawn.png");
- Texture lave ;
- lave.loadFromFile("lave.png");
- 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)*40,(i+1)*40) ;
- if ( matCases[i][j]==0 )
- carre.setTexture(vide);
- else if ( matCases[i][j]==1 )
- carre.setTexture(blocNon);
- else if ( matCases[i][j]==2 )
- carre.setTexture(blocOui);
- else if ( matCases[i][j]==3 )
- carre.setTexture(mort);
- else if ( matCases[i][j]==4 )
- carre.setTexture(barrier);
- else if ( matCases[i][j]==5 )
- carre.setTexture(bouton);
- else if ( matCases[i][j]==6 )
- carre.setTexture(fin);
- else if ( matCases[i][j]==7 )
- carre.setTexture(spawn);
- else if ( matCases[i][j]==9 )
- carre.setTexture(lave);
- 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 Viseur(Point * PosVis, Event evenement)
- {
- PosVis->x=evenement.mouseMove.x;
- PosVis->y=evenement.mouseMove.y;
- }
- void Deplacement(Point * PosPla, Event evenement)
- {
- if (evenement.key.code == Keyboard::Left)
- {
- PosPla->x-=5;
- printf("RECULE");
- }
- if (evenement.key.code == Keyboard::Right)
- {
- PosPla->x+=5;
- printf("AVANCE");
- }
- }
- void affichageViseur(RenderWindow * fenetre, Point PosVis)
- {
- Texture curseur;
- if (!curseur.loadFromFile("viseur.png"))
- printf("PB de chargement de curseur !\n");
- Sprite viseur;
- viseur.setTexture(curseur);
- 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 perso;
- if (!perso.loadFromFile("player.png"))
- printf("PB de chargement de player !\n");
- Sprite player;
- player.setTexture(perso);
- player.setOrigin(Vector2f(TAILLE_CASE/2,TAILLE_CASE/2));
- player.setPosition(PosPla.x,50);
- fenetre->draw(player);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement