TASK #1
TASK:
Create the Paddle class.
HINT:
To create a Paddle class, you will need to identify which variables are used to describe the paddle objects in your game. Then, you will need to move the variables to the class definition as instance variables. Be sure to correctly define the initial values of each instance variable.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #2
TASK:
Create a left paddle object.
HINT:
You will need to invoke the Paddle constructor and set as arguments
the values needed to initialize the object's instance variables. You can look at the parameters for the constructor in the Paddle class.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #1
- Create a right paddle object.
TASK #3
TASK:
Add an update method to the Paddle class..
HINT:
To add an update method to the Paddle class, you will need to follow the syntax as exemplified here
CHECK UP:
Watch the video below to check that you completed the task.
TASK #4
TASK:
Make the appropriate adjustments so that your game works using the Paddle class.
HINT:
You will need to use each paddle object's image and rect instance variable when blitting to the screen.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #2
- Objectify the ball.
TASK #5
TASK:
Add an intro screen.
HINT:
To add an intro screen, you will need to create another while loop that will be placed before the game loop. This loop will continue to run until the user clicks their mouse onto the screen.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #3
- Create and add another text object to the intro screen that says "-- Click Here --".
TASK #6
TASK:
Make "-- Click here --" blink.
HINT:
To have the ‘Click here’ surface blink, you will need to use time’s get_ticks method to get the current time outside of the intro loop. Then inside of the loop, you will need to run get_ticks again to determine when half a second has passed. Using a branch statement, you can blit the ‘Click here’ surface every half second.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #7
TASK:
Add a score instance variable to the Paddle class and print the left paddle's score to the screen.
HINT:
After adding a score instance variable, you will need to create another set of instance variables that will contain that score’s value printed on a surface. Then, you need to blit that surface onto the screen in the appropriate location.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #4
- Create and print another text object that will contain the score for the right paddle.
TASK #8
TASK:
Increment the score of the left paddle when the ball goes off the screen.
HINT:
You will need to add to the branch statement in the update method of the Ball class that checks if the ball went off the screen. You will simply increment the score instance variable at this time.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #5
- Increment the right paddle's score when the ball goes off the left side of the screen.
TASK #9
TASK:
Reposition the ball when it goes off screen.
HINT:
You will need to add to the branch statement in the update method of the Ball class that checks if the ball went off the screen. At this moment, you will need to reposition the ball object by reassigning the x and y values of its rect to the middle of the screen. Remember that you will also have to reset the y values of the two paddle objects.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #10
TASK:
Pause the game for a second after the ball leaves the screen, before it is repositioned.
HINT:
You will need to invoke time's sleep method at the moment in the branch statement that checks if the ball has left the screen.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #11
TASK:
Re-render the left paddle's score when the ball goes off the right side of the screen.
HINT:
You must invoke Text's render method when a paddle's score instance variable is incremented so that the change will be
reflected on the screen. Since the score is incremented in ball's update method, you will need to pass each paddle's score surface to the ball's update method.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #12
TASK:
Create the Text class.
HINT:
You will need to analyze your text objects and notice which variables are necessary to describe it. After you have decided which variables are needed to create a text object, you will define a Text class that contains those same instance variables. Finally, you will need to create instances of the Text class instead of creating those variables in your program.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #13
TASK:
Create an instance of the Text class that will contain the left paddle's score.
HINT:
To create a Text class, you will need to identify which variables are used to describe the text objects in your game. Then, you will need to move the variables to the class definition as instance variables. Be sure to correctly define the initial values of each instance variable.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #6
- Create a text object for the title and use the object in the intro loop.
- Create a text object for the subtitle and add it as well.
TASK #14
TASK:
Move the logic from Task #11 into the Text class’ update method.
HINT:
To move the logic into the Text class’ update method, you will need to determine the lines of code that deal with the updating of the score surface and move them into the Text class' update method. Be sure to pass any data that the block of code needs to Text' update method.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #15
TASK:
Explore why passing an object behaves differently than passing a variable containing a primitive data type(ints, double, char, string, etc).
HINT:
Watch the video below to get a thorough explanation.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #7
- Use the Ball's update method to update and print right paddle's score to the screen.
TASK #16
TASK:
What is the Game class?
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #8
- Define a Game class.
- Create an instance of the Game class and make the appropriate adjustments in main.
TASK #17
TASK:
What logic should go into the Game class' update method?
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #9
- Define an update method in the Game class.
- Move the logic that handles the scoring system to the update method.
TASK #18
TASK:
How to move the blinking text functionality into the Game class.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #10
- Create a blink method in the Game class.
- Use the blink method in main.
TASK #19
TASK:
How to move the restart algorithm into the Game class.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #11
- Create a restart method in the Game class.
- Move the restart logic into the restart method.
- Make the ball pause for another second once it is moved to the center of the screen.
TASK #20
TASK:
Move the title text object into the Game class as an instance variable.
HINT:
You will need to move the creation of the text objects from the main function into the constructor of the Game class. Once that is complete, you
will need to reference the Game object's text instance variables throughout your program when you previously referenced the text objectst that were local to the main function.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #12
- Move the other text objects into Game as an instance variable.
TASK #21
TASK:
How to move the restart algorithm into Game's update.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #13
- Create an outro loop that says "Great Match!".
- Add blinking text that says "-- Click to Restart --".
TASK #22
TASK #23
TASK:
Load your sound files into sound objects.
HINT:
To load a sound file, you will need to run mixer's pre_init() function at the
start of your program. Then, you will need to store the return value of a call to mixer's Sound constructor in a variable, which you will need
to give the location of the sound file as an argument. This variable will now contain the sound object, which can run the play method where ever you choose.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #14
- Use the sound objects you created to play sound effects.
- Use at least 3 different sounds.
TASK #24
TASK:
Download graphic images into an images folder.
HINT:
You will need to first create a folder in your project called
"images" and place your images there. Click here if you would like to use the same images that I used.
CHECK UP:
Watch the video below to check that you completed the task.
TASK #25
TASK:
Load a graphic image into an object.
HINT:
You will need to invoke the image.load() method with the location of the image file passed as an
argument. Store the surface with an image that is returned in a variable.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #15
- Load the "background" image into an object as well.
TASK #26
TASK:
Blit the introduction’s background image at the start of the game.
HINT:
You will need to blit the intro background image that you loaded in the
last task to the screen in the intro loop. Remember that this background image covers the screen and will take the place
of the call to screen.fill() that we used to clear the screen of previous changes to the sprites.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #16
- Blit the "background" image to the background of the game loop.
TASK #27
TASK:
Load the image of the ball into the "image" instance variable.
HINT:
You will need to create an image instance variable in the Ball class' constructor
that will be set to the return value of an invocation to image.load(). Remember that you must pass the location of the image you
want this instance variable to contain as an argument to image.load().
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #17
- Load the paddle's image into an instance variable called image in Paddle's constructor.
TASK #28
TASK:
End the game when the score of either player reaches 3.
HINT:
You can end the game when a certain condition is true by setting the game object's play
instance variable equal to false.
CHECK UP:
Watch the video below to check that you completed the task.
CHALLENGE EXERCISE #18
- Add an outro loop that will display the player who won the game.
- Display blinking text that will encourage the player to click to play again.
- Have the game restart when the player clicks during the outro loop.
Congratulations!
You have completed the PONG project!
You have completed the PONG project!