Tutorial 20 pt.1:Fart annoyed curious on bool and void
Posted: June 19th, 2019, 6:09 am
Hey man. So I did some experimentation on Fart Annoyed. I made the DoWallCollision into void function instead of bool. Everything is cool but when the ball hits the wall it doesnt rebound, it will display assertion failed. I know the difference between the two functions (bool returns bool values and void returns nothing) but is there something more to them that I miss.
Code: Select all
void Ball::DoWallCollision(const RectF & wall)
{
RectF ballrect = GetRect();
if (ballrect.left < wall.left)
{
pos.x += wall.left-ballrect.left;
vel.x = -vel.x;
}
else if (ballrect.right > wall.right)
{
pos.x -= wall.right - ballrect.right;
vel.x = -vel.x;
}
if (ballrect.top<wall.top)
{
pos.y += wall.top - ballrect.top;
vel.y = -vel.y;
}
else if (ballrect.bottom > wall.bottom)
{
pos.y -= wall.bottom - ballrect.bottom;
vel.y = -vel.y;
}
}