Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib>
- #include <SFML/Graphics.hpp>
- #include <SFML/Graphics/Sprite.hpp>
- #include <SFML/Window.hpp>
- #include <cmath>
- #include "perso/perso.h"
- #define LONGEUR 25
- #define LARGEUR 15
- using namespace std;
- using namespace sf;
- RenderWindow fen;
- CircleShape cercle;
- ifstream map00("map/map00.rpgm");
- int main()
- {
- // TEXTURE
- Texture joueur, floor00, floor01, floor02; // Création de la texture
- if(!joueur.loadFromFile("texture/lidia2.png", IntRect(0, 0, 0, 0)))
- {
- cout << "Impossible de charger la texture lidia.png" << endl;
- return 1;
- }
- if(!floor01.loadFromFile("texture/red.png", IntRect(0, 0, 50, 50)))
- {
- cout << "Impossible de chager la texture red.png" << endl;
- return 1;
- }
- if(!floor00.loadFromFile("texture/0.jpg", IntRect(0, 0, 50, 50)))
- {
- cout << "Impossible de chager la texture green.png" << endl;
- return 1;
- }
- if(!floor02.loadFromFile("texture/blue.png", IntRect(0, 0, 50, 50)))
- {
- cout << "Impossible de chager la texture blue.png" << endl;
- return 1;
- }
- joueur.setSmooth(true);
- // FENETRE
- fen.create(VideoMode(LONGEUR*50/*25*/, LARGEUR*50)/*15*/, "fen");
- // SPRITE
- Sprite spriteJ, sprite00, sprite01, sprite02;
- spriteJ.setTexture(joueur);
- sprite00.setTexture(floor00);
- sprite01.setTexture(floor01);
- sprite02.setTexture(floor02);
- personnageJoueur joueurCP;
- // map
- int map[LARGEUR+1][LONGEUR+1];
- string ligne;
- int m=0;
- for(int i = 0; i <= LARGEUR; i++)
- {
- for(int j = 0; j <= LONGEUR; j++)
- {
- map[i][j] = 0;
- }
- }
- while(getline(map00, ligne))
- {
- for (int j=0;j<=LONGEUR;j++)
- {
- map[m][j] = ligne[j]-'0';
- }
- m++;
- }
- // BOUCLE INFINIT
- string name;
- cout << "Avant de commencé a jouer, comment t'appelle tu aventurier" << endl;
- cin >> name;
- while(fen.isOpen())
- {
- Event event; // création d'une var event
- while (fen.pollEvent(event)) // on capture l'event
- {
- if(event.type == Event::Closed)
- {
- fen.close();
- }
- }
- if(Keyboard::isKeyPressed(Keyboard::Right))
- {
- spriteJ.move(50, 0);
- }
- if(Keyboard::isKeyPressed(Keyboard::Left))
- {
- spriteJ.move(-50, 0);
- }
- if(Keyboard::isKeyPressed(Keyboard::Up))
- {
- spriteJ.move(0, -50);
- }
- if(Keyboard::isKeyPressed(Keyboard::Down))
- {
- spriteJ.move(0, 50);
- }
- // MAP
- for (int i=0;i<LONGEUR;i++)
- {
- for (int j=0;j<LARGEUR;j++)
- {
- switch (map[j][i])
- {
- case 0:
- sprite00.setPosition(i*50, j*50);
- fen.draw(sprite00);
- break;
- case 1:
- sprite01.setPosition(i*50, j*50);
- fen.draw(sprite01);
- break;
- case 2:
- sprite02.setPosition(i*50, j*50);
- fen.draw(sprite02);
- break;
- default:
- sprite02.setPosition(i*50, j*50);
- fen.draw(sprite01);
- break;
- }
- }
- }
- cout << "X: " << spriteJ.getPosition().x << "\n" << endl;
- cout << "Y: " << spriteJ.getPosition().y << "\n" << endl;
- fen.draw(spriteJ);
- fen.display(); // afficher la fenettre
- fen.clear(); // On clean la fenettre
- }
- return 0;
- }
- ➜ Jeu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement