Пример #1
0
def run_game():
    # Initialize game and create a screen object.
    pygame.init()
    # start_game = False
    ai_settings = Settings()

    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))

    screen = pygame.display.set_mode((1200, 800))
    pygame.display.set_caption("Super Pong 64")

    start_game = False

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats, "")
    title = Title(ai_settings, screen, "")

    # make the left paddle
    left_paddle = Left_Paddle(ai_settings, screen)
    right_paddle = Right_Paddle(ai_settings, screen)
    bottom_paddle = Bottom_Paddle(ai_settings, screen)
    top_paddle = Top_Paddle(ai_settings, screen)
    top_left = Top_Left(ai_settings, screen)
    center_line = Center_Line(ai_settings, screen)
    bottom_right = Bottom_Right(ai_settings, screen)
    balls = Group()

    play_button = Button(ai_settings, screen, "Play")

    # Start the main loop for the game
    while True:
        title.prep_title("")
        title.prep_rules("")
        gf.check_events(ai_settings, screen, stats, sb, play_button,
                        left_paddle, top_left, bottom_paddle, balls)

        if stats.game_active:

            left_paddle.update(ai_settings)
            right_paddle.update(ai_settings, balls)
            bottom_paddle.update(ai_settings)
            top_paddle.update(ai_settings, balls)
            bottom_right.update(ai_settings, balls)
            top_left.update(ai_settings)

            gf.update_balls(ai_settings, stats, screen, sb, left_paddle,
                            right_paddle, bottom_paddle, top_paddle, top_left,
                            bottom_right, balls)

            gf.update_top_paddle(ai_settings, top_paddle)
            gf.update_bottom_right(ai_settings, bottom_right)
            gf.update_right_paddle(ai_settings, right_paddle)

        gf.update_screen(ai_settings, screen, stats, sb, title, left_paddle,
                         right_paddle, bottom_paddle, center_line, top_paddle,
                         top_left, bottom_right, balls, play_button)
Пример #2
0
def run_game():

    # Initialize game and create a screen object.
    pygame.init()
    ai_settings = Settings()

    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))

    screen = pygame.display.set_mode((1200, 800))
    pygame.display.set_caption("Alien Invasion")

    # Make the Play button.
    play_button = Button(ai_settings, screen, "Play")

    hi_button =  Button2(ai_settings, screen)

    # Create an instance to store game statistics.
    stats = GameStats(ai_settings)
    # foo = open("foo.txt", "w")
    # foo.write("0")
    # foo.close()
    fo = open("foo.txt", "r+")
    stats.high_score = int(fo.readline())
    stats.high_score2 = int(fo.readline())
    stats.high_score3 = int(fo.readline())
    fo.close()
    print("hiscore: " + str(stats.high_score))


    # Create an instance to store game statistics and create a scoreboard.
    sb = Scoreboard(ai_settings, screen, stats)
    title = Title(ai_settings, screen, "", stats)


    # Make a ship, a group of bullets, and a group of aliens.

    ship = Ship(ai_settings, screen)

    ufo = UFO(ai_settings, screen)

    # Make a group to store bullets in.
    # blue = Blue(ai_settings, screen)
    # red = Red(ai_settings, screen)
    # green = Green(ai_settings, screen)
    bullets = Group()
    alien_bullets = Group()
    aliens = Group()

    # Create the fleet of aliens.
    gf.create_fleet(ai_settings, screen, ship, aliens, alien_bullets)

    # Start the main loop for the game.
    while True:
        title.prep_title("")
        title.prep_rules("")
        title.prep_blue_msg("")
        title.prep_red_msg("")
        title.prep_green_msg("")
        gf.check_events(ai_settings, screen, stats, sb, play_button, hi_button, ship,
            aliens, bullets, alien_bullets)

        if stats.game_active:
            ship.update(clock)
            ufo.update()
            # ship.explode(hit)
            # if hit == True and ship.image == 'images/Ship Full.gif':
            #     ship.center_ship()
            # We update the aliens’ positions after the bullets have been updated,
            # because we’ll soon be checking to see whether any bullets hit any aliens.
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                bullets, alien_bullets)
            # print(len(bullets))
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                bullets, alien_bullets)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens,
                         ufo, title, bullets, alien_bullets, play_button,
                         hi_button)