mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 07:53:43 +00:00
sliding collision around borders done
This commit is contained in:
parent
fb88128f37
commit
314b58ac4a
@ -44,12 +44,31 @@ void TransformComponent::update()
|
||||
// if(velocity.x != 0 && velocity.y != 0)
|
||||
|
||||
float multiplier = velocity.x != 0 && velocity.y != 0 ? 0.707 : 1; //normalizes vector
|
||||
|
||||
Vector2D newPos(
|
||||
position.x + velocity.x * speed * multiplier,
|
||||
position.y + velocity.y * speed * multiplier
|
||||
);
|
||||
if (newPos.x < 0 || newPos.x + (this->width * this->scale) > SCREEN_SIZE_WIDTH || newPos.y < 0 || newPos.y + (this->height * this->scale) > SCREEN_SIZE_HEIGHT)
|
||||
return;
|
||||
|
||||
if (newPos.x < 0)
|
||||
{
|
||||
newPos.x = 0;
|
||||
}
|
||||
|
||||
if (newPos.x + (this->width * this->scale) > SCREEN_SIZE_WIDTH)
|
||||
{
|
||||
newPos.x = SCREEN_SIZE_WIDTH - (this->width * this->scale);
|
||||
}
|
||||
|
||||
if (newPos.y < 0)
|
||||
{
|
||||
newPos.y = 0;
|
||||
}
|
||||
|
||||
if (newPos.y + (this->height * this->scale) > SCREEN_SIZE_HEIGHT)
|
||||
{
|
||||
newPos.y = SCREEN_SIZE_HEIGHT - (this->height * this->scale);
|
||||
}
|
||||
|
||||
position = newPos;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user