Skip to content
Snippets Groups Projects
Commit f24706da authored by Jie Luo's avatar Jie Luo
Browse files

bug fixed for the ball not hitting the paddles

parent 548e8beb
No related branches found
No related tags found
No related merge requests found
...@@ -56,4 +56,8 @@ public class Player { ...@@ -56,4 +56,8 @@ public class Player {
if(score==NOLIFE){ return true;} if(score==NOLIFE){ return true;}
else{ return false; } else{ return false; }
} }
public void resetScore(){
score = LIFE;
}
} }
...@@ -388,13 +388,13 @@ public class GameController{ ...@@ -388,13 +388,13 @@ public class GameController{
gameDisplay.setBottomScore(scoreBottom); gameDisplay.setBottomScore(scoreBottom);
ai.decrementLife(); ai.decrementLife();
} else if(ballY+2.5*ballSize>frameHeight-inset-2*padHeight && velY > 0 && ballX + ballSize >= bottomPadX && ballX <= bottomPadX + padWidth){ } else if(ballY+2.5*ballSize>frameHeight-inset-padHeight && velY > 0 && ballX + ballSize >= bottomPadX && ballX <= bottomPadX + padWidth){
/** /**
* If the ball is touching the bottom paddle * If the ball is touching the bottom paddle
* - reverse the direction * - reverse the direction
*/ */
velY = -velY; velY = -velY;
} else if(ballY<=inset+2*padHeight && velY < 0 && ballX + ballSize >= topPadX && ballX <= topPadX + padWidth){ } else if(ballY<=inset+padHeight && velY < 0 && ballX + ballSize >= topPadX && ballX <= topPadX + padWidth){
/** /**
* If the ball is touching the top paddle * If the ball is touching the top paddle
* - reverse the direction * - reverse the direction
...@@ -594,16 +594,12 @@ public class GameController{ ...@@ -594,16 +594,12 @@ public class GameController{
endTime = System.currentTimeMillis(); endTime = System.currentTimeMillis();
timeElapsed = (endTime-startTime)/1000.0; timeElapsed = (endTime-startTime)/1000.0;
System.out.println(timeElapsed); System.out.println(timeElapsed);
} }
private void resetGame(){ private void resetGame(){
scoreTop = 0; player.resetScore();
scoreBottom = 0; ai.resetScore();
} }
......
...@@ -96,6 +96,9 @@ public class GameView{ ...@@ -96,6 +96,9 @@ public class GameView{
public void createGame(){ public void createGame(){
gameFrame = new JFrame("FaultInOurPong"); gameFrame = new JFrame("FaultInOurPong");
gameFrame.setContentPane(ponggame); gameFrame.setContentPane(ponggame);
gameFrame.setSize(FRAMEWIDTH,FRAMEHEIGHT); gameFrame.setSize(FRAMEWIDTH,FRAMEHEIGHT);
gameFrame.setResizable(false); gameFrame.setResizable(false);
gameFrame.setLocationRelativeTo(null); gameFrame.setLocationRelativeTo(null);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment