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 {
if(score==NOLIFE){ return true;}
else{ return false; }
}
public void resetScore(){
score = LIFE;
}
}
......@@ -388,13 +388,13 @@ public class GameController{
gameDisplay.setBottomScore(scoreBottom);
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
* - reverse the direction
*/
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
* - reverse the direction
......@@ -594,16 +594,12 @@ public class GameController{
endTime = System.currentTimeMillis();
timeElapsed = (endTime-startTime)/1000.0;
System.out.println(timeElapsed);
System.out.println(timeElapsed);
}
private void resetGame(){
scoreTop = 0;
scoreBottom = 0;
player.resetScore();
ai.resetScore();
}
......
......@@ -96,6 +96,9 @@ public class GameView{
public void createGame(){
gameFrame = new JFrame("FaultInOurPong");
gameFrame.setContentPane(ponggame);
gameFrame.setSize(FRAMEWIDTH,FRAMEHEIGHT);
gameFrame.setResizable(false);
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