05 Prove : Assignment
Overview
Use your knowledge of object-oriented programming to write a one-player Pong game in Python.
Instructions
Configure your system
Before starting on the program, refer to the preparation material for this week about getting the arcade library set up and configured on your system.
Specification
For this project you will recreate a simple version of the classic Pong arcade game.
The following are the basic specifications:
The ball should bounce along the top, left, and bottom edges of the screen. If it goes of the right side of the screen, it should be lost.
If the ball hits the paddle, it should bounce.
The paddle should be on the right edge of the screen and move up and down with the arrow keys. It should not be able to move off the screen.
The left and right arrow keys should move the paddle down and up. They should be able to be held down.
At the start of the game, and after the ball is lost, it should start at a random location along the left edge of the screen, and with a random velocity (choose values that seem appropriate to you).
The user is awarded 1 point for every time they hit the ball with the paddle. They lose 5 points for every time they miss.
In addition, use the following values:
The screen is 400 pixels wide by 300 pixels high.
The ball radius is 10.
The paddle is 10 pixels wide by 50 pixels high. Each move of the paddle should be by 5 pixels.
Object-oriented Design
To help break the problem down into meaningful, cohesive pieces, we can create a number of classes to represent the elements of the game.
In future projects, you will be responsible to determine the classes needed, but to help you get started on this project, we will work from the same design. In addition, one of the benefits of encapsulation is the ability to define a class interface and then have different people working independently on the different classes.
In some sections of this course, students will work in pairs. But for our section, you will work in a pair with the instructor. I will provide a Pong class to represent the game and the rules. This Pong class will assume the existence of a Ball, Paddle, Point, and Velocity class as follows:
Point |
---|
x : float |
y : float |
__init__() |
Velocity |
---|
dx : float |
dy : float |
__init__() |
Ball |
---|
center : Point |
velocity : Velocity |
__init__() |
draw() |
advance() |
bounce_horizontal() |
bounce_vertical() |
restart() |
Paddle |
---|
center : Point |
__init__() |
draw() |
move_up() |
move_down() |
The provided Pong class will handle all the user input and call the methods of the above classes at the appropriate times. Your task is to implement these classes and methods.
You may download the code to start with here: pong.py. You are welcome to change any of the provided code (and encouraged to add additional "cool" elements to the game play) but you should not need to change anything to achieve the basic functionality.
For simplicity, for this first graphics assignment, you are welcome to put all of your classes in the same .py file.
Code hints and suggestions
You may refer to Common Arcade Functions for more information about the functions to use for drawing circles and rectangles.
Start by creating all the classes you need with the correct data members and blank methods. Then you can go through and fill in the methods one by one.
You can get a random float from a range as follows:
import random
...
random.uniform(-2, 2)
You are encouraged to work together and help one another on this assignment!
Automatic Grading Script (TestBed)
There is not automated test script for this assignment.
Submission
This is different: Instead of copying your python file to the Linux system and submitting it there. Please upload it to the I-Learn assignment.
Assessment and Grading
For your information, the instructor will use these assessment guidelines to evaluate your assignment. Feel free to refer to this to understand the expectations of this submission.