Пример #1
0
def run_game():

    #Initialize game and create a screen object
    #pygame.mixer.pre_init(44100, 16, 2, 4096) (Unused code for testing)
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Gal Game")

    #Entity
    ship = Ship(ai_settings, screen)

    #make a group to store them
    bullets = Group()
    enemies = Group()

    #creates enemys
    gf.create_army(ai_settings, screen, enemies)

    #Start the main loop for the game
    while (ai_settings.isRunning == True):

        if (ai_settings.option == "Play"):

            gf.play_music(ai_settings)
            gf.check_events(ai_settings, screen, ship, bullets)
            ship.update()
            gf.update_bullets(bullets)
            gf.update_screen(ai_settings, screen, ship, enemies, bullets)

            if ai_settings.ship_lives == 0:
                ai_settings.option = "Death"

        elif (ai_settings.option == "Score"):
            sc.showScores(ai_settings, screen)
            sc.scoreChoice(ai_settings)

        elif (ai_settings.option == "Restart"):
            gf.restart(ai_settings)
            ai_settings.option = "Play"

        elif (ai_settings.option == "Shut Down"):
            sys.exit()

        elif (ai_settings.option == "Death"):
            #Future testing
            #sc.readScores(ai_settings)
            dt.deathMenu(ai_settings, screen)
            dt.deathChoice(ai_settings)

        elif (ai_settings.option == "Pause"):
            pt.pauseMenu(ai_settings, screen)
            pt.optionMenu(ai_settings)

        else:
            mn.mainMenu(ai_settings, screen)
            mn.choiceMenu(ai_settings)
Пример #2
0
def run_game():
    """"Initializes the game"""
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    stats = GameStats(settings)
    scoreboard = Scoreboard(settings, screen, stats)
    f.load_score(stats, scoreboard)

    #Play button
    play_button = Button(settings, screen, "Play")

    #Makes a ship/alien object and bullet group
    ship = Ship(settings, screen)
    bullets = Group()
    aliens = Group()

    #Creat aliens
    g.create_army(settings, screen, ship, aliens)

    #Start main loop of the game.
    while True:

        #Watch for game events and moves ship
        g.update_events(settings, screen, stats, play_button, ship, aliens,
                        bullets, scoreboard)

        if stats.game_active:
            ship.move()
            g.update_bullets(settings, screen, stats, scoreboard, ship, aliens,
                             bullets)
            g.update_aliens(settings, stats, screen, ship, aliens, bullets,
                            scoreboard)

        #Updates screen after each loop
        g.update_screen(settings, screen, stats, scoreboard, ship, aliens,
                        bullets, play_button)
def run_game():
    """Run the game
    ...
    This function starts the game. It initializes pygame, instantiates the
    screen, play button, stats, scoreboard, corgi, borks, kitties and an army
    thereof. It then starts the main loop which updates the screen and checks
    for events. When the game is active, it also updates the corgi, the borks
    and the kitties."""
    pygame.init()
    settings = Settings()

    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption(settings.caption)

    logo = Logo(settings, screen)
    play_button = Button(screen, settings, settings.play_button_text)
    stats = GameStats(settings)
    scoreboard = Scoreboard(settings, screen, stats)
    corgi = Corgi(settings, screen)
    borks = Group()
    kitties = Group()

    gf.create_army(settings, screen, corgi, kitties)

    # game loop
    while True:
        gf.update_screen(settings, screen, stats,
                         scoreboard, corgi, kitties, borks, play_button, logo)
        gf.check_events(settings, screen, stats,
                        scoreboard, play_button, kitties, corgi, borks)

        if stats.game_active:
            corgi.update()
            gf.update_borks(settings, screen, stats,
                            scoreboard, corgi, kitties, borks)
            gf.update_kitties(settings, stats, screen,
                              scoreboard, corgi, kitties, borks)
Пример #4
0
def run_game():
    # Initialize the game and create a screen object
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("shoot everything")

    # Make a ship:
    ship = Ship(ai_settings, screen)

    # Make a viking:
    # viking = Viking(ai_settings, screen)

    # Make a group to store bullets in
    bullets = Group()

    # Make a group to hold vikings in:
    vikings = Group()

    # Create an army of vikings:
    gf.create_army(ai_settings, screen, ship, vikings)

    # Set the background color:
    bg_color = (0, 102, 153)

    # Start the main loop fo rthe game
    while True:

        # ai_settings, screen, and bullets have been added as arguments here.
        gf.check_events(ai_settings, screen, ship, bullets)

        ship.update()
        gf.update_bullets(bullets)

        # print(len(bullets)) # This prints out the number of bullets on screen in the terminal
        gf.update_screen(ai_settings, screen, ship, vikings, bullets)
Пример #5
0
def run_game():
    #Initialize game and create a screen object.
    pygame.init()
    settings = Settings()
    pygame.display.set_caption(settings.title)

    unit_group_l = Group()
    unit_group_r = Group()
    blood = Group()
    unit_group_dead = Group()
    hit_decals = Group()

    buttons = Group()

    all_groups = {
        "unit_group_l": unit_group_l,
        "unit_group_r": unit_group_r,
        "blood": blood,
        "unit_group_dead": unit_group_dead,
        "hit_decals": hit_decals,
        "buttons": buttons
    }

    #Initialize World Map Classes
    """in all_groups/ andere Gruppe?"""
    worldmap = WorldMap(settings, all_groups)
    testplayer = TestPlayer(settings, all_groups, 15, 10)
    testbutton = Button(settings, 32, 30, 30, "test")

    #Add Units to group
    gf.add_unit(settings, unit_group_l, Terran, settings.army_size_l,
                all_groups)
    gf.add_unit(settings, unit_group_r, Psion, settings.army_size_r,
                all_groups)

    gf.create_army(settings, unit_group_l, all_groups, "left")
    gf.create_army(settings, unit_group_r, all_groups, "right")

    #Start the main loop for the game.
    while True:
        """MENU"""
        #Menu Screen
        while settings.game_state == "menu":
            gf.check_events_menu(settings, all_groups)
            gf.update_screen_menu(settings, all_groups)
        """MAP"""
        #Map Screen
        while settings.game_state == "map":
            gf.check_events_map(settings, testplayer, all_groups)
            gf.update_screen_map(settings, worldmap, testplayer, testbutton,
                                 all_groups)

            pass
        """Battle"""
        #Battle Screen
        while settings.game_state == "battle":

            # Get Time
            clock.tick(FPS) / 1000
            ticks = pygame.time.get_ticks()
            """TEST TICKS"""
            #print(ticks)

            # Watch for keyboard and mouse events.
            gf.check_events(settings, all_groups)

            gf.update_screen(settings, all_groups)