diff --git a/.idea/misc.xml b/.idea/misc.xml index 1ce6e7f..d15472f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/out/production/final/Ball.class b/out/production/final/Ball.class new file mode 100644 index 0000000..6b6d60b Binary files /dev/null and b/out/production/final/Ball.class differ diff --git a/out/production/final/GameFrame.class b/out/production/final/GameFrame.class new file mode 100644 index 0000000..1c47018 Binary files /dev/null and b/out/production/final/GameFrame.class differ diff --git a/out/production/final/GamePanel.class b/out/production/final/GamePanel.class new file mode 100644 index 0000000..044ca3c Binary files /dev/null and b/out/production/final/GamePanel.class differ diff --git a/out/production/final/GenericObject.class b/out/production/final/GenericObject.class new file mode 100644 index 0000000..8d4a782 Binary files /dev/null and b/out/production/final/GenericObject.class differ diff --git a/out/production/final/Main.class b/out/production/final/Main.class new file mode 100644 index 0000000..aa9ef20 Binary files /dev/null and b/out/production/final/Main.class differ diff --git a/out/production/final/Paddle.class b/out/production/final/Paddle.class new file mode 100644 index 0000000..18d0f6d Binary files /dev/null and b/out/production/final/Paddle.class differ diff --git a/save.txt b/save.txt new file mode 100644 index 0000000..af1e489 --- /dev/null +++ b/save.txt @@ -0,0 +1 @@ +4 2 \ No newline at end of file diff --git a/src/Paddle.java b/src/Paddle.java deleted file mode 100644 index 1e396e2..0000000 --- a/src/Paddle.java +++ /dev/null @@ -1,82 +0,0 @@ -/* Eric Li, ICS4U, Completed 5/29/2022 - -Paddle class defines behaviours for the left and right player-controlled paddles */ - -import java.awt.*; -import java.awt.event.KeyEvent; - -public class Paddle extends GenericObject { - public final int SPEED = 5; - public static final int PADDLE_WIDTH = 8; - public static final int PADDLE_HEIGHT = 80; - public int upKey, downKey; - public Paddle(int x, int y, int upKey, int downKey) { - super(x, y, PADDLE_WIDTH, PADDLE_HEIGHT); - this.upKey = upKey; - this.downKey = downKey; - } - - // this is private because it's only intended to be called from checkCollision - // this checks whether the ball has collided with the paddle in either the 'L' or the 'R' direction, and returns a boolean - private boolean hasCollided(Ball ball, char direction) { - // while this.x and this.y were not needed, they were added to prevent confusion with ball.x and ball.y - if ((Math.abs(ball.x - this.x - this.xVelocity) <= Paddle.PADDLE_WIDTH && direction == 'L' && Math.signum(ball.xVelocity) == -1.0) || - (Math.abs(ball.x - this.x - this.xVelocity) <= Ball.BALL_DIAMETER && direction == 'R' && Math.signum(ball.xVelocity) == 1.0)) { - return (this.y - ball.y <= Ball.BALL_DIAMETER && this.y - ball.y >= 0) || - (ball.y - this.y <= Paddle.PADDLE_HEIGHT && ball.y - this.y >= 0); - } - return false; - } - - // this uses hasCollided() to check if a collision has happened; if it has, the xDirection is reversed and the speed is changed - // returns a boolean which is used for sanity checking in GamePanel.checkCollision() - public boolean checkCollision(Ball ball, char direction) { - if (hasCollided(ball, direction)) { - // reverse x direction and add a portion of paddle speed - // also adds random spray - ball.yVelocity += this.yVelocity / 4 + (int)(Math.random() * 3 - 1); - ball.xVelocity = -(ball.xVelocity) + (int)(Math.random() * 3 - 1); - return true; - } - return false; - } - - // moves paddle when key is pressed - public void keyPressed(KeyEvent e) { - if(e.getKeyCode() == upKey){ - setYDirection(SPEED*-1); - move(); - } - if(e.getKeyCode() == downKey){ - setYDirection(SPEED); - move(); - } - } - - // stops moving paddle when key is released - public void keyReleased(KeyEvent e) { - if(e.getKeyCode() == upKey){ - setYDirection(0); - move(); - } - if(e.getKeyCode() == downKey){ - setYDirection(0); - move(); - } - } - - // calls parent then does sanity checking to ensure that the paddle does not leave the screen - public void move() { - super.move(); - // collisions logic for paddles to prevent them from going into the borders - if (y + PADDLE_HEIGHT + 5 > GamePanel.GAME_HEIGHT) { - y = GamePanel.GAME_HEIGHT - PADDLE_HEIGHT - 5; - } else if (y < 5) { - y = 5; - } - } - public void draw(Graphics g) { - g.setColor(Color.WHITE); - g.fillRect(x, y, PADDLE_WIDTH, PADDLE_HEIGHT); - } -} \ No newline at end of file