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))
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 ball_bounce_off(ball): breakout.set_y_velocity(ball, -breakout.get_y_velocity(ball))
def ball_bounce_off(ball): y = breakout.get_y_velocity(ball) breakout.set_y_velocity(ball, y * -1)