Non il ne s'affiche pas du tout ... :/ l'alpha est à 25 car après je le met à 255 dans une fonction et même à 255 sa ne marche pas :/
Je vous montre le code de toute la class :
General.h
class Batiment
{
public:
Batiment(std::string image, int vie, int type);
void ChargerCaractere(std::string fichier);
bool IsCollideUnite(sf::Sprite unite);
bool Placeable(float x, Terrain *terre);
void Placer(float x, float y, bool placer);
void Afficher(sf::RenderWindow *app, bool visible);
sf::Vector2f GetPosition();
int GetVie();
int GetType();
void Degat(float degat);
sf::Sprite GetSprite();
void AjouterUnite(Unite* uniter, int id);
void RemoveUnite(Unite* uniter, int id);
private:
std::vector<int> unite_in_place;
std::vector<sf::Sprite> sprite_unite;
std::vector<sf::Vector2f> position_unite;
int m_vie, m_viemax, m_type, m_nombre_unite;
bool en_creation, m_placer, m_placeable;
int m_t,curseur;
std::string fichier_image;
sf::Vector2f m_position;
sf::Image image_batiment, image_batimenton, image_batimentoff, m_imagevie;
sf::Sprite *sprite_batiment;
sf::Sprite sprite_batimenton, sprite_batimentoff, m_spritevie;
};
General.cpp
Batiment::Batiment(string image, int vie, int type)
{
m_spritevie = sf::Sprite();
m_placer = false;
m_placeable = false;
m_vie = vie;
m_t = 0;
en_creation = true;
curseur = 0;
m_viemax = vie;
m_type = type;
m_nombre_unite = 0;
m_position = sf::Vector2f(0,0);
if(!image_batiment.LoadFromFile(image.c_str()) || !image_batimenton.LoadFromFile(image.c_str()) || !image_batimentoff.LoadFromFile(image.c_str()) || image.c_str() == "")
{
cout << "Impossible de charger l'image du batiment.." << endl;
}
for(int x(0);x<image_batiment.GetWidth();x++)
for(int y(0);y<image_batiment.GetHeight();y++)
if(image_batiment.GetPixel(x,y).a > 0)
image_batiment.SetPixel(x,y,Color(image_batiment.GetPixel(x,y).r,image_batiment.GetPixel(x,y).g ,image_batiment.GetPixel(x,y).b,25));
for(int x(0);x<90;x++)
for(int y(0);y<image_batimenton.GetHeight();y++)
if(image_batimenton.GetPixel(x,y).a > 0)
image_batimenton.SetPixel(x,y,Color(0,255 ,0,25));
for(int x(0);x<image_batimentoff.GetWidth();x++)
for(int y(0);y<image_batimentoff.GetHeight();y++)
if(image_batimentoff.GetPixel(x,y).a > 0)
{
image_batimentoff.SetPixel(x,y,Color(255,0 ,0,25));
}
image_batiment.SetSmooth(false);
image_batimenton.SetSmooth(false);
image_batimentoff.SetSmooth(false);
sprite_batimenton.SetImage(image_batimenton);
sprite_batiment.SetImage(image_batiment);
sprite_batimentoff.SetImage(image_batimentoff);7
sprite_batiment.SetCenter(image_batiment.GetWidth()/2,image_batiment.GetHeight());
sprite_batiment.SetScale(1.2,1.2);
sprite_batimenton.SetCenter(image_batimenton.GetWidth()/2,image_batimenton.GetHeight());
sprite_batimentoff.SetCenter(image_batimentoff.GetWidth()/2,image_batimentoff.GetHeight());
sprite_batimentoff.SetScale(1.2,1.2);
sprite_batimenton.SetScale(1.2,1.2);
if(!m_imagevie.LoadFromFile("picture/map/vie.png"))
{
cout << "Impossible de charger l'image de la vie du batiment..." << endl;
}
else
{
m_spritevie.SetImage(m_imagevie);
m_spritevie.SetScale(2,2);
}
}
void Batiment::ChargerCaractere(string fichier)
{
ifstream fiche(fichier.c_str());
int pos(0), x(0);
while(!fiche.eof())
{
string mot;
fiche >> mot;
if(pos == 0)
{
m_nombre_unite++;
x = atoi(mot.c_str());
pos = 1;
}
else
{
pos = 0;
position_unite.push_back(sf::Vector2f(x, atoi(mot.c_str())));
cout << position_unite[position_unite.size()-1].y << endl;
}
}
}
bool Batiment::Placeable(float x, Terrain *terre)
{
int y1 = terre->cherTerrain(x+image_batiment.GetWidth()/2,-1);
int y2 = terre->cherTerrain(x-image_batiment.GetWidth()/2,-1);
if(y1-y2 < 20 && y1-y2>-20)
{
m_placeable = true;
return true;
}
else
{
m_placeable = false;
return false;
}
}
bool Batiment::IsCollideUnite(sf::Sprite unite)
{
if(CollisionBoiteSensible(unite, *sprite_batiment) != -1)
{
return true;
}
else
{
return false;
}
}
void Batiment::Placer(float x, float y, bool placer)
{
m_placer = placer;
m_position = sf::Vector2f(x, y);
//m_position = sf::Vector2f(x,terre->cherTerrain(x,-1));
sprite_batiment->SetPosition(m_position);
sprite_batimentoff.SetPosition(m_position);
sprite_batimenton.SetPosition(m_position);
m_spritevie.SetPosition(m_position+Vector2f(-30,-sprite_batiment->GetSize().x - 40));
}
void Batiment::Afficher(sf::RenderWindow *app, bool visible)
{
if(en_creation && m_placer)
{
int tailleX = image_batiment.GetWidth()-1;
int collone = 0;
int random = rand() % tailleX - 1;
int y(0);
int test_complete(0);
for(int i(0); i< image_batiment.GetWidth();i++)
{
int x = i;
y = image_batiment.GetHeight()-curseur-1;
if(!image_batiment.GetPixel(x,y).a == 0)
image_batiment.SetPixel(x,y,Color(image_batiment.GetPixel(x,y).r,image_batiment.GetPixel(x,y).g,image_batiment.GetPixel(x,y).b,255));
}
curseur++;
if(curseur >= image_batiment.GetHeight())
{
en_creation = false;
}
int i(0);/*
for(i=0;i<tailleX;i++)
{
if(image_batiment.GetPixel(i,image_batiment.GetHeight()-curseur+1).a > 200 || image_batiment.GetPixel(i,image_batiment.GetHeight()-curseur+1).a == 0)
{
collone++;
}
}
cout << tailleX << endl;
if(collone >= i)
{
curseur+=2;
cout << curseur << ":" << image_batiment.GetHeight() << ". Colone = " << collone << endl;
if(curseur == image_batiment.GetHeight())
en_creation = false;
}*/
collone = 0;
}
if(visible)
{
for(int i(0);i<sprite_unite.size();i++)
{
app->Draw(sprite_unite[i]);
}
app->Draw(*sprite_batiment);
app->Draw(m_spritevie);
if(!m_placer)
{
if(m_placeable)
app->Draw(sprite_batimenton);
else
app->Draw(sprite_batimentoff);
}
}
}
int Batiment::GetVie()
{
return m_vie;
}
int Batiment::GetType()
{
return m_type;
}
sf::Sprite Batiment::GetSprite()
{
return *sprite_batiment;
}
void Batiment::Degat(float degat)
{
m_vie -= degat;
if(m_vie<0)
m_vie = 0;
float v = m_vie/m_viemax*30;
v--;
m_spritevie.SetImage(m_imagevie);
m_spritevie.SetSubRect(IntRect(0,0,(int)(v),4));
m_spritevie.SetScale(2,2);
}
sf::Vector2f Batiment::GetPosition()
{
return m_position;
}
void Batiment::AjouterUnite(Unite* uniter, int id)
{
if(position_unite.size()>sprite_unite.size())
{
sprite_unite.push_back(sf::Sprite());
sprite_unite[sprite_unite.size()] = uniter->GetSurface();
uniter->SetPosition(m_position+sf::Vector2f(position_unite[0].x,-position_unite[0].y));
uniter->SetInBatiment(true);
unite_in_place.push_back(id);
}
}
void Batiment::RemoveUnite(Unite* uniter, int id)
{
for(int i(0);i<unite_in_place.size();i++)
{
if(unite_in_place[i] == id)
{
unite_in_place.erase(unite_in_place.begin()+i);
sprite_unite.erase(sprite_unite.begin()+i);
}
uniter->SetInBatiment(false);
uniter->SetPosition(m_position);
}
}