ive been searching far and wide for how to detect collisions with java for a game that im making(pong)... not any other language BUT java... am i on a wild goose chase? i think it must be possible cause i play java games all the time that would have to use collision checking... i was thinking something like this:
public void checkIfBounce(){
if(ball_x-radius==paddle_x+10){ // if ball&paddle are the same x
for(int i=-1;i<40;i++){ // 40 is the paddles length
if(paddle_y+i==ball_y)ballXspeed=-1;
}
}
}
i thought i could call this in the run() methed of an applet to see if the ball and the paddle had made a collision, then the for loop would test each possible position to see if they had contacted, but it doesnt work... anyone know why? if you know how to detect collisions in java or know a site that tells you how, please tell me...
thanks...
public void checkIfBounce(){
if(ball_x-radius==paddle_x+10){ // if ball&paddle are the same x
for(int i=-1;i<40;i++){ // 40 is the paddles length
if(paddle_y+i==ball_y)ballXspeed=-1;
}
}
}
i thought i could call this in the run() methed of an applet to see if the ball and the paddle had made a collision, then the for loop would test each possible position to see if they had contacted, but it doesnt work... anyone know why? if you know how to detect collisions in java or know a site that tells you how, please tell me...
thanks...
Comment