Exemple #1
0
def draw_objects():
    breakout.clear_screen()

    # Draw the paddle, ball, and wall of bricks
    # TODO
    for brick in bricks:
        x = breakout.get_x(brick)
        y = breakout.get_y(brick)
        width = breakout.get_width(brick)
        height = breakout.get_height(brick)
        color = breakout.get_color(brick)
        breakout.draw_rectangle(x, y, width, height, color)
    x = breakout.get_x(paddle)
    y = breakout.get_y(paddle)
    width = breakout.get_width(paddle)
    height = breakout.get_height(paddle)
    color = breakout.get_color(paddle)
    breakout.draw_rectangle(x, y, width, height, color)

    x = breakout.get_x(ball)
    y = breakout.get_y(ball)
    radius = breakout.get_radius(ball)
    color = breakout.get_color(ball)
    breakout.draw_circle(x, y, radius, color)
    # Tell pygame to actually redraw everything (DON'T CHANGE)
    pygame.display.flip()
def draw_objects():
    # First wipe canvas clean
    breakout.clear_screen()
    # Draw the paddle, ball, and wall of bricks
    breakout.draw_rectangle(breakout.get_x(paddle), breakout.get_y(paddle), breakout.get_width(paddle), breakout.get_height(paddle), breakout.get_color(paddle))
    breakout.draw_circle(breakout.get_x(ball), breakout.get_y(ball), breakout.get_radius(ball), breakout.get_color(ball))
    for brick in bricks:
        breakout.draw_rectangle(breakout.get_x(brick), breakout.get_y(brick), breakout.get_width(brick), breakout.get_height(brick), breakout.get_color(brick))
    # Tell pygame to actually redraw everything
    pygame.display.flip()
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))
Exemple #4
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