Bonsoir,
J'essaye de recréer un bomberman histoire de bien maîtriser la SFML, mais je coince au niveau des collisions..
J'ai une classe Map et Case et dans Map je dispose d'un vector[Y][X] de case, chaque cases prend en paramètre un type, 0 = bloc, 1 = mur, 2=herbe tous ça lut grâce à un fichier .txt
Mais lorsque je test les collisions, le rect de mon perso et de la case sa ne marche pas...
IntRect Case::GetBoundingBox() const
{
IntRect box;
box.left = (int)Get_Position(_type).x;
box.top = (int)Get_Position(_type).y;
box.width = 30;
box.height = 30;
return box;
}
IntRect Player::GetBoundingBox() const
{
IntRect rect;
rect.left = (int)vel.x+1;
rect.top = (int)vel.y;
rect.width = 20;
rect.height = 28;
return rect;
}
bool Player::collision()
{
if(bouger)
{
int idY = GetBoundingBox().top / 30; // grâce à ça je peut connaitre la case en Y de mon perso
int idX = GetBoundingBox().left / 30; // ici en X
cout << _map->Get_Type(idY, idX) << endl;
if(_map->Get_Type(idY, idX) == 0 || 1)
{
if(GetBoundingBox().left <= _map->GetBoundingBox(idY, idX).left + _map->GetBoundingBox(idY, idX).width)
return true;
}
}
return false;
}