This is the CLASSIC intro programming project. The idea here is
you are going to make a simple pong game, where a ball will bounce
back and forth when hit by two paddles from each side.
2 paddles, a ball that either hits a paddle and returns, or doesnt.
If it doesnt the game should reset. Up and down is controlled
with with q and a. Keep track of the score.
Rubric - 18 points:
- The paddles move up or down approp (2 point)
- The ball starts at the center and moves in a random direction. (2)
- The ball hits a paddle and bounces off at the appropriate angle
- If it does not hit a paddle it goes off screen (2 point)
- New ball appears if old ball goes off screen, going in random direction (2 point)
- You use 3 classes - one for paddle, ball and Pong (2 points)
- Code in all 3 classes is properly indented, commented, and have
approp variable names. (2 points)
- You keep score, which works properly (2 points)
- Game plays well
Advanced - must do at least 2 of the following (2 points each):
- Ball moves faster as game goes on.
- Limit game to 5 balls and it says who won
- ball moves
faster if hit on edges or when paddle is moving
- better game play in any way you figure out
- 2 controllers at same time
Goal 1 - Get paddles to move up and down.
- In pong, if key
pressed is q then paddle1.moveUp(); if a then paddle1.moveDown().
For this to work, you will need to
- add moveUp and moveDown methods in Paddle.
Goal 2. In Ball
- Add variables int changeInX and also int changeInY. Originally have them random
- Create a method moveBall that will move that ball around the screen. Each frame (in update of Pong) call this method.
- Have it bounce off the top and bottom walls.
- If it goes off screen (left and right) , reset the ball.
- Create a method drawBall(Graphics g) that will draw the ball
Goal 3. Collision
- Each frame (in update of Pong), check to see if you are hitting a paddle
If you are, how sholud the ball change?
- if (myBall.isCollision(leftPaddle)==true) //this means we are hitting the left paddle
1. Fix the game so both users can control their paddles at the same time. Note when you hold down up and then press the a key, the paddle no longer goes up. To do this:
- Create a variable String movingDirection in Paddle that will be either up,down, or nothing.
- In keyPressed, if the key is the up key, we would say paddleRight.movingDirection="up"
- In drawBall, we would say if movingDirection is up, move up
- In keyReleased, if the key released is the up key, we would say paddleRight.movingDirection=""
- Do this for all keys.