CPSC120A
Fundamentals of Computer Science I

Lab 14

Accumulator

Use the command line to create a new directory called lab14 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.

Keyboard Control

Download the bouncing_ball.py Python program that we created in class. Modify the program so that it also draws a keyboard controlled rectangle at the bottom of the screen. Use pygame.key to move the rectangle left when the user holds down the left arrow key and right when the user holds down the right arrow key. It should not be possible to move the rectangle any other directions. You can use an image that you find on-line or you can use the following image:

Image Interaction

Modify the bouncing_ball.py Python program so that if the ball hits the rectangle, the ball bounces as if it hit the bottom of the screen. The ball is hitting the rectangle if all three of the following are true:

  1. The ball is far enough down that the bottom of the ball is below the top of the rectangle.
  2. The ball is far enough right that the right side of the ball is to the right of the left side of the rectangle.
  3. The ball is far enough left that the left side of the ball is to the left of the right side of the rectangle.

Also modify the program so that if the ball reaches the bottom of the screen the main loop stops running.

Design Document

Create a design document for your assignment 4 game, on paper. The design document should include a diagram of what the game will look like. It should also have a text description of how to play the game including how to win or lose.

Please give me your design document before beginning work on the assignment.

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.