Difference between revisions of "Pong"

From WLCS
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''Objective:'''
+
'''Objectives:'''
* You will use the GASP Python library to create Pong
+
* You will create Pong using your programming language of choice (e.g. Scratch, Python)
* 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:'''
+
'''Requirements:'''
# Read and walk through the entire HTTLACS: Ch 8.  Be sure to analyze and run the code given to you.
+
* Background with dashed line through the middle
# Complete the following Ch 8 exercises: #1-5, 8-10
+
* Two paddles parallel to each other
#* For exercises #8, you should comment most lines of code, explaining what each line does
+
** Left paddle goes up and down using S and W keys
 +
** Right paddle goes up and down using Up and Down keys
 +
* Ball movement and placement
 +
** Ball starts from the middle
 +
** Moves around at angles
 +
** Bounces when it hits a paddle
 +
** Bounces when it hits the top and bottom
 +
* Scoreboard
 +
** If the ball goes beyond the left side, then the right player gets a point
 +
** If the ball goes beyond the right side, then the left player gets a point
 +
** When either player reaches 10, then they win
 +
* Sounds
 +
** Played when it hits the paddles
 +
** Played when it hits the bottom or top
 +
** Played when a player scores
  
'''Pong Directions:'''
+
'''Bonus Requirements:'''
# Copy catch.py to pong.py and change the ball 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.
+
* Allow the paddles to move left and right using the A, D, Left, and Right arrow keys
# 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.  
+
* Allow the paddles to rotate
# Notice that the ball's collision with the paddle is not exact.  We need to fix this...
+
* Gradually change the speed of the ball as the points get higher
## 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:
+
* Difficulty selection screen (e.g. Beginner, Intermediate, Expert)
##* The vertical coordinate of the ball (by) is between the bottom (py) and top (py+h) of the paddle
+
* Change the speed of the ball depending on where the ball hits the paddle
##* The horizontal location of the ball (bx) + its radius (r) is greater than the front of the paddle (px)
+
* Items that randomly appear that give players:
## 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:
+
** increased speed
 +
** decreased speed
 +
** a longer paddle
 +
** a shorter paddle
 +
** freeze (i.e. paddle cannot move)
 +
** a projectile that can fire and disable the other player's paddle
  
<source lang="python">
+
'''Grading Rubric:'''
def hit(bx, by, r, px, py, h):
+
* 1 pt - background and graphics
    """
+
* 1 pt - sounds play when hitting paddles and edges
      >>> hit(760, 100, 10, 780, 100, 100)
+
* 2 pts - paddles move up and down with keyboard
      False
+
* 2 pts - ball bounces properly off the paddles
      >>> hit(770, 100, 10, 780, 100, 100)
+
* 2 pts - Player 1 and Player 2 scores work and display properly
      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.
 

Latest revision as of 11:25, 9 October 2014

Objectives:

  • You will create Pong using your programming language of choice (e.g. Scratch, Python)
  • The Pong game will require that you use math, variables, conditionals, and loops!

Resources:

Requirements:

  • Background with dashed line through the middle
  • Two paddles parallel to each other
    • Left paddle goes up and down using S and W keys
    • Right paddle goes up and down using Up and Down keys
  • Ball movement and placement
    • Ball starts from the middle
    • Moves around at angles
    • Bounces when it hits a paddle
    • Bounces when it hits the top and bottom
  • Scoreboard
    • If the ball goes beyond the left side, then the right player gets a point
    • If the ball goes beyond the right side, then the left player gets a point
    • When either player reaches 10, then they win
  • Sounds
    • Played when it hits the paddles
    • Played when it hits the bottom or top
    • Played when a player scores

Bonus Requirements:

  • Allow the paddles to move left and right using the A, D, Left, and Right arrow keys
  • Allow the paddles to rotate
  • Gradually change the speed of the ball as the points get higher
  • Difficulty selection screen (e.g. Beginner, Intermediate, Expert)
  • Change the speed of the ball depending on where the ball hits the paddle
  • Items that randomly appear that give players:
    • increased speed
    • decreased speed
    • a longer paddle
    • a shorter paddle
    • freeze (i.e. paddle cannot move)
    • a projectile that can fire and disable the other player's paddle

Grading Rubric:

  • 1 pt - background and graphics
  • 1 pt - sounds play when hitting paddles and edges
  • 2 pts - paddles move up and down with keyboard
  • 2 pts - ball bounces properly off the paddles
  • 2 pts - Player 1 and Player 2 scores work and display properly