Pong

From WLCS
Revision as of 09:15, 26 January 2010 by Admin (talk | contribs)

Objective:

  • You will use the GASP Python library to create Pong
  • The Pong game will require that you use math, variables, functions, and loops!

Resources:

Catch Directions:

  1. Read and walk through the entire HTTLACS: Ch 8. Be sure to analyze and run the code given to you.
  2. 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

Pong Directions:

  1. Copy catch.py to pong.py and change the ball into a paddle by using Box instead of the Circle. You can look at Appendix B for more information on Box. Make the adjustments needed to keep the paddle on the screen.
  2. Replace the distance function with a boolean function hit(bx, by, r, px, py, h) that returns True when the vertical coordinate of the ball (by) is between the bottom and top of the paddle, and the horizontal location of the ball (bx) is less than or equal to the radius (r) away from the front of the paddle. 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:
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
    """