Skip to content

anonymous /CD.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Collision detection
public void checkCollisions(){
//p1-puck
if(puck.xPos < 450){
if(puck.yPos >= p1.yPos - 20 && puck.yPos <= p1.yPos + 60){
if(puck.xPos <= p1.xPos + 10 && !(puck.xPos <= p1.xPos)){
puck.xPos = p1.xPos + 11;
puck.xSpeed = -puck.xSpeed;
}else if(puck.xPos >= p1.xPos - 20 && !(puck.xPos + 20 >= p1.xPos + 10)){
puck.xPos = p1.xPos - 21;
puck.xSpeed = -puck.xSpeed;
}
}
//p2-puck
}else if(puck.yPos >= p2.yPos - 20 && puck.yPos <= p2.yPos + 60){
if(puck.xPos >= p2.xPos - 20 && !(puck.xPos + 20 >= p2.xPos + 10)){
puck.xPos = p2.xPos - 21;
puck.xSpeed = -puck.xSpeed;
}else if(puck.xPos <= p2.xPos + 10 && !(puck.xPos <= p2.xPos)){
puck.xPos = p2.xPos + 11;
puck.xSpeed = -puck.xSpeed;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.