Ejemplo n.º 1
0
def run_game():
    # initialize game and create screen object
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(settings.screen_res)
    pygame.display.set_caption("Alien Invasion")
    stats = Stats()
    ship = Ship(screen)
    bullets = Group()
    aliens = Group()
    play_button = Button(settings, screen, 'Play')
    scoreboard = Scoreboard(settings, screen, stats)
    fun.create_fleet(settings, screen, aliens, ship.rect.height, stats)

    # start the main loop for the game
    while True:
        fun.check_events(settings, screen, ship, bullets, stats, aliens, play_button, scoreboard)
        if stats.game_active:
            ship.update()
            bullets.update()
            aliens.update()
            fun.drop_aliens(aliens)
            fun.collide(ship, aliens, bullets, settings, stats)
            fun.delete_bullets(bullets)
        fun.update_screen(screen, settings, ship, bullets, aliens, stats, play_button, scoreboard)
Ejemplo n.º 2
0
def run():
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    play_button = Button(game_settings, screen, "Play")
    stats = GameStats(game_settings)
    sb = Scoreboard(game_settings, screen, stats)
    ship = Ship(game_settings, screen)
    bullets = Group()
    aliens = Group()
    f.create_fleet(game_settings, screen, ship, aliens)
    while True:
        f.check_events(game_settings, screen, stats, sb, play_button, ship,
                       aliens, bullets)
        if stats.game_active:
            ship.update()
            f.update_bullets(game_settings, screen, stats, sb, play_button,
                             ship, aliens, bullets)
            f.update_aliens(game_settings, stats, sb, screen, ship, aliens,
                            bullets)

        f.update_screen(game_settings, screen, stats, sb, ship, aliens,
                        bullets, play_button)
Ejemplo n.º 3
0
def run_game():
    pygame.init()
    ai_settings = Settings
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    alien = Alien(ai_settings, screen)
    pygame.display.set_caption("Invasion2.0")
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # main loop
    while True:
        gf.check_events(ai_settings, screen, stats, play_button, ship, aliens,
                        bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, aliens, bullets,
                              stats)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets,
                         play_button, sb)
Ejemplo n.º 4
0
def run_game():
    pygame.init()
    ai_setting = setting()
    scree = pygame.display.set_mode(
        (ai_setting.screen_width, ai_setting.screen_hight))
    aliens = Group()
    ship = Ship(scree, ai_setting)
    alien = Alien(ai_setting, scree)
    gf.create_fleet(ai_setting, scree, ship, aliens)
    bullets = Group()
    pygame.display.set_caption('New game')
    stats = GameStats(ai_setting)
    sb = Scoreboard(ai_setting, scree, stats)
    play_button = Button(ai_setting, scree, "Play")

    while True:
        gf.check_events(ship, ai_setting, scree, bullets, stats, play_button,
                        aliens)
        if stats.game_active:
            ship.update()
            gf.update_aliens(ai_setting, aliens, ship, stats, bullets, scree)
            gf.update_bullet(ai_setting, scree, ship, aliens, bullets, sb,
                             stats)
        gf.update_screen(ai_setting, scree, ship, bullets, aliens, play_button,
                         stats, sb)
Ejemplo n.º 5
0
def run_game():
    #Инициализация игры и создание экрана
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien War")
    play_button = Button(ai_settings, screen, "Play")
    stats = GameStats(ai_settings)
    sb = ScoreBoard(ai_settings, screen, stats)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    f.create_fleet(ai_settings, screen, ship, aliens)
    # Назначение цвета фона
    bg_color = (100, 100, 100)
    alien = Alien(ai_settings, screen)
    while True:
        f.check_events(ai_settings, screen, stats, sb, play_button, ship,
                       aliens, bullets)
        if stats.game_active:
            ship.update()
            f.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)
            f.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                            bullets)
        f.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                        play_button)
Ejemplo n.º 6
0
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    ship = Ship(ai_settings, screen)
    alien = Alien(ai_settings, screen)

    bullets = Group()
    aliens = Group()

    gf.create_fleet(ai_settings, screen, ship, aliens)

    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        #bullets.update()
        gf.update_bullets(bullets)
        gf.update_aliens(ai_settings, aliens)

        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        #print(len(bullets))
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Ejemplo n.º 7
0
def run_game():
    pygame.init()
    ai_settings = settings.Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    #screen=pygame.display.set_mode((1200,800))
    #bg_color=(200,200,222)
    pygame.display.set_caption("alien invasion")
    ship = Ship(ai_settings, screen)
    play_button = Button(ai_settings, screen, "play")
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    #存储子弹
    bullets = Group()
    aliens = Group()

    gf.create_fleet(ai_settings, screen, ship, aliens)

    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        bullets, aliens)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets)
        #每次循环都重绘屏幕
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button)
Ejemplo n.º 8
0
def rungame():

    #initializin pygame,settings,and scr objs
    pygame.init()

    s = Settings()
    
    screen = pygame.display.set_mode((s.screen_width,s.screen_height))
    pygame.display.set_caption("CORONA INVASION!")

    #make the play button
    play_button = Button(s,screen,"Play")

    #create instance to store game statistics and create a scoreboard
    stats = GameStats(s)
    sb = Scoreboard(s,screen,stats)


    #time to make a ship
    sanit = Sanitizer(s , screen)
    #make a  virus
    #coro = Coro(s,screen)                                    ####optional for now
    #making a group to store bullets in
    bubbles = Group()
    coros = Group()
    #create fleet of viruses
    f.create_fleet(s,screen,sanit,coros)
  

    #main loop for the game
    while True:
        f.check_events(s,screen,stats,sb,play_button,sanit,coros,bubbles) 


           
        bubbles.update()
        
        if stats.game_active:
            sanit.update()
            f.update_bubbles(s,screen,stats,sb,sanit,coros,bubbles)
            f.update_coros(s,screen,stats,sb,sanit,coros,bubbles)
            f.update_screen(s,screen,stats,sb,sanit,coros,bubbles,play_button)
Ejemplo n.º 9
0
def run_game():
    pygame.init()  #初始化背景设置
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))  #设置屏幕大小
    pygame.display.set_caption("Alien Invasion")

    # 创建play按钮
    play_button = Button(ai_settings, screen, "Play")

    #创建一个用于储存游戏统计信息的实例
    stats = GameStats(ai_settings)

    #创建一艘飞船,一个子弹编组和一个外星人编组
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    #创建外星人群
    func.create_fleet(ai_settings, screen, ship, aliens)

    #开始游戏的主循环
    while True:

        func.check_events(ai_settings, screen, stats, play_button, ship,
                          aliens, bullets)

        if stats.game_active:
            ship.update()
            #bullets.update()
            func.update_bullet(ai_settings, screen, ship, aliens, bullets)
            func.update_aliens(ai_settings, screen, stats, ship, aliens,
                               bullets)
            # #删除以消失子弹(优化主循环,将此放入function中)
            # for bullet in bullets.copy():
            #     if bullet.rect.bottom <= 0:
            #         bullets.remove(bullet)
            # print(len(bullets))

        #每次循环时都重绘屏幕
        func.update_screen(ai_settings, screen, stats, ship, bullets, aliens,
                           play_button)
Ejemplo n.º 10
0
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    play_button = Button(screen, "Play", ai_settings.screen_width / 2, 300,
                         200, 50)
    reset_button = Button(screen, "Reset", ai_settings.screen_width / 2, 400,
                          200, 50)
    high_score_button = Button(screen, "High Score",
                               ai_settings.screen_width / 2, 500, 200, 50)
    pause_button = Button(screen, "Pause", 160, 30, 100, 40)
    back_button = Button(screen, "Back", 160, 30, 100, 40)
    ship = Ship(ai_settings, screen)
    Alien(ai_settings, screen)
    bullets = Group()
    alien_bullets = Group()
    arches = Group()
    # Explode(ai_settings, screen)
    explosio = Group()
    aliens = Group()  # Alien(ai_settings, screen)
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    gf.create_fleet(ai_settings, screen, ship, aliens, arches)

    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button,
                        pause_button, high_score_button, reset_button,
                        back_button, ship, aliens, bullets, arches)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets, alien_bullets, explosio, arches)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, alien_bullets, arches)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         alien_bullets, play_button, pause_button,
                         high_score_button, reset_button, back_button,
                         explosio, arches)
Ejemplo n.º 11
0
def run_game():

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

    game_settings = Settings()  # Make it constructor.Make an instance.

    screen = pygame.display.set_mode(
        (game_settings.screen_width,
         game_settings.screen_height))  # Set screen size
    alien = Alien(game_settings, screen)  # Make Alien.
    pygame.display.set_caption("Alien Shooter")

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

    ship = Ship(screen, game_settings)  # Make a a ship.

    stats = GameStats(
        game_settings)  # Create an instance to store game statistics.

    sb = ScoreBoard(game_settings, screen, stats)
    bullets = Group()  # Make a group of bullets.
    aliens = Group()  # # Make a group of aliens.

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

    # Start main loop for the game.
    while True:
        # Watch Keyboard and Mouse events.
        gf.check_events(ship, game_settings, screen, bullets, play_button,
                        stats, aliens, sb)
        if stats.game_active:
            ship.update()
            gf.update_bullets(bullets, aliens, game_settings, screen, ship,
                              stats, sb)  # Updating bullets.
            gf.update_aliens(game_settings, aliens, ship, stats, screen,
                             bullets, sb)  # Update aliens.
        # Updating or loading the screen.
        gf.update_screen(game_settings, screen, ship, bullets, aliens,
                         play_button, stats, sb)
Ejemplo n.º 12
0
def run_game():
    # init game and create display object
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Example Game")

    # create ship
    ship = Ship(game_settings, screen)
    bullets = Group()
    #Create alien group
    aliens = Group()
    gf.create_fleet(game_settings, screen, aliens)

    while True:
        gf.check_events(game_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        #gf.update_aliens(game_settings, alien)
        gf.update_screen(game_settings, screen, ship, aliens, bullets)
Ejemplo n.º 13
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))
    pygame.display.set_caption("Alien Invasion")
    #Make a ship
    ship = Ship(ai_settings, screen)
    #Make a group to store bullets in
    bullets = Group()
    aliens = Group()
    #Make an alien
    gf.create_fleet(ai_settings, screen, ship, aliens)
    # Start the main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_aliens(ai_settings, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Ejemplo n.º 14
0
def run_game():

    #Initialize game and create a screen object.
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Stars")

    # Make a group of stars.
    stars = Group()

    # Create the fleet of stars.

    functions.create_fleet(settings, screen, stars)

    # Start the main loop for the game.

    while True:

        functions.check_events()
        functions.update_screen(settings, screen, stars)
Ejemplo n.º 15
0
def run_game():
    # 初始化游戏并创建屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("外星人")

    # 创建play按钮
    play_button = Button(ai_settings, screen, "play")

    # 创建外星人
    alien = Alien(ai_settings, screen)

    # 创建一艘飞船
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    # 创建用于储存数据的实例
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # 创建外星人群
    fun.create_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏的主循环
    while True:
        fun.check_events(ai_settings, screen, stats, play_button, ship, aliens,
                         bullets)
        if stats.game:
            ship.update()
            fun.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                               bullets)
            fun.update_aliens(ai_settings, stats, screen, ship, aliens,
                              bullets)
        fun.update_screen(ai_settings, screen, stats, sb, ship, aliens,
                          bullets, play_button)
Ejemplo n.º 16
0
def run_game():
	#Initialize and create screen project
	pygame.init()
	game_settings = Settings()
#	screen = pygame.display.set_mode((1200,800))
	screen = pygame.display.set_mode(
		(game_settings.screen_width, game_settings.screen_height))
	pygame.display.set_caption("Rocket game")
	
	# make a rocket
	rocket = Rocket(game_settings, screen)
	# Make a group to store bullets in.
	bullets = Group()	
	aliens = Group()
	
	fn.create_fleet(game_settings, screen, rocket, aliens)
	# Main loop
	while True:
		# Watch for keyboard and mouse events
		fn.check_events(game_settings, screen, rocket, bullets)
		rocket.update()
		fn.update_bullets(bullets)				
		fn.update_screen(game_settings, screen, rocket, aliens, bullets)
def run_game():
        #Initialze and create a screen object
        pygame.init()
        ai_set = Settings()
        screen = pygame.display.set_mode((ai_set.screen_width, ai_set.screen_height))
        pygame.display.set_caption("Alien Invasion")

        #play button
        play_button = Button(ai_set, screen, "PLAY")

        #create game stats
        stats = GameStats(ai_set)
        sb = Scoreboard(ai_set, screen, stats)

        #create the Ship
        ship = Ship(ai_set, screen)
        bullets = Group()
        #alien group
        aliens = Group()

        # setting background color
        bg_color = (26, 48, 85)

        #make an alien
        # alien = Alien(ai_set, screen)
        #make fleet of aliens
        fu.create_fleet(ai_set, screen, ship, aliens)

        while True:
            fu.check_events(ai_set, screen, stats, sb, play_button, ship, aliens, bullets)
            if stats.game_active:
                ship.update()
                fu.update_bullets(ai_set, screen, stats, sb, ship, aliens, bullets)
                fu.update_aliens(ai_set, stats, screen, sb, ship, aliens, bullets)
            #Redraw screen during each pass of loop
            fu.update_screen(ai_set, screen, stats, sb, ship, aliens, bullets, play_button)
Ejemplo n.º 18
0
def run_game():
    pg.init()
    bullet_sound = pg.mixer.Sound("Bullet.wav")
    pg.mixer.music.load("music.wav")
    AI = Settings()
    stats = Gamestats(AI)
    # to store the bullets
    alien_bullets_shoot = Group()
    bullets = Group()
    aliens = Group()
    screen = pg.display.set_mode((AI.screen_width, AI.screen_height))
    pg.display.set_caption("Space Wars")
    print(str(AI.screen_width) + " " + str(AI.screen_height))
    my_ship = ship(AI, screen, "my_ship.png", AI.screen_width / 2,
                   AI.screen_height - 30)
    wallpaper = ship(AI, screen, "space.png", AI.screen_width / 2,
                     AI.screen_height)
    # To make a play button
    play_button = Button(AI, screen, "Play", AI.screen_width / 2 - 50,
                         AI.screen_height / 2 - 150, 42, (0, 0, 255),
                         (0, 255, 0), 0)
    exit_button = Button(AI, screen, "Exit", AI.screen_width / 2 - 50,
                         AI.screen_height / 2 + 50, 42, (0, 0, 255),
                         (0, 255, 0), 0)
    scoreboard = Button(AI, screen, "Leaderboard", AI.screen_width / 2 - 50,
                        AI.screen_height / 2 - 50, 40, (0, 0, 255),
                        (0, 255, 0), 50)
    GameOver = Button(AI, screen, "Game over", AI.screen_width / 2 - 50,
                      AI.screen_height / 2, 50, (0, 0, 0), (0, 255, 0), 0)
    bullet = Bullet(AI, screen, my_ship)
    no_aliens = f.find_no_aliens(AI, screen, "alienship.png")
    temp = 0
    x = []
    count = 0
    tmp = random.randint(8, no_aliens)
    for c in range(tmp):
        x.append(c + 1)
    random.shuffle(x)
    pg.mixer.music.play(-1)
    while True:
        with open("file.txt") as score:
            last_score = score.read()
        if stats.ship_left > 0 and stats.game_active:
            count = 1
            if len(aliens) == 0:
                bullets.empty()
                if stats.game_active:
                    AI.increase_speed()
                    AI.score_increase += 2
                    AI.player_level += 1
                temp = 0
                x = []
                tmp = random.randint(no_aliens - 4, no_aliens)
                for c in range(tmp):
                    x.append(c + 1)
                    random.shuffle(x)
            f.event_check(AI, screen, my_ship, bullets, stats, play_button,
                          aliens, bullets, bullet_sound, exit_button)
            if stats.game_active:
                if temp < tmp:
                    temp = f.create_fleet(AI, screen, aliens, "alienship.png",
                                          no_aliens, temp, x)
                my_ship.update()
                f.bullets_collision_check(AI, aliens, bullets)
                f.update_screen(AI, screen, my_ship, bullets, aliens, stats,
                                "my_ship.png", alien_bullets_shoot, last_score)
                delete_bullets(bullet, bullets)
                f.display_aliens(screen, AI, aliens, my_ship, stats, bullets)
            if not stats.game_active:
                wallpaper.blitme()
                play_button.draw_button()
                exit_button.draw_button()
                scoreboard.draw_button()
            pg.display.update()
        else:
            if count == 1:
                c = 5
                if int(last_score) < int(AI.player_score):
                    with open("file.txt", 'w') as file_object:
                        file_object.write(str(AI.player_score))
                pg.mixer.music.pause()
                while c > 0:
                    screen.fill((0, 0, 0))
                    msg = "Re-directing to main menu in....... " + str(c)
                    new_game = Button(AI, screen, msg,
                                      AI.screen_width / 2 - 100, 30, 25,
                                      (0, 0, 0), (255, 0, 0), 0)
                    new_game.draw_button()
                    GameOver.draw_button()
                    pg.display.update()
                    time.sleep(1)
                    c -= 1
                count = 0
            elif count == 0:
                wallpaper.blitme()
                play_button.draw_button()
                exit_button.draw_button()
                scoreboard.draw_button()
                pg.display.update()
                stats.game_active = False
                f.event_check(AI, screen, my_ship, bullets, stats, play_button,
                              aliens, bullets, bullet_sound, exit_button)
                pg.mixer.music.unpause()

    pg.display.flip()