would this work

Feb 23, 2012 at 3:57am
okay i have made some collision code for pong but when i test it my pong crashes just as it opens and it had no error codes so i dont't know how to google a solution to the problem thus i am un able to work out where i went wrong so i need a hand in locating the problem, i must of done something wrong for it to crash but i cant see what i did. Here is the code i made for the collision.

Why does programming have to be so hard to understand >.<


{
if(rightpaddle_x >= mballx && rightpaddle_x <= (mballx + ball_width) ||
(rightpaddle_x + paddle_width ) >= mballx && (rightpaddle_x + paddle_width ) <= (mballx + ball_width))

if(rightpaddle_y >= mbally && rightpaddle_y <= ( mbally + ball_length) ||
(rightpaddle_y + paddle_length) >= mbally && (rightpaddle_y + paddle_length) <= ( mbally +ball_length))
//The ball and paddle appear to overlap.
return true;
//The ball and the paddle appear to NOT overlap:
return false;
}




thats the collision code and if you want a list of the varriables i use here they are

float backgroundx = 0;
float backgroundy = 0;
float mballx = 492; // 'M' stand for metroid.
float mbally = 384;
float ballxspeed = 4;
float ballyspeed = 2;
float rightpaddle_1x = 990;
float rightpaddle_1y = 20;
float leftpaddle_2x = 15;
float leftpaddle_2y = 450;
float ballrside = mballx + 40;
float position = 0;
float paddle_width = 5;
float paddle_length = 15;
float ball_width = 2.5;
float ball_length = 5;
Feb 23, 2012 at 5:44am
Can't you just test your collision function with a bunch of data to see if it works? The code you have posted will not be able to crash the program by itself. Best is to run your program through a debugger to see what is going wrong.
Feb 23, 2012 at 8:54am
i am running though the debugger in VS 2010 and it contains no errors just crashes. well it opens for a couple of second then ends and i cant locate the error cause none of the code is wrong in a sense....i might have something terminating or doing something it shouldn't do but its not telling me so i am at a loss as to what i should do and it only started to crash after i added this code....so the it has to be in there.
Last edited on Feb 23, 2012 at 8:55am
Feb 23, 2012 at 11:18am
Are you sure the program crashes? Couldn't it be that the program terminates normally by returning from main or calling std::exit?
Feb 23, 2012 at 10:08pm
i cant locate any reason why it would terminate, i guess there is a line of code that is doing but i cant see where >.<
Topic archived. No new replies allowed.