Difference between revisions of "Pong"

From WLCS
m (Protected "Pong" ([edit=sysop] (indefinite) [move=sysop] (indefinite)))
Line 1: Line 1:
'''Objective:'''
+
'''Objectives:'''
* You will use the GASP Python library to create Pong
+
* You will use Scratch to create Pong
* The Pong game will require that you use math, variables, functions, and loops!
+
* The Pong game will require that you use math, variables, conditionals, and loops!
  
 
'''Resources:'''
 
'''Resources:'''
* [http://openbookproject.net/thinkCSpy/ch08.html HTTLACS: Ch 8]
+
* [http://en.wikipedia.org/wiki/Pong Wikipedia - Pong]
 
+
* [http://www.ponggame.org/ Pong Game]
'''Catch Directions:'''
 
# Read and walk through the entire HTTLACS: Ch 8.  Be sure to analyze and run the code given to you.
 
# Complete the following Ch 8 exercises: #1-5, 8-10
 
#* For exercises #8, you should comment most lines of code, explaining what each line does
 
# Submit the exercises on-line by following the these instructions:
 
## Name your file ch8_FIRSTNAME_LASTNAME.txt or ch8_FIRSTNAME_LASTNAME.odt
 
## Submit the file online via SchoolWebLockers
 
  
 
'''Pong Directions:'''
 
'''Pong Directions:'''
# Copy catch.py from Section 8.10 in [http://openbookproject.net/thinkcs/python/english2e/ch08.html Case Study: Catch] to pong.py and change the mitt into a paddle by using Box instead of the Circle. You can look at [http://openbookproject.net/thinkCSpy/app_b.html Appendix B] for more information on Box. Make the adjustments needed to keep the paddle on the screen.
+
# Each player should be able to move the paddles up and down
# When you play the Catch game, the ball collides and is caught.  In Pong, we want the ball to bounce back if there is a collision.  If the ball collides, you should make it bounce back along the x-axis.  Hint: We have already made the ball bounce in the y-axes when it hits the top or bottom of the screen.
+
# The ball should bounce if there is a collision.  If the ball collides, you should make it bounce back along the x-axis.  In order to bounce, negate the ball's direction (multiply by negative 1)
# Notice that the ball's collision with the paddle is not exact.  We need to fix this...
+
# ...
## Replace the distance function with a boolean function hit(bx, by, r, px, py, h), which will return True if the ball hits the paddle and False otherwise.  The ball hits the paddle when all the following are True:
+
# ...
##* The vertical coordinate of the ball (by) is between the bottom (py) and top (py+h) of the paddle
+
# ...
##* The horizontal location of the ball (bx) + its radius (r) is greater than the front of the paddle (px)
 
## Use hit to determine when the ball hits the paddle, and make the ball bounce back in the opposite horizontal direction when hit returns True. Your completed function should pass these doctests:
 
 
 
<source lang="python">
 
def hit(bx, by, r, px, py, h):
 
    """
 
      >>> hit(760, 100, 10, 780, 100, 100)
 
      False
 
      >>> hit(770, 100, 10, 780, 100, 100)
 
      True
 
      >>> hit(770, 200, 10, 780, 100, 100)
 
      True
 
      >>> hit(770, 210, 10, 780, 100, 100)
 
      False
 
    """
 
</source>
 
 
 
# Change the scoring logic to give the player a point when the ball goes off the screen on the left.
 
# Add a new paddle on the left side of the screen which moves up when 'a' is pressed and down when 's' is pressed.  
 
# Create a second hit function for the left paddle, and use it in the loop by checking if the ball ever hits the left paddle
 
# Change the starting point for the ball to the center of the screen, (400, 300), and make it randomly move to the left or right at the start of each round.
 
# Be sure to change the scoring logic so that both players receives points properly.
 
  
 
'''Grading Rubric:'''
 
'''Grading Rubric:'''

Revision as of 07:10, 10 October 2012

Objectives:

  • You will use Scratch to create Pong
  • The Pong game will require that you use math, variables, conditionals, and loops!

Resources:

Pong Directions:

  1. Each player should be able to move the paddles up and down
  2. The ball should bounce if there is a collision. If the ball collides, you should make it bounce back along the x-axis. In order to bounce, negate the ball's direction (multiply by negative 1)
  3. ...
  4. ...
  5. ...

Grading Rubric:

  • 2 pts - right paddle moves up and down with keyboard
  • 2 pts - ball bounces properly off the right paddle
  • 2 pts - left paddle moves up and down with keyboard
  • 2 pts - ball bounces properly off the left paddle
  • 2 pts - Player 1 and Player 2 points are tracked and displayed properly