From 95efc66d2b4907204508602757454db1218afa5a Mon Sep 17 00:00:00 2001 From: Samuel Fu Date: Tue, 13 Mar 2018 15:14:26 -0700 Subject: [PATCH] fixed #72 --- .../projects/games/pong/gameplay/Ball.java | 21 ++++++++++++------- .../projects/games/pong/highscore/scores.csv | 3 ++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/edu/ucsb/cs56/projects/games/pong/gameplay/Ball.java b/src/edu/ucsb/cs56/projects/games/pong/gameplay/Ball.java index 58b443d..14cac6b 100644 --- a/src/edu/ucsb/cs56/projects/games/pong/gameplay/Ball.java +++ b/src/edu/ucsb/cs56/projects/games/pong/gameplay/Ball.java @@ -123,12 +123,12 @@ public void holdBallToPaddle(KeyEvent evt, double distance) setAttached(true); setSpeedX(getXVelocity()); - if(evt.getKeyCode() == KeyEvent.VK_A && ( (int)(distance+50) < (DifficultyLevel.getPaddleHeight()) ) ) { + if(evt.getKeyCode() == KeyEvent.VK_A && ( (int)(distance+35) < (DifficultyLevel.getPaddleHeight()) ) ) { stopBall(); paddle = false; } - if(evt.getKeyCode() == KeyEvent.VK_LEFT && ( (int)(distance+40) <(DifficultyLevel.getPaddleHeight()) )) { + if(evt.getKeyCode() == KeyEvent.VK_LEFT && ( (int)(distance+45) <(DifficultyLevel.getPaddleHeight()) )) { stopBall(); paddle = true; } @@ -153,7 +153,7 @@ public void releaseBallFromPaddle(KeyEvent evt, double distance) { //attached = false; setAttached(false); - if(evt.getKeyCode() == KeyEvent.VK_A && ( (int)(distance+50) < DifficultyLevel.getPaddleHeight() ) ) { + if(evt.getKeyCode() == KeyEvent.VK_A && ( (int)(distance+35) < DifficultyLevel.getPaddleHeight() ) ) { setYVelocity(p1.getYVelocity()); if(getSpeedX() < 0) setXVelocity(getSpeedX() * -1); @@ -161,7 +161,7 @@ public void releaseBallFromPaddle(KeyEvent evt, double distance) setXVelocity(getSpeedX()); } - if(evt.getKeyCode() == KeyEvent.VK_LEFT && ( (int)(distance+40) < DifficultyLevel.getPaddleHeight() ) ) { + if(evt.getKeyCode() == KeyEvent.VK_LEFT && ( (int)(distance+45) < DifficultyLevel.getPaddleHeight() ) ) { setYVelocity(p2.getYVelocity()); if(getSpeedX() > 0) setXVelocity(getSpeedX() * -1); @@ -175,7 +175,7 @@ public void releaseBallFromPaddle(KeyEvent evt, double distance) * @param distance ArrayList of distances from balls */ public void keyPressed(KeyEvent evt, ArrayList distance){ - if ( (evt.getKeyCode() == KeyEvent.VK_A) && ( distance.get(0) < DifficultyLevel.getPaddleHeight()) && (isAttached() == false)) { + if ( (evt.getKeyCode() == KeyEvent.VK_A) && ( (int)(distance.get(0)+35) < DifficultyLevel.getPaddleHeight()) && (isAttached() == false)) { holdBallToPaddle(evt, distance.get(0)); } if(paddle == false && isAttached() == true){ @@ -186,10 +186,13 @@ public void keyPressed(KeyEvent evt, ArrayList distance){ if( evt.getKeyCode() == KeyEvent.VK_S && distance.get(2) > 5){ setYVelocity(p1.getYVelocity()); } - } + }else{ + setYVelocity(0); + } + } - if (evt.getKeyCode() == KeyEvent.VK_LEFT && distance.get(1)< DifficultyLevel.getPaddleHeight() && isAttached() == false) { + if (evt.getKeyCode() == KeyEvent.VK_LEFT && (int)(distance.get(1)+45)< DifficultyLevel.getPaddleHeight() && isAttached() == false) { holdBallToPaddle(evt, distance.get(1)); } if(paddle == true && isAttached() == true){ @@ -200,7 +203,9 @@ public void keyPressed(KeyEvent evt, ArrayList distance){ if( evt.getKeyCode() == KeyEvent.VK_DOWN && distance.get(3) > 5 ){ setYVelocity(p2.getYVelocity()); } - } + } else{ + setYVelocity(0); + } } } diff --git a/src/edu/ucsb/cs56/projects/games/pong/highscore/scores.csv b/src/edu/ucsb/cs56/projects/games/pong/highscore/scores.csv index 76cd5b6..f12c09a 100644 --- a/src/edu/ucsb/cs56/projects/games/pong/highscore/scores.csv +++ b/src/edu/ucsb/cs56/projects/games/pong/highscore/scores.csv @@ -4,6 +4,7 @@ 57,V 50,Richard 32,ProfessorOak +14, 12,mee 9,Cloud Strife 9,Andrew YEAH @@ -16,4 +17,4 @@ 2,Caitsith 1,Victoria 0,sam -15, +261,