def build_bricks():
    #Create an empty array
    bricks = []
    for row in range(constants.NUM_ROWS):
        for col in range(constants.BRICKS_PER_ROW):
            x_position = constants.GAP + (col * (constants.BRICK_WIDTH + constants.GAP))
            y_position = row* (constants.BRICK_HEIGHT + constants.GAP)

            # Set the brick color based on row number 
            color = None
            if (row == 0 or row == 1):
                color = constants.RED
            elif (row == 2 or row  == 3):
                color = constants.ORANGE
            elif (row  == 4 or row  == 5):
                color = constants.GREEN
            elif (row == 6 or row  == 7):
                color = constants.YELLOcol
            else: 
                color = constants.YELLOW

            #Create a new brick and set the x,y, and color 
            b = breakout.create_new_brick()
            breakout.set_x(b, x_position)
            breakout.set_y(b, y_position)
            breakout.set_color(b, color)
            bricks.append(b)
    return bricks
Example #2
0
def paddle_update_position(paddle):
    breakout.get_mouse_location()
    location = breakout.get_mouse_location()
    x_position = location[0]
    if x_position >= constants.SCREEN_WIDTH - constants.PADDLE_WIDTH - 5:
        x_position = constants.SCREEN_WIDTH - constants.PADDLE_WIDTH - 5

    breakout.set_x(paddle, x_position)
def ball_update_position(ball):
    x = breakout.get_x(ball)
    y = breakout.get_y(ball)
    x += breakout.get_x_velocity(ball)
    y += breakout.get_y_velocity(ball)
    breakout.set_x(ball, x)
    breakout.set_y(ball, y)

    # If it hits the side walls, bounce off them
    if breakout.get_x(ball) >= constants.SCREEN_WIDTH:
        breakout.set_x_velocity(ball, -breakout.get_x_velocity(ball))
    if breakout.get_x(ball) < 0:
        breakout.set_x_velocity(ball, -breakout.get_x_velocity(ball))

    # If it hits the ceiling, bounce off it
    if breakout.get_y(ball) < 0:
        breakout.set_y_velocity(ball, -breakout.get_y_velocity(ball))
Example #4
0
def build_bricks():
    # Create an empty list
    bricks = []
    for s in range(6):
        y = s * 25
        if s < 2:
            color = colors[0]
        elif s == 2:
            color = colors[1]
        elif s >= 4:
            color = colors[2]
        for i in range(5):
            x = (i + 1) * 5 + i * 75
            brick = breakout.create_new_brick()
            breakout.set_x(brick, x)
            breakout.set_y(brick, y)
            breakout.set_color(brick, color)
            bricks.append(brick)
    return bricks
Example #5
0
def ball_update_position(ball):
    x = breakout.get_x(ball)
    y = breakout.get_y(ball)
    x_velocity = breakout.get_x_velocity(ball)
    y_velocity = breakout.get_y_velocity(ball)
    new_x = x + x_velocity
    new_y = y + y_velocity
    breakout.set_x(ball, new_x)
    breakout.set_y(ball, new_y)
    if new_x >= constants.SCREEN_WIDTH - constants.BALL_RADIUS:
        x_velocity = x_velocity * -1
    elif new_x <= constants.BALL_RADIUS:
        x_velocity = x_velocity * -1
    elif new_y <= constants.BALL_RADIUS:
        y_velocity = y_velocity * -1
    breakout.set_x_velocity(ball, x_velocity)
    breakout.set_y_velocity(ball, y_velocity)
    if new_y == constants.SCREEN_HEIGHT - constants.BALL_RADIUS:
        x_velocity = x_velocity
        y_velocity = y_velocity
def paddle_update_position(paddle):
    coordinates =  breakout.get_mouse_location()
    x = coordinates[0]
    breakout.set_x(paddle, breakout.clamp(x + breakout.get_x_velocity(paddle), 0, constants.SCREEN_WIDTH - breakout.get_width(paddle)))