From 757ad4e9892d8d38eb6f79b8297b3f002bcfd18d Mon Sep 17 00:00:00 2001 From: Samuel Fu Date: Wed, 28 Feb 2018 21:10:01 -0800 Subject: [PATCH] fix #92 --- .../projects/games/pong/gameplay/Pong.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/edu/ucsb/cs56/projects/games/pong/gameplay/Pong.java b/src/edu/ucsb/cs56/projects/games/pong/gameplay/Pong.java index 972d8ed..09269e5 100644 --- a/src/edu/ucsb/cs56/projects/games/pong/gameplay/Pong.java +++ b/src/edu/ucsb/cs56/projects/games/pong/gameplay/Pong.java @@ -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(); } } }