コード例 #1
0
ファイル: breakout.py プロジェクト: ifanchang/stancode_101
def main():
    life_count = 0
    graphics = BreakoutGraphics()
    print("TotalLife:" + str(graphics.sum_bricks))

    # Add animation loop here!
    face_vx = face_vy = 1
    rate_dx = graphics.getter_dx()
    rate_dy = graphics.getter_dy()

    while life_count != NUM_LIVES:
        # Update
        graphics.ball.move(rate_dx, rate_dy)
        graphics.ball_tracker_paddle()

        # When the ball out of the window, update the number of the life.
        if graphics.dead == 1:
            life_count += 1
            graphics.dead = 0

        # Check
        graphics.ball_tracker_bricks()

        # the ball touch the bricks
        if graphics.remove_succ == 1:
            face_vy = face_vy * -1
            if graphics.ball.x <= 0 or graphics.ball.x >= graphics.window.width - graphics.ball.width:
                face_vx = face_vx * -1
            graphics.remove_succ = 0

        # The ball is not touch the bricks
        else:
            # Checking if the ball touch the right side or the left side of the window
            if graphics.ball.x <= 0 or graphics.ball.x >= graphics.window.width - graphics.ball.width:
                face_vx = face_vx * -1

            # Checking if the ball touch the paddle
            if graphics.paddle_touch == 1:
                graphics.paddle_touch = 0
                face_vy = face_vy * -1

            # Checking if the ball touch the top of the window
            elif graphics.ball.y <= 0:
                face_vy = face_vy * -1

        # Updating the rate of dx and the rate of dy speeds
        rate_dx = graphics.getter_dx() * face_vx
        rate_dy = graphics.getter_dy() * face_vy

        # Checking if the game is over
        if graphics.bricks_remove == graphics.sum_bricks:
            print("YOU WIN in breakout.py")
            break

        # Pause
        pause(FRAME_RATE)

    print("GAME OVER_checking point")
コード例 #2
0
def main():
    # Add animation loop here!
    # graphics = BreakoutGraphics(brick_cols=5, brick_rows=4)
    graphics = BreakoutGraphics()  # start backoutgraphics
    lives = NUM_LIVES  # get a variable equal NUM_LIVES
    while True:
        if graphics.ball.y + graphics.ball.height >= graphics.window.height:  # accidentally fall, lives minus 1
            lives -= 1  # live minus 1
            graphics.set_ball()  # reset the ball back to initial situation
        if lives == 0:  # dead condition - all lives gone
            graphics.dead()  # start the dead method
            break  # stop the while loop
        if graphics.move_brick == graphics.tot_brick:  # win condition - all brick remove
            graphics.win()  # start the win method
            break  # stop the while loop
        pause(FRAME_RATE)  # temporary stop
        graphics.move_ball()  # start the move_ball method
        graphics.wall_collision()  # start the wall_collision method
        graphics.detect_brick()  # start the detect_brick method
        graphics.detect_paddle()  # start the detect_paddle method
コード例 #3
0
ファイル: breakout.py プロジェクト: lily71903/sc-project
def main():
    """
    A breakout game, user can click mouse to start,and move the mouse to control the paddle,
    using the paddle to bounce the ball for hitting bricks.
    """
    graphics = BreakoutGraphics()
    life = NUM_LIVES

    # Add animation loop here!
    while life > 0:
        dx = graphics.get_dx()
        dy = graphics.get_dy()
        pause(FRAME_RATE)
        graphics.ball.move(dx, dy)
        graphics.window_check()
        graphics.check_remove()
        life -= graphics.dead()
        if graphics.ball.y >= graphics.window.height:
            graphics.restart()