def main(): """ This program creates the Breakout Game. A ball will be bouncing around the GWindow and bounce back if it hits the walls, paddles or the bricks. Bricks are removed if hit by the ball. Player can use the paddle to prevent ball from falling out of the bottom window by moving the mouse. The game ends if all the bricks are removed or the ball falls out of the bottom wall for over NUM_LIVES. """ graphics = BreakoutGraphics() # Add animation loop here! lives = NUM_LIVES while True: pause(FRAME_RATE) while graphics.mouse_lock is True: if graphics.ball_out(): lives -= 1 if lives > 0: graphics.reset_ball() break elif lives <= 0: break if graphics.brick_left == 0: break graphics.move_ball() graphics.handle_collision() pause(FRAME_RATE) if graphics.brick_left == 0: break
def main(): graphics = BreakoutGraphics() lives = NUM_LIVES # Balls after the first ball are random served. while True: graphics.move_ball() # Balls are moved based on this function. graphics.check_for_collisions( ) # Check whether the ball is colliding with paddle or brick. graphics.wall_collisions( ) # Check whether the ball is colliding with edges. pause(FRAME_RATE) # Pause the animation with FRAME_RATE. if graphics.ball_out(): # If the ball is out of the bottom edge: lives -= 1 # Minus 1 life. if lives > 0: # If left lives > 0, play again. graphics.reset_ball() # Reset the ball position. else: graphics.game_over() # If left lives <= 0, game over. break # Stop looping if we've lost all NUM_LIVES lives. if graphics.win_game(): # If all bricks are removed, you win. break # Stop looping while you win.