/* the ball is a quad and each corner is set like this-
ballubl = Ball Up Bottom Left (up being the direction)
ballubr = Ball Up Bottom Right
ballutr = Ball Up Top Right
ballutl = Ball Up Top Left
*/
ballubl = ballubl + 0.2; // MOVE THE BALL UP
ballubr = ballubr + 0.2;
ballutr = ballutr + 0.2;
ballutl = ballutl + 0.2;
if (ballutl = 6.0)
ballubl = ballubl - 0.2; // IF THE BALL HEIGHT IS 6.0 MOVE DOWN
ballubr = ballubr - 0.2;
ballutr = ballutr - 0.2;
ballutl = ballutl - 0.2;
This doesn''t work.. I understand why. but If I try
if (ballutl<=6.0)
{
ballubl = ballubl + 0.2; // MOVE THE BALL UP
ballubr = ballubr + 0.2;
ballutr = ballutr + 0.2;
ballutl = ballutl + 0.2;
}
if (ballutl==6.0)
{
ballubl = ballubl - 0.2; // MOVE THE BALL DOWN
ballubr = ballubr - 0.2;
ballutr = ballutr - 0.2;
ballutl = ballutl - 0.2;
}
After I put this in all all looks fine but because I put in if(ballutl<=6.0) the less than sign (<) makes the ball get bounce up and down at the top because as soon as it goes below 6.0 it tries going back up
Can anybody help please
Thanks In Advance
Alan
IF YA SMELL... WHAT THE BEZZ IS COOKIN''''
Bouncing Problem
I have been making a pong game... but I have tried adding the code that bounces the ball of the walls but I have an idea of how it will work but the code I put in don''t! heres a snippet
"if (ballutl = 6.0)" is an assign statement not a comparison
BTW i dont recommend dont comparissions with floating point numbers (rounding errors)
u prolly wanna do someit like so
stick this in the init function
ball_velocity.y = 0.2;
then each movement loop do this
if (pos_pos.y < 0.0)
ball_velocity.y = 0.2;
if (pos_pos.y >= 6.0)
ball_velocity.y = -0.2;
and to move the ball go
ball_pos.y += ball_velocity.y;
http://members.xoom.com/myBollux
BTW i dont recommend dont comparissions with floating point numbers (rounding errors)
u prolly wanna do someit like so
stick this in the init function
ball_velocity.y = 0.2;
then each movement loop do this
if (pos_pos.y < 0.0)
ball_velocity.y = 0.2;
if (pos_pos.y >= 6.0)
ball_velocity.y = -0.2;
and to move the ball go
ball_pos.y += ball_velocity.y;
http://members.xoom.com/myBollux
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement