Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <SFML/Graphics.hpp>
  6. #include <SFML/Graphics/Sprite.hpp>
  7. #include <SFML/Window.hpp>
  8. #include <cmath>
  9.  
  10. #include "perso/perso.h"
  11.  
  12. #define LONGEUR 25
  13. #define LARGEUR 15
  14.  
  15. using namespace std;
  16. using namespace sf;
  17.  
  18. RenderWindow fen;
  19. CircleShape cercle;
  20. ifstream map00("map/map00.rpgm");
  21.  
  22. int main()
  23. {
  24.     // TEXTURE
  25.  
  26.     Texture joueur, floor00, floor01, floor02; // Création de la texture
  27.     if(!joueur.loadFromFile("texture/lidia2.png", IntRect(0, 0, 0, 0)))
  28.     {
  29.         cout << "Impossible de charger la texture lidia.png" << endl;
  30.         return 1;
  31.     }
  32.     if(!floor01.loadFromFile("texture/red.png", IntRect(0, 0, 50, 50)))
  33.     {
  34.     cout << "Impossible de chager la texture red.png" << endl;
  35.     return 1;
  36.     }
  37.     if(!floor00.loadFromFile("texture/0.jpg", IntRect(0, 0, 50, 50)))
  38.     {
  39.     cout << "Impossible de chager la texture green.png" << endl;
  40.     return 1;
  41.     }
  42.     if(!floor02.loadFromFile("texture/blue.png", IntRect(0, 0, 50, 50)))
  43.     {
  44.         cout << "Impossible de chager la texture blue.png" << endl;
  45.         return 1;
  46.     }
  47.  
  48.    
  49.     joueur.setSmooth(true);
  50.  
  51.     // FENETRE
  52.  
  53.     fen.create(VideoMode(LONGEUR*50/*25*/, LARGEUR*50)/*15*/, "fen");
  54.  
  55.     // SPRITE
  56.  
  57.     Sprite spriteJ, sprite00, sprite01, sprite02;
  58.  
  59.     spriteJ.setTexture(joueur);
  60.     sprite00.setTexture(floor00);
  61.     sprite01.setTexture(floor01);
  62.     sprite02.setTexture(floor02);
  63.     personnageJoueur joueurCP;
  64.     // map
  65.      int map[LARGEUR+1][LONGEUR+1];
  66.          string ligne;
  67.          int m=0;
  68.  
  69.     for(int i = 0; i <= LARGEUR; i++)
  70.     {
  71.         for(int j = 0; j <= LONGEUR; j++)
  72.         {
  73.         map[i][j] = 0;
  74.         }
  75.     }
  76.          while(getline(map00, ligne))
  77.          {
  78.              for (int j=0;j<=LONGEUR;j++)
  79.              {
  80.                  map[m][j] = ligne[j]-'0';
  81.              }
  82.              m++;
  83.          }
  84.  
  85.    
  86.     // BOUCLE INFINIT
  87.  
  88.     string name;
  89.     cout << "Avant de commencé a jouer, comment t'appelle tu aventurier" << endl;
  90.     cin >> name;
  91.     while(fen.isOpen())
  92.     {
  93.         Event event; // création d'une var event
  94.         while (fen.pollEvent(event)) // on capture l'event
  95.         {
  96.             if(event.type == Event::Closed)
  97.             {
  98.                 fen.close();
  99.             }
  100.         }
  101.         if(Keyboard::isKeyPressed(Keyboard::Right))
  102.         {
  103.             spriteJ.move(50, 0);
  104.         }
  105.  
  106.         if(Keyboard::isKeyPressed(Keyboard::Left))
  107.         {
  108.             spriteJ.move(-50, 0);
  109.         }
  110.  
  111.         if(Keyboard::isKeyPressed(Keyboard::Up))
  112.         {
  113.             spriteJ.move(0, -50);
  114.         }
  115.  
  116.         if(Keyboard::isKeyPressed(Keyboard::Down))
  117.         {
  118.             spriteJ.move(0, 50);
  119.         }
  120.  
  121.     // MAP        
  122.  
  123.         for (int i=0;i<LONGEUR;i++)
  124.         {
  125.             for (int j=0;j<LARGEUR;j++)
  126.                 {
  127.                     switch (map[j][i])
  128.                     {
  129.                         case 0:
  130.                 sprite00.setPosition(i*50, j*50);
  131.                 fen.draw(sprite00);
  132.                 break;
  133.    
  134.                         case 1:
  135.                 sprite01.setPosition(i*50, j*50);
  136.                 fen.draw(sprite01);
  137.                 break;
  138.    
  139.                         case 2:
  140.                 sprite02.setPosition(i*50, j*50);
  141.                 fen.draw(sprite02);
  142.                 break;
  143.  
  144.             default:
  145.                 sprite02.setPosition(i*50, j*50);
  146.                 fen.draw(sprite01);
  147.             break;
  148.                     }
  149.                 }
  150.         }
  151.     cout << "X: " << spriteJ.getPosition().x << "\n" << endl;
  152.     cout << "Y: " << spriteJ.getPosition().y << "\n" << endl;
  153.         fen.draw(spriteJ);
  154.         fen.display(); // afficher la fenettre
  155.         fen.clear(); // On clean la fenettre
  156.     }
  157.  
  158.     return 0;
  159. }
  160. ➜  Jeu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement