void checkCollisionWithMap(float Dx, float Dy)
{
for (int i = 0; i < obj.size(); i++)//проходимся по объектам
if (getRect().intersects(obj[i].rect))//проверяем пересечение игрока с объектом
{
if (obj[i].name == "Solid")//если встретили препятствие
{
if (Dy>0) { y = obj[i].rect.top - h; dy = 0; onGround = true; }
if (Dy<0) { y = obj[i].rect.top + obj[i].rect.height; dy = 0; }
if (Dx>0) { x = obj[i].rect.left - w; dx = -0.1; sprite.scale(-1, 1); }
if (Dx<0) { x = obj[i].rect.left + obj[i].rect.width; dx = 0.1; sprite.scale(-1, 1); }
}
if (obj[i].name == "stairs")//если встретили лестницу
{
if (Dy > 0) { y = obj[i].rect.top; dy = 0; }
if (Dy<0) { y = obj[i].rect.top + obj[i].rect.height; dy = 0; }
}
}
}
void control() {
float CurrentFrame = 0;
Clock clock;
float time = clock.getElapsedTime().asMicroseconds();
if (Keyboard::isKeyPressed) {
if (Keyboard::isKeyPressed(Keyboard::Left))
{
state = left;
speed = 0.1;
}
if (Keyboard::isKeyPressed(Keyboard::Right))
{
state = right;
speed = 0.1;
}
if ((Keyboard::isKeyPressed(Keyboard::Up)) && (onGround))
{
state = up;
speed = -0.1;
}
if (Keyboard::isKeyPressed(Keyboard::Down))
{
state = down;
speed = 0.1;
}
}
}