Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
iamSamuelFu committed Mar 1, 2018
1 parent 29457b2 commit 757ad4e
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/edu/ucsb/cs56/projects/games/pong/gameplay/Pong.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,39 @@ public void paddleCollision() { // speed starts out at 1
if( ( b[i].rectangle ).intersects( p1.rectangle ) ){
playPaddleCollisionAudio();
b[i].setXVelocity( -1 * ( b[i].getXVelocity() - moreSpeed ) );
incrementHits();
if((b[i].getYVelocity() >0) && p1.getYVelocity() >0){
b[i].setYVelocity(b[i].getYVelocity()+2);
}
if((b[i].getYVelocity() <0) && p1.getYVelocity() <0){
b[i].setYVelocity(b[i].getYVelocity()-2);
}
if((b[i].getYVelocity() >0) && p1.getYVelocity() <0){
b[i].setYVelocity(b[i].getYVelocity()-2);
}
if((b[i].getYVelocity() <0) && p1.getYVelocity() >0){
b[i].setYVelocity(b[i].getYVelocity()+2);
}
incrementHits();
}

// checks if it hits p2
else if( ( b[i].rectangle ).intersects( p2.rectangle ) ){
playPaddleCollisionAudio();
b[i].setXVelocity( -1 * ( b[i].getXVelocity() + moreSpeed ) );
incrementHits();
if((b[i].getYVelocity() >0) && p1.getYVelocity() >0){
b[i].setYVelocity(b[i].getYVelocity()+2);
}
if((b[i].getYVelocity() <0) && p1.getYVelocity() <0){
b[i].setYVelocity(b[i].getYVelocity()-2);
}
if((b[i].getYVelocity() >0) && p1.getYVelocity() <0){
b[i].setYVelocity(b[i].getYVelocity()-2);
}
if((b[i].getYVelocity() <0) && p1.getYVelocity() >0){
b[i].setYVelocity(b[i].getYVelocity()+2);
}

incrementHits();
}
}
}
Expand Down

0 comments on commit 757ad4e

Please sign in to comment.