Alors oui j'ai toujours mon problème et après moult-moult essais je décide donc de poster mon code entier ( je prévient il est long
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
unsigned int a = 100;
unsigned int blasteur = 0;
unsigned int missi = 0;
unsigned int blas = 0;
unsigned int col = 1 ;
unsigned int yo = 0;
unsigned int vie1 = 100;
unsigned int vie2 = 100;
unsigned int vie3 = 100;
unsigned int vie4 = 100;
unsigned int move1 = 0;
unsigned int move2 = 0;
unsigned int move3 = 0;
int movez = 0;
unsigned int point;
string poin;
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "[1.0] SPACE");
sf::RectangleShape Rect_health;
///Image de fond.///////////////////////////////////////////////
sf::Sprite backg;
sf::Texture background;
background.loadFromFile("back.png");
backg.setTexture(background);
///Image du ship/////////////////////////////////////////
sf::Sprite ship;
sf::Texture shi;
shi.loadFromFile("sh.png");
ship.setTexture(shi);
ship.setPosition(380, 440);
///barre de vie///////////////////////////////////////
sf::Sprite vie;
sf::Texture viee;
viee.loadFromFile("barre.png");
vie.setTexture(viee);
vie.setPosition(0, 576);
///barre du minigun///////////////////////////////////
sf::Sprite minigun;
sf::Texture minigu;
minigu.loadFromFile("minigun.png");
minigun.setTexture(minigu);
minigun.setPosition(600, 540);
///Barre du missile////////////////////////////////
sf::Sprite missile;
sf::Texture miss;
miss.loadFromFile("missile.png");
missile.setTexture(miss);
missile.setPosition(670, 540);
///image du vso enemie 1 ////////////////////////////////////
sf::Sprite obs;
sf::Texture obst;
obst.loadFromFile("en1.png");
obs.setTexture(obst);
obs.setPosition(130, 330);
///image du vso enemie 2 /////////////////////////////////////
sf::Sprite vso2;
sf::Texture vso;
vso.loadFromFile("en2.png");
vso2.setTexture(vso);
vso2.setPosition(230, 330);
///image du vso enemie 3 /////////////////////////////////////
sf::Sprite vso3;
sf::Texture v;
v.loadFromFile("en3.png");
vso3.setTexture(v);
vso3.setPosition(530, 330);
///image de la limite (bas)
sf::Sprite limite;
sf::Texture lim;
lim.loadFromFile("limite.png");
limite.setTexture(lim);
limite.setPosition(0, 530);
///image de la limite (gauche)
sf::Sprite limite2;
sf::Texture lim2;
lim2.loadFromFile("limite2.png");
limite2.setTexture(lim2);
limite2.setPosition(0, 0);
///image de la limite (droite)
sf::Sprite limite3;
sf::Texture lim3;
lim3.loadFromFile("limite3.png");
limite3.setTexture(lim3);
limite3.setPosition(799, 0);
///image de la limite (haut)
sf::Sprite limite4;
sf::Texture lim4;
lim4.loadFromFile("limite4.png");
limite4.setTexture(lim4);
limite4.setPosition(0,1);
///initialisation des blasteur Allier/////////
sf::Sprite blat;
sf::Texture blas;
///initialisation du missile//////////
sf::Sprite mis;
sf::Texture ms;
///initialisation du blasteur enemie 1 /////////////
sf::Sprite be;
sf::Texture bes;
bes.loadFromFile("balle.png");
be.setTexture(bes);
be.setPosition(obs.getPosition().x, obs.getPosition().y);
///initialisation du blasteur enemie 2 ///////
sf::Sprite be2;
sf::Texture bes2;
bes2.loadFromFile("balle2.png");
be2.setTexture(bes2);
be2.setPosition(vso2.getPosition().x, vso2.getPosition().y);
///initialisation du blasteur enemie 2 //////////////
sf::Sprite be3;
sf::Texture bes3;
bes3.loadFromFile("balle3.png");
be3.setTexture(bes3);
be3.setPosition(vso3.getPosition().x, vso3.getPosition().y);
///initialisation du game over/////////////////////
sf::Sprite Game;
sf::Texture Over;
Over.loadFromFile("game.png");
///initialisation du cercle///////////////////////
sf::Sprite cercle;
sf::Texture cercl;
cercl.loadFromFile("cercle.png");
std::ostringstream out;
out << yo;
std::string test = yo.str();
sf::Font font;
font.loadFromFile("of.ttf");
sf::Text pts;
pts.setFont(font);
pts.setString(yo);
pts.setColor(sf::Color::Yellow);
pts.setCharacterSize(20);
pts.setPosition(340,572);
///.///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///.////////////////////////////////////////////////////////////////////////////////////////////////////////
///Boucle ...//////////////////////////////
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
sf::FloatRect o = obs.getGlobalBounds();
sf::FloatRect s = ship.getGlobalBounds();
sf::FloatRect blaste = blat.getGlobalBounds();
sf::FloatRect mini = minigun.getGlobalBounds();
sf::FloatRect rocket = missile.getGlobalBounds();
sf::FloatRect Crc = cercle.getGlobalBounds();
sf::FloatRect misss = mis.getGlobalBounds();
sf::FloatRect bal = be.getGlobalBounds();
sf::FloatRect bal2 = be2.getGlobalBounds();
sf::FloatRect bal3 = be3.getGlobalBounds();
sf::FloatRect lim = limite.getGlobalBounds();
sf::FloatRect lim2 = limite2.getGlobalBounds();
sf::FloatRect lim3 = limite3.getGlobalBounds();
sf::FloatRect lim4 = limite4.getGlobalBounds();
sf::FloatRect vs2 = vso2.getGlobalBounds();
sf::FloatRect vs3 = vso3.getGlobalBounds();
///Choie des armes//////////////////////////
if ((sf::Keyboard::isKeyPressed(sf::Keyboard::A)) )
{
cercle.setPosition(598, 540);
cercle.setTexture(cercl);
}
if ((sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) )
{
cercle.setPosition(668, 540);
cercle.setTexture(cercl);
}
///.//////////////////////////////////////////////
///Deplacement du vaisseau vers la Gauche//////////////////////////
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
ship.move(sf::Vector2f(-0.04,0)) ;
}
///Deplacement du vaisseau vers la Droite//////////////////////////
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
ship.move(sf::Vector2f(0.04,0)) ;
}
///./////////////////////////////////////////////////////////////////////////////////////////////////
///Vaisseau intersect obstacle////////////////////////
if ((s.intersects(bal)) | (s.intersects(bal2)))
{
ship.move(sf::Vector2f(0,0.9)) ;
a = a - 5;
}
///La vie du vaisseau//////////////////////////
double size_health = a/100.0 * 200.0;
Rect_health.setSize(sf::Vector2f(-size_health, 9));
Rect_health.setPosition(210, 581);
Rect_health.setFillColor(sf::Color(0, 255, 0, 100));
if ( a == 0 )
{
Game.setTexture(Over);
Game.setPosition(200, 200);
movez = 1;
}
///Affichage du blasteur///////////////////////////////////////////
if ((sf::Mouse::isButtonPressed(sf::Mouse::Left)) &&((Crc.intersects(mini))))
{
blat.setPosition(ship.getPosition().x, ship.getPosition().y);
blas.loadFromFile("bullet.png");
blat.setTexture(blas);
blasteur = 1;
}
///affichage du missile////////////////////////////////////////////
if ((sf::Mouse::isButtonPressed(sf::Mouse::Left)) &&((Crc.intersects(rocket))))
{
mis.setPosition(ship.getPosition().x, ship.getPosition().y);
ms.loadFromFile("rock.png");
mis.setTexture(ms);
missi = 1;
}
///deplacement du tir blasteur//////////////////////////////
if ((blasteur == 1) | (sf::Mouse::isButtonPressed(sf::Mouse::Left)))
{
blat.move(sf::Vector2f(0,-0.035));
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Right))
{
blat.move(sf::Vector2f(0,0));
blasteur = 0;
}
///deplacement de tir missile///////////////////////////////
if ((missi == 1) | (sf::Mouse::isButtonPressed(sf::Mouse::Left)))
{
mis.move(sf::Vector2f(0,-0.02));
}
///Deplacement du blast enemie/////////////////////////////
if ( col == 1)
{
be.move(sf::Vector2f(0,0.04));
be2.move(sf::Vector2f(0,0.04));
be3.move(sf::Vector2f(0,0.04));
}
///colistion vso 1 blasteur////////////////////////////////
if (blaste.intersects(o))
{
vie1 = vie1 - 50;
//cout << vie1 << endl;
blat.setPosition(ship.getPosition().x, ship.getPosition().y);
}
///colistion vso 2 blasteur////////////////////////////////
if (blaste.intersects(vs2))
{
vie2 = vie2 - 50;
//cout << vie2 << endl;
blat.setPosition(ship.getPosition().x, ship.getPosition().y);
}
///colistion vso 3 blasteur////////////////////////////////
if (blaste.intersects(vs3))
{
vie3 = vie3 - 50;
//cout << vie3 << endl;
blat.setPosition(ship.getPosition().x, ship.getPosition().y);
}
///colistion vso 1 missile////////////////////////////////
if (misss.intersects(o))
{
vie1 = vie1 - 100;
//cout << vie1 << endl;
mis.setPosition(ship.getPosition().x, ship.getPosition().y);
}
///colistion vso 2 missile////////////////////////////////
if (misss.intersects(vs2))
{
vie2 = vie2 - 100;
// cout << vie2 << endl;
mis.setPosition(ship.getPosition().x, ship.getPosition().y);
}
///colistion vso 3 missile////////////////////////////////
if (misss.intersects(vs3))
{
vie3 = vie3 - 100;
//cout << vie3 << endl;
mis.setPosition(ship.getPosition().x, ship.getPosition().y);
}
///colision limite 1////////////////////////
if ((bal.intersects(lim)) | (bal.intersects(s)))
{
be.setPosition(obs.getPosition().x, obs.getPosition().y);
}
if (((bal2.intersects(lim))) | (bal2.intersects(s)))
{
be2.setPosition(vso2.getPosition().x, vso2.getPosition().y);
}
if (((bal3.intersects(lim))) | (bal3.intersects(s)))
{
be3.setPosition(vso3.getPosition().x, vso3.getPosition().y);
}
///./////////////////////////////////////////////
///colision limite 2/////////////////////////////
if (o.intersects(lim2))
{
move1 = 0;
}
if (vs2.intersects(lim2))
{
move2 = 0;
}
if (vs3.intersects(lim2))
{
move3 = 0;
}
///colision limite droite/////////////////////////
if (o.intersects(lim3))
{
move1 = 1;
}
if (vs2.intersects(lim3))
{
move2 = 1;
}
if (vs3.intersects(lim3))
{
move3 = 1;
}
///deplacement des vso enemie vers la droite
if ( move1 == 0 )
{
obs.move(sf::Vector2f(0.03,0));
}
if ( move2 == 0 )
{
vso2.move(sf::Vector2f(0.03,0));
}
if ( move3 == 0 )
{
vso3.move(sf::Vector2f(0.03,0));
}
///deplacement des vso enemie vers la gauche
if ( move1 == 1)
{
obs.move(sf::Vector2f(-0.03,0));
}
if ( move2 == 1)
{
vso2.move(sf::Vector2f(-0.03,0));
}
if ( move3 == 1)
{
vso3.move(sf::Vector2f(-0.03,0));
}
if (movez == 1)
{
col =5;
move1 = 3;
move2 = 3;
move3 = 3;
blasteur = 3;
missi = 3;
obs.move(sf::Vector2f(0,0));
vso2.move(sf::Vector2f(0,0));
vso3.move(sf::Vector2f(0,0));
}
///./////////////////////////////////
if (s.intersects(lim))
{
ship.setPosition(ship.getPosition().x, 440);
}
///limite droite pour ship
if (s.intersects(lim3))
{
ship.setPosition(745,440);
}
///Limite gauche pour ship
if (s.intersects(lim2))
{
ship.setPosition(5,440);
}
///.///////////////////////////////////////////////////////////////////////////////////
///vie des vso///////////////////////////////////////////////////////////////////
///.///////////////////////////////////////////////////////////////////////////////////
///VIE DU VSO1 ////////////////////////////
if ( vie1 == 0 )
{
int randX = rand() % 750;
int randY = rand() % 350;
obs.setPosition(randX, randY);
vie1 = 100;
yo = yo + 1;
cout << yo << endl;
std::ostringstream out;
}
///VIE DU VSO 2 /////////////////////////////
if ( vie2 == 0 )
{
int randX2 = rand() % 750;
int randY2 = rand() % 350;
vso2.setPosition(randX2, randY2);
vie2 = 100;
yo = yo + 1;
cout << yo << endl;
std::ostringstream out;
}
///VIE DU VSO 3 ///////////////////////////
if ( vie3 == 0 )
{
int randX3 = rand() % 750;
int randY3 = rand() % 350;
vso3.setPosition(randX3, randY3);
vie3 = 100;
yo = yo + 1;
cout << yo << endl;
std::ostringstream out;
}
window.clear();
window.draw(backg);
window.draw(ship);
window.draw(vie);
window.draw(obs);
window.draw(minigun);
window.draw(missile);
window.draw(mis);
window.draw(limite);
window.draw(limite2);
window.draw(limite3);
window.draw(limite4);
window.draw(be);
window.draw(be2);
window.draw(be3);
window.draw(vso2);
window.draw(vso3);
window.draw(blat);
window.draw(pts);
window.draw(cercle);
window.draw(Game);
window.draw(Rect_health);
window.display();
}
}
Vue la longueur de code je pense que peut de monde vont si attarder, si quelque personne le fond je leurs dit un grand merci d'avance.
Pour les courageux, je suis sous code-block 13.12 avec le compilateur de défaut