I have a ball sprite and I need it to have a 50/50 chance to bounce off a platform sprite. Here is the code:
bally=bally+3;
ballx=ballx+3;
ballx += xspd;
bally += yspd;
if(bally > 580 && bally <590 && ballx < mouseX+300 && ballx > mouseX-150){
yspd*=-3;
}
else if(bally > 580 && bally <590 && ballx < mouseX+150 && ballx > mouseX){
yspd*=+3;
}
if(ballx > 900){
xspd*=-3;
}
if(ballx < 0){
xspd*=+3;
}
if(bally < 0 && bally > 700){
state=LOSE;
}
This code make the ball bounce off the walls but once it bounces off the platform at the top it only bounces to the right. I need it to be a 50/50 chance to bounce either left or right. Thanks
I tried to make an else if statement before but that didn't work, along with changing the xspd variable in said else if statement.