class logo

CS 122 - Assignment 2

Pong: We're beginning to get a little more comfortable with Scratch now and can implement classic arcade games. Pong was one of the earliest arcade games, and is fairly straightforward to implement.

Here's my solution for this assignment. Note that as with all assignments, my version is not the only way to do it!

solution.sb

Posted Wednesday, July 29

Your Scratch project should do the following things:

  • Have a ball that flies back and forth, paddles on the left and right sides of the stage, goals behind the paddles, and a scorekeeper who reports the score. See the screenshot below for one example of a way to put it together.
  • The left player should be controlled by the 'w' and 's' key. When 'w' is hit, the paddle should move up the screen 10 pixels, and when the 's' key is hit, the paddle should move down the screen 10 pixels.
  • The right player should be controlled in much the same way, except use the 'up arrow' and 'down arrow keys'.
  • When the green flag is clicked, the paddles should be centered and the ball moved to the center of the stage. Nothing then happens until the space bar is hit, which puts the ball in play.
  • The ball should fly back and forth, bouncing realistically off the paddles and the top and bottom of the screen. If it makes it past one of the paddles and touches the goal area, the opposite player scores a point, and the ball and paddles are reset until the space bar is pressed again.
  • Determining the bounce logic is a little bit difficult. You should have the ball move by moving a few pixels inside a "repeat loop". I suggest using a "repeat until" loop, that will stop when a goal is scored. Inside the loop, the ball should check to see if it is touching a paddle or the edge. To bounce realistically off of a paddle, the ball should point in a new direction that is 360 minus its current direction. If you want to throw in a bit of randomness as well, you can.
  • When a goal is scored, the ref should announce that fact by saying who scored. There should also be score displays somewhere on the stage (check the checkbox next to the variable that holds a score to have it displayed on the stage.

screenshot of what the field might look like

Note that you don't need to copy my playing field or paddles exactly, it is just one idea of how they might be done.

Add the ability to watch a replay of the last point when the user hits the 'r' key between points. The replay should show the movement of the paddles as well as the ball, and should alter the look of the background slightly so it is obvious that we are watching a replay. After the replay is finished, the ball should be reset and the background should go back to normal.

Implement a non-square paddle with more realistic bouncing. A curved paddle would allow control over the angle that the ball returns to in theory add a bit more skill to the game.

Submit your Scratch project file implementing the pong game.

This assignment is due Monday, July 27th, at 7:00 am

Use this form to submit your completed assignment. You can submit an assignment multiple times, and I will generally only look at the last submission. If you do submit more than once, make sure that each submission is complete on its own and doesn't rely on something you submitted previously.

Student number (no dashes):
This is the 9-digit number on your student body card. It probably starts 950 or 951 and it looks something like this: 950123456. This number is used to identify your submission so please enter it carefully.
Name (first and last):
Email address:
Notes about this assignment:
Use the notes field to mention if you worked in a group or got help with any part of the assignment. Also note if something doesn't work correctly, it shows that you know about the problem. If you don't mention it, I'll assume you didn't test your project, and thus will grade you more harshly.
Your solution to this assignment