コード例 #1
0
def enter_game_page(m):
    global graphics  # set graphics object to global so animation loop can call it.

    obj = log_in_page.window.get_object_at(m.x, m.y)
    if obj is log_in_page.play_button or obj is log_in_page.play_label or obj is log_in_page.fb_button \
            or obj is log_in_page.fb_label or obj is log_in_page:
        graphics = BreakoutGraphics()  # new window will show at this moment.
        log_in_page.window.close()  # close the login window.
        graphics.draw_bricks()
        graphics.add_score_board()
        graphics.add_accessories(
            10
        )  # give argument to determine the total number of blue/red blocks will show.
        graphics.dx_getter()
        graphics.dy_getter()
        """
        The following part has some bugs I still figuring out, that is, when I use GPolygon to draw a heart 
        shape and add it to window, it seems to conflict to method: window.get_object_at(x,y). Though it's not perfect,
        I use GOval to represent NUM_LIVES on the right-top window. 
        """
        for i in range(NUM_LIVES):
            heart = graphics.draw_heart_icon()
            graphics.window.add(
                heart, graphics.window.width - graphics.heart_shape.width *
                (i + 1) - 5 * (i + 1),
                graphics.score_board_label.y - graphics.heart_shape.height)
コード例 #2
0
ファイル: breakout.py プロジェクト: samfang9527/SC101
def main():
    graphics = BreakoutGraphics()
    # main loop
    while True:

        # start and restart page
        if graphics.get_page() == 0 or graphics.get_page() == 2:
            graphics.start_page()
            while True:
                pause(FRAME_RATE)
                if graphics.get_page() != 0 or graphics.get_page != 2:
                    break

        # game page
        elif graphics.get_page() == 1:
            graphics.game_reset()
            graphics.draw_bricks()
            ball = graphics.get_ball()
            window = graphics.get_window()
            while graphics.get_lives() > 0:
                pause(FRAME_RATE)
                ball.move(graphics.get_ball_velocity()[0],
                          graphics.get_ball_velocity()[1])
                if 0 > ball.x or ball.x + ball.width > window.width:
                    if ball.x < 0:
                        ball.x = 0
                    elif ball.x + ball.width > window.width:
                        ball.x = window.width - ball.width
                    graphics.set_ball_velocity(x=-1)
                if 0 > ball.y:
                    ball.y = 0
                    graphics.set_ball_velocity(y=-1)
                graphics.detect_collision()
                graphics.wind()
                if ball.y > window.height:
                    graphics.set_lives()
                    graphics.game_reset()
                    graphics.draw_bricks()
                if graphics.check_over():
                    break
            graphics.set_page(2)