The Starting Template

The starting template for this project contains the initial version of the Breakout.py file. This file is shown below and takes care of the following details:

0######################################################################
# Name:
# Collaborators (if any):
# Section leader's name:
# Generative AI transcript (if used):
# List of extensions made (if any):
######################################################################

"""
This program (once you have finished it) implements the Breakout game
"""
1from pgl import GWindow, GOval, GRect
import random

# Constants
2GWINDOW_WIDTH = 360           # Width of the graphics window
GWINDOW_HEIGHT = 600          # Height of the graphics window
N_ROWS = 10                   # Number of brick rows
N_COLS = 10                   # Number of brick columns
BRICK_ASPECT_RATIO = 4 / 1    # Width to height ratio of a brick
BRICK_TO_BALL_RATIO = 3 / 1   # Ratio of brick width to ball size
BRICK_TO_PADDLE_RATIO = 2 / 3 # Ratio of brick to paddle width
BRICK_SEP = 2                 # Separation between bricks (in pixels)
TOP_FRACTION = 0.1            # Fraction of window above bricks
BOTTOM_FRACTION = 0.05        # Fraction of window below paddle
N_BALLS = 3                   # Number of balls (lives) in a game
TIME_STEP = 10                # Time step in milliseconds
INITIAL_Y_VELOCITY = 3.0      # Starting y velocity downwards
MIN_X_VELOCITY = 1.0          # Minimum random x velocity
MAX_X_VELOCITY = 3.0          # Maximum random x velocity

# Derived Constants
BRICK_WIDTH = (GWINDOW_WIDTH - (N_COLS + 1) * BRICK_SEP) / N_COLS
BRICK_HEIGHT = BRICK_WIDTH / BRICK_ASPECT_RATIO
PADDLE_WIDTH = BRICK_WIDTH / BRICK_TO_PADDLE_RATIO
PADDLE_HEIGHT = BRICK_HEIGHT / BRICK_TO_PADDLE_RATIO
PADDLE_Y = (1 - BOTTOM_FRACTION) * GWINDOW_HEIGHT - PADDLE_HEIGHT
BALL_DIAMETER = BRICK_WIDTH / BRICK_TO_BALL_RATIO


3# Function: breakout
def breakout():
    """The main program for the Breakout game."""

    gw = GWindow(GWINDOW_WIDTH, GWINDOW_HEIGHT)

    # You fill in the rest of this function along with any additional
    # helper and callback functions you need





4# Startup code
if __name__ == "__main__":
    breakout()
0
Submission metadata. Please make sure you don’t forget to fill it all out!
1
It includes the imports you will need in writing the game.
2
It defines the constants that control the game parameters, such as the dimensions of the various objects. Your code should use these constants internally so that changing them in your file changes the behavior of the program accordingly. Note that some of these constants are specified directly, but that others are derived from constants specified earlier.
3
It includes a skeleton for the breakout function that creates the graphics window. Your job is to add the code for the Breakout game along with the definition of any helper and callback functions, all of which are easiest to define as inner functions inside breakout so they can share its variables.
4
It includes the startup code to invoke the breakout function when the Breakout.py module is run from the command line.

The library pgl.py is included in the initial template repository as well, so that you should be able to download the entire repository and get straight to coding.