Je ne pense pas que le code entre en jeu puisque même en supprimant, ça ne marche pas. Si tu veux, voici mon code :
#include "C:\Users\NIKO\Downloads\SFML-2.4.2-windows-gcc-4.9.2-tdm-32-bit(2)\SFML-2.4.2\include\SFML\Graphics.hpp"
#include "C:\Users\NIKO\Downloads\SFML-2.4.2-windows-gcc-4.9.2-tdm-32-bit(2)\SFML-2.4.2\include\SFML\audio.hpp"
#include "C:\Users\NIKO\Downloads\SFML-2.4.2-windows-gcc-4.9.2-tdm-32-bit(2)\SFML-2.4.2\include\SFML\OpenGL.hpp"
#include "C:\Users\NIKO\Downloads\SFML-2.4.2-windows-gcc-4.9.2-tdm-32-bit(2)\SFML-2.4.2\include\SFML\Graphics\Font.hpp"
#include "C:\Users\NIKO\Downloads\SFML-2.4.2-windows-gcc-4.9.2-tdm-32-bit(2)\SFML-2.4.2\include\SFML\Window\joystick.hpp"
#include "Collision.h"
#include "Personnage.h"
#include "pause_programme.h"
#include "menu.h"
#include "maisonSimple.h"
//#include <box2D.h>
#include <fstream>
using namespace sf;
using namespace std;
namespace touche = Kollision;
sf::RenderWindow app;
sf::RenderWindow ast;
CircleShape triangle(80, 3);
ConvexShape convex;
ConvexShape convex2;
CircleShape forme(100.f);
RectangleShape rect;
Texture perso;
Texture ennemieSimple;
Texture ennemieSimpleMort;
Texture barDEndurance;
Texture maison1;
Sprite sprite_perso;
Sprite sprite_ennemiesimple;
Sprite sprite_barDEndurance;
Sprite sprite_maison1;
Music musique1;
Font policeEcriture;
Text afficheS("dddd", policeEcriture);
struct AABB {
int x;
int y;
int h;
int l;
};
enum direction{Down, Left, Right, Up};
enum directionEnnemie{eDown, eLeft, eRight, eUp};
enum directionEnnemieMort{eDownM, eLeftM, eRightM, eUpM};
/*enum joystik{Count = 8, ButtonCount = 32, AxisCount = 8};
enum Axis {X, Y, Z, R, U, V, PovX, PovY};*/
Vector2i animation(1, Down);
Vector2i animationEnnemieSimple(1, Down);
Vector2i animationEnnemieSimpleMort(1, Down);
int m_i = 100;
bool updateFPS = true;
int speed = 3;
void gestionClavier();
void gestionSourie();
int mainTestGraphismeDEUXPOINTAsteroide();
int blocksize = 32;
int bl0cksiz3 = 48;
Vector2i position;
View camera;
int screenwiz = 1000;
int screenheigt = 800;
bool continueStopMusique1 = false;
bool fullscreen = true;
double durationMusique1;
bool collision(AABB box1, AABB box2){
if((box2.x >= box1.x + box1.l) // trop à droite
|| (box2.x + box2.l <= box1.x) // trop à gauche
|| (box2.y >= box1.y + box1.h) // trop en bas
|| (box2.y + box2.h <= box1.y)) // trop en haut
return false;
else{
return true;
}
}
Personnage hero, ennemie;
double height2, width2;;
int dfgdfgh()
{
app.create(VideoMode(1000, 800), "Ça Fonctionne !", Style::None);
app.setPosition(Vector2i(500, 200));
app.setFramerateLimit(25);
Menu menu(app.getPosition().x, app.getPosition().y);
forme.setFillColor(sf::Color(22,152,200));
forme.setPosition(100, 10);
forme.setRadius(50);
forme.setOutlineColor(Color::Red);
forme.setOutlineThickness(2);
triangle.setFillColor(Color::Blue);
triangle.setPosition(500, 40);
triangle.setOutlineColor(Color::Green);
triangle.setOutlineThickness(2);
convex.setPointCount(5);
convex.setPoint(0, Vector2f(0, 0));
convex.setPoint(1, Vector2f(200, 10));
convex.setPoint(2, Vector2f(400, 40));
convex.setPoint(3, Vector2f(200, 100));
convex.setPoint(4, Vector2f(0, 0));
convex.setPosition(320, 400);
convex.setFillColor(Color(80, 20, 81));
convex.setOutlineColor(Color(200, 200, 200));
convex.setOutlineThickness(3);
convex.setPosition(700, 300);
convex2.setPointCount(6);
convex2.setPoint(0, Vector2f(0,0));
convex2.setPoint(1, Vector2f(200,0));
convex2.setPoint(2, Vector2f(200,300));
convex2.setPoint(3, Vector2f(100,300));
convex2.setPoint(4, Vector2f(100,100));
convex2.setPoint(5, Vector2f(0,0));
convex2.setPosition(600,600);
convex2.setFillColor(Color(10,10,80));
convex2.setOutlineColor(Color(30,30, 100));
convex2.setOutlineThickness(5);
rect.setFillColor(Color::Blue);
rect.setPosition(48, 20);
rect.setOutlineColor(Color(123, 0, 55));
rect.setOutlineThickness(8);
rect.setSize(Vector2f(18, 25));
app.setMouseCursorVisible(false);
touche::CreateTextureAndBitmask(ennemieSimple, "vEnnemie.png");
touche::CreateTextureAndBitmask(perso, "basePerso.png");
touche::CreateTextureAndBitmask(ennemieSimpleMort, "eeennemieMort.png");
touche::CreateTextureAndBitmask(maison1, "frhfghfghfghfgh.png");
if(!perso.loadFromFile("basePerso.png")){
cout<<"Erreur !\n";
pause_programme();
return EXIT_FAILURE;
}
/*if(!ennemieSimple.loadFromFile("vEnnemie.png")){
cout<<"Erreur2";
pause_programme();
return EXIT_FAILURE;
}*/
if(!ennemieSimpleMort.loadFromFile("eeennemieMort.png")){
cout<<"Erreur 3\n";
pause_programme();
return EXIT_FAILURE;
}
ennemieSimple.setSmooth(true);
perso.setSmooth(true);
maison1.setSmooth(true);
sprite_perso.setTexture(perso);
sprite_maison1.setTexture(maison1);
sprite_ennemiesimple.setTexture(ennemieSimple);
sprite_ennemiesimple.setPosition(100, 50);
sprite_maison1.setPosition(500, 500);
if(!musique1.openFromFile("Antonin_Dvorak_-_New_World_Symphony_Allegro_con_fu.ogg")){
cout<<"Erreur 4\n";
pause_programme();
return EXIT_FAILURE;
}
musique1.play();
sprite_perso.setPosition(0,0);
if(!policeEcriture.loadFromFile("font.ttf")){
cout<<"Erreur 5\n";
pause_programme();
return EXIT_FAILURE;
}
while (app.isOpen())
{
sf::Event event;
while (app.pollEvent(event))
{
switch (event.type)
{
/*if (Keyboard::isKeyPressed(Keyboard::Escape)){
case sf::Event::KeyReleased:
switch (event.key.code == Keyboard::Escape)
{
case sf::Keyboard::W:
menu.MoveUp();
break;
case sf::Keyboard::X:
menu.MoveDown();
break;
case sf::Keyboard::Return:
switch (menu.GetPressedItem())
{
case 0:
std::cout << "Play button has been pressed" << std::endl;
break;
case 1:
std::cout << "Option button has been pressed" << std::endl;
break;
case 2:
app.close();
musique1.stop();
break;
}
break;
}
break;
}*/
case sf::Event::JoystickConnected:
afficheS.setString("yudgvhjsduivfkjvhuisdgvuyiougfybv");
afficheS.setCharacterSize(50);
break;
case sf::Event::Closed:
app.close();
musique1.stop();
break;
}
// switch (event.type){
//
// case sf::Event::KeyReleased:
// switch (event.key.code){
//
// case sf::Keyboard::Return:
//
// if (true == fullscreen){
//
// app.create(sf::VideoMode(600, 600), "sfml", sf::Style::None);
// fullscreen = false;
//
// }
//
// else {
//
// app.create(sf::VideoMode(600, 600, 32),"sfml", sf::Style::Fullscreen);
// fullscreen = true;
//
// }
//
//
// break;
// }
//
// }
if (event.type == sf::Event::Closed){
musique1.stop();
app.close();
break;
}
if(Joystick::isConnected(0)){
cout<<"vdfbgbggfcool";
}
if (sf::Joystick::isButtonPressed(0, 1))
{
std::cout << "Button 1 is being pressed" << std::endl;
}
if (Keyboard::isKeyPressed(Keyboard::L)){
mainTestGraphismeDEUXPOINTAsteroide();
}
gestionClavier();
gestionSourie();
animation.x++;
animationEnnemieSimple.x++;
if (touche::PixelPerfectTest(sprite_perso, sprite_ennemiesimple)){
afficheS.setString("pppppp");
afficheS.setCharacterSize(100);
afficheS.setFillColor(Color::Red);
afficheS.setPosition(50, 50);
}
if (touche::PixelPerfectTest(sprite_perso, sprite_maison1)){
afficheS.setString("ghggigy");
afficheS.setCharacterSize(100);
afficheS.setFillColor(Color::Red);
afficheS.setPosition(50, 50);
app.draw(afficheS);
}
if (animation.x * blocksize >= perso.getSize().x){
animation.x = 0;
}
if(animationEnnemieSimple.x * blocksize >= ennemieSimple.getSize().x){
animationEnnemieSimple.x = 0;
}
if(animationEnnemieSimpleMort.x * bl0cksiz3 >= ennemieSimpleMort.getSize().x){
animationEnnemieSimpleMort.x = 0;
}
sprite_perso.setTextureRect(IntRect(animation.x * blocksize, animation.y * blocksize, blocksize, blocksize));
sprite_ennemiesimple.setTextureRect(IntRect(animationEnnemieSimple.x * blocksize, animationEnnemieSimple.y * blocksize, blocksize, blocksize));
//caméra
camera.reset(FloatRect(0, 0,screenwiz, screenheigt));
Vector2f position(screenwiz / 2, screenheigt / 2);
position.x = sprite_perso.getPosition().x + (blocksize / 2) - (screenwiz / 2) ;
position.y = sprite_perso.getPosition().y + (blocksize / 2) - (screenheigt / 2) ;
if (position.x < 0){
position.x = 0;
}
if (position.y < 0){
position.y = 0;
}
camera.reset(FloatRect(position.x, position.y, screenwiz, screenheigt));
app.setView(camera);
//collision
/*if (sprite_perso.getGlobalBounds().intersects(rect.getGlobalBounds())){
cout<<"collision\n";
}
if (sprite_perso.getGlobalBounds().intersects(convex.getGlobalBounds())){
cout<<"collision 2\n";
}
if (sprite_perso.getGlobalBounds().intersects(forme.getGlobalBounds())){
cout<<"collision 3\n";
}*/
/*if (sprite_perso.getGlobalBounds().intersects(sprite_ennemiesimple.getGlobalBounds())){
cout<<"Collision 4\n";
hero.recevoirDegats(1);
hero.afficherEtat();
}*/
if (hero.estVivant() == false){
cout<<"Game over\n";
cout<<"Vous etes mort :(\n";
afficheS.setString("Game Over");
afficheS.setColor(Color::Red);
afficheS.setFont(policeEcriture);
afficheS.setCharacterSize(100);
afficheS.setPosition(50, 50);
}
if(ennemie.estVivant() == false){
cout<<"GG\n";
//sprite_ennemiesimple.move(1000000, 1000000);
sprite_ennemiesimple.setTexture(ennemieSimpleMort);
sprite_ennemiesimple.setTextureRect(IntRect(animationEnnemieSimple.x * blocksize, animationEnnemieSimple.y * blocksize, blocksize, blocksize));
afficheS.setString("Bien joué");
afficheS.setCharacterSize(100);
afficheS.setPosition(50, 50);
afficheS.setColor(Color::Green);
}
/* if (sprite_perso.getGlobalBounds().intersects(sprite_ennemiesimple.getGlobalBounds())){
cout<<"Collision 4\n";
hero.recevoirDegats(0.5);
hero.afficherEtat();
}*/
cout<<"Position perosonnage X : "<<sprite_perso.getPosition().x<<"\nPosition personnage Y : "<<sprite_perso.getPosition().y<<"\n";
}
app.clear();
ast.clear();
app.draw(forme);
app.draw(triangle);
app.draw(convex);
app.draw(rect);
app.draw(convex2);
app.draw(sprite_maison1);
app.draw(sprite_ennemiesimple);
app.draw(sprite_perso);
app.draw(afficheS);
app.display();
}
return 0;
}
void gestionClavier(){
/*10 872px par minute*/
if (Keyboard::isKeyPressed(Keyboard::LAlt) && Keyboard::isKeyPressed(Keyboard::Up)){
animation.y = Up;
sprite_perso.move(0, -(speed + 3));
}
else if (Keyboard::isKeyPressed(Keyboard::LAlt) && Keyboard::isKeyPressed(Keyboard::Down)){
animation.y = Down;
sprite_perso.move(0, (speed + 3));
}
else if (Keyboard::isKeyPressed(Keyboard::LAlt) && Keyboard::isKeyPressed(Keyboard::Right)){
animation.y = Right;
sprite_perso.move((speed + 3), 0);
}
else if (Keyboard::isKeyPressed(Keyboard::LAlt) && Keyboard::isKeyPressed(Keyboard::Left)){
animation.y = Left;
sprite_perso.move(-(speed + 10), 0);
}
/*5 778px par minute*/
else if (Keyboard::isKeyPressed(Keyboard::Up))
{
animation.y = Up;
sprite_perso.move(0, -speed);
}
else if (Keyboard::isKeyPressed(Keyboard::Down))
{
animation.y = Down;
sprite_perso.move(0, speed);
}
else if (Keyboard::isKeyPressed(Keyboard::Right))
{
animation.y = Right;
sprite_perso.move(speed, 0);
}
else if (Keyboard::isKeyPressed(Keyboard::Left))
{
animation.y = Left;
sprite_perso.move(-speed, 0);
}
else if (Keyboard::isKeyPressed(Keyboard::E)){
animationEnnemieSimple.y = eUp;
sprite_ennemiesimple.move(0, -speed);
}
else if (Keyboard::isKeyPressed(Keyboard::D)){
animationEnnemieSimple.y = eDown;
sprite_ennemiesimple.move(0, speed);
}
else if (Keyboard::isKeyPressed(Keyboard::F)){
animationEnnemieSimple.x = eLeft;
sprite_ennemiesimple.move(speed, 0 );
}
else if (Keyboard::isKeyPressed(Keyboard::S)){
animationEnnemieSimple.x = eRight;
sprite_ennemiesimple.move(-speed, 0);
}
else if(Keyboard::isKeyPressed(Keyboard::K)){
musique1.pause();
}
else if(Keyboard::isKeyPressed(Keyboard::M)){
musique1.play();
}
else if(Keyboard::isKeyPressed(Keyboard::B)){
hero.changerArme("Baton de la destruction", 9);
cout<<"1kkkkk\n\n";
for(int i = 0; i < 50; i++){
ennemie.recevoirDegats(1);
seconds(1);
}
}
if (sprite_perso.getPosition().x <= 0){
sprite_perso.setPosition(Vector2f(0, sprite_perso.getPosition().y));
}
if (sprite_perso.getPosition().y <= 0){
sprite_perso.setPosition(Vector2f(sprite_perso.getPosition().x, 0));
}
if (Keyboard::isKeyPressed(Keyboard::Home)){
cout<<"ll";
afficheS.setString("LLLLLLLLL");
afficheS.setCharacterSize(100);
}
}
void gestionSourie(){
if(Mouse::isButtonPressed(Mouse::Left)){
position = Mouse::getPosition(app);
cout<<"position x :"<<position.x<<"\nposition y : "<<position.y<<"\n";
int mouseGx = position.x;
int mouseGy = position.y;
sprite_maison1.setPosition(mouseGx, mouseGy);
}
if(Mouse::isButtonPressed(Mouse::Middle)){
position = Mouse::getPosition(app);
int mouseMx = position.x;
int mouseMy = position.y;
sprite_perso.setPosition(mouseMx, mouseMy);
}
if (Mouse::isButtonPressed(Mouse::Right)){
cout<<"Vie du hero : ";
hero.afficherEtat();
cout<<"\n\n\nVie de l'ennemi : ";
ennemie.afficherEtat();
position = Mouse::getPosition(app);
int mouseGx = position.x;
int mouseGy = position.y;
sprite_ennemiesimple.setPosition(mouseGx, mouseGy);
}
}
Donc le problème est que le joystick fait complètement planter le programme quand je le branche même lorsque dans le code il n'y a aucune interaction avec le joystick
Pour rappel, je débute dans la SFML.
Merci de vos réponses