warhammerdude20
03-01-2004, 04:44 PM
i am trying to make a pong game in java and this is the rebound function for the left paddle. now just to set a few variables:
x_pos is the balls x position
y_pos is the balls y position
x_speed is the x speed of the ball
radius is only for the ball and is the balls radius.
paddle1_x you can quess
paddle1_y you can also guess...
now i did not have a radius for my paddles so the paddle streches 40 y down and 10 x in width... so without any further ado, heres the code:
public void bounceToLeft(){
if(x_pos-radius<=paddle1_x+10&&x_pos-radius>=paddle1_x){
if(y_pos<=paddle1_y-40&&y_pos>=paddle1_y){
x_speed=-1;
}
}
}
i call this function in the run method of the applet. does anyone know why it doesnt work?
thanks
x_pos is the balls x position
y_pos is the balls y position
x_speed is the x speed of the ball
radius is only for the ball and is the balls radius.
paddle1_x you can quess
paddle1_y you can also guess...
now i did not have a radius for my paddles so the paddle streches 40 y down and 10 x in width... so without any further ado, heres the code:
public void bounceToLeft(){
if(x_pos-radius<=paddle1_x+10&&x_pos-radius>=paddle1_x){
if(y_pos<=paddle1_y-40&&y_pos>=paddle1_y){
x_speed=-1;
}
}
}
i call this function in the run method of the applet. does anyone know why it doesnt work?
thanks