The Partridge Family were neither partridges nor a family. Discuss.
-
dawg_duggart
- Posts: 2
- Joined: June 19th, 2019, 5:42 am
Post
by dawg_duggart » 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;
}
}
-
albinopapa
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Post
by albinopapa » June 19th, 2019, 4:55 pm
What is the message for the assertion or what condition causes the assertion?
Functions that have a return type other than void such as bool should return a value ( true or false in this case ) that you can assign to a variable or use directly such as [ if( ball.DoWallCollision( wall ) ) ] and functions that have a return type of void cannot return a value and must be called on their own. You cannot assign void to variable nor can you create a void type variable.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
-
dawg_duggart
- Posts: 2
- Joined: June 19th, 2019, 5:42 am
Post
by dawg_duggart » June 20th, 2019, 2:20 pm
My mistake man. I rewrite the code on my own from the beginning of the tutorial and everything is fine now. I think the error has something to do with the "Retarget Project" because I think I forgot to do that on my previous try. Anyway thanks man