def run_game():
    # initialize game and create a screen object.
    # initialize pygame, settings, and 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 ivasion")

    # make a ship.
    ship = Ship(ai_settings, screen)

    # start the main loop for the game.
    while True:


        gf.check_events(ship)
        ship.update()
        gf.update_screen(ai_settings, screen, ship)


        # redraw the screen during each pass through  the loop.
        screen.fill(ai_settings.bg_color)
        ship.blitme()

        # make the most recently drawn screen visible.
        pygame.display.flip()
    def run_game(self):
        """Main function for Space Invaders."""

        # Start the main loop for Space Invaders.
        while True:
            func.check_events(self.settings, self.screen, self.player, self.player_shots)

            self.player.update()

            # Only update shot when there is a shot on the screen.
            if self.player.has_active_shot:
                func.update_player_shots(self.settings, self.game_stats, self.player, self.player_shots, self.shields,
                                         self.invaders, self.invader_shots)

            self.frame_count = func.update_invader_shots(self.settings, self.invader_shots, self.ground_blocks,
                                                         self.shields, self.frame_count, self.player, self.game_stats)

            func.update_invaders(self.settings, self.screen, self.invaders, self.shields, self.invader_shots,
                                 self.player, self.game_stats)

            func.update_screen(self.settings, self.screen, self.scoreboard, self.player, self.player_shots,
                               self.ground_blocks, self.shields, self.invaders,
                               self.invader_shots, self.game_stats)
            # Set max fps.
            self.clock.tick(self.settings.fps)
def run_game():

    # Initialize pygame, settings and screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Snoopvasion")

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

    # Make a ship.
    ship = Ship(ai_settings, screen)
    # Make a group to store bullets in
    bullets = Group()
    aliens = Group()

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

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)

        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
示例#4
0
def run_game():
	#Initializes the settings needed for pygame to run properly
	pygame.init()
	
	aiSettings = Settings()
	#Display mode called 'screen' is made, with 1200 x 800 dimensions
	#Screen is where the game elements are shown
	screen = pygame.display.set_mode(
		(aiSettings.screen_width,aiSettings.screen_height))
	pygame.display.set_caption("Alien Invasion")
	#Sets background colour
	
	stats = GameStats(aiSettings)
	
	
	#Makes a ship on screen
	ship = Ship(aiSettings,screen)
	#Bullets! - make a group called bullets
	bullets = Group()
	#Aliens are made
	aliens = Group()
	
	#Calls on the createFleet function
	gf.createFleet(aiSettings, screen, ship, aliens)
	
	while True:
		gf.check_events(aiSettings,screen,ship,bullets)
		if stats.game_active:
			ship.update()
			gf.updateBullets(aiSettings, screen, ship, aliens, bullets)
			gf.updateAliens(aiSettings, stats, screen, ship, aliens, bullets)
	
		gf.update_screen(aiSettings, screen, ship, aliens, bullets)
示例#5
0
def run_game():
    #Initialize pygame, settings, screen and 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 ship
    ship = Ship(ai_settings ,screen)
    #Make a group to store bullets in
    bullets = Group()
    #Make an alien group
    aliens = Group()
    #Make play button
    play_button = Button(ai_settings, screen, "Play")
    #Create fleet of aliens
    gf.create_fleet(ai_settings, screen, ship, aliens)
    #Create instance to store game statistics and create scoreboard
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    
    #Start main loop for game
    while True:
        #Watch for keyboard/mouse events
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
        
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
            
        #Redraw the screen during each pass through the loop
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
示例#6
0
def run_game():
	# Initialize pygame, settings, and screen object
	pygame.init()
	ai_settings = Settings()
	screen = pygame.display.set_mode(
		(ai_settings.screen_width, ai_settings.screen_height))
	pygame.display.set_caption("Mutha F****n' Alien Invasion")

	# Set the background color.
	# bg_color = (230,230,230)

	# Make a ship, a group of bullets, and a group of aliens.
	ship = Ship(ai_settings, screen)
	bullets = Group()
	aliens = Group()

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

	# # A group to store super bullets in.
	# super_bullets = Group()

	# Start the main loop for the game.
	while True:

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

		# Make the most recently drawn screen visible.
		pygame.display.flip()
示例#7
0
def run_game():
	# Initilize game and create a screen object
	pygame.init()
	ai_settings = Settings()

	# create a display window named screen
	screen = pygame.display.set_mode(
		(ai_settings.screen_width, ai_settings.screen_height))
	pygame.display.set_caption("Alien Invasion")

	# set background color 
	bg_color = (230, 230, 230)

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

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

	# 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_screen(ai_settings, screen, ship, bullets)
def run_game():
    # Inicjalizacja pygame, ustawień i obiektu ekranu.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Inwazja obcych")
    
    # Utworzenie egzemplarza przeznaczonego do przechowywania
    # danych statystycznych dotyczących gry.
    stats = GameStats(ai_settings)
    
    # Zdefiniowanie koloru tła.
    bg_color = (230, 230, 230)
    
    # Utworzenie statku, grupy pocisków oraz grupy obcych.
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    
    # Utworzenie floty obcych.
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # Rozpoczęcie pętli głównej gry.
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
示例#9
0
def run_game():

    # Initialising game, setting and screen objects
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
    pygame.display.set_caption("Space War")

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

    # Make Bullet (Group)
    bullets = Group()

    # Make Alien
    # alien = Alien(ai_settings,screen)
    aliens = Group()

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

    # Fleet of aliens
    gf.create_fleet(ai_settings,screen,ship,aliens)

    # Game loop
    while True:

        # Check for events
        gf.check_events(ai_settings,screen,ship,bullets)
        if stats.game_active:
            # Updates
            ship.update()
            gf.update_bullets(ai_settings,screen,ship,aliens,bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings,screen,ship,aliens,bullets)
示例#10
0
def run_game():
    """初始化pygame、设置和屏幕对象"""
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # 创建button按钮
    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)

    # 开始游戏主循环
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)

        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)
示例#11
0
def run_game():
    # Initialise
    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 the Play button.
    play_button = Button(ai_settings, screen, "Play")

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

    # Make a ship, a group of bullets and a group of aliens.
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    
    # Create the alien fleet
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # main loop
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
def run_game():
    pygame.init()

    ai_settings = Settings()

    """ Screen settings and such"""
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))

    pygame.display.set_caption("Alien Invasion")
    stats = GameStats(ai_settings)

    bg_color = (230, 230, 230)
    """background screen color; grey"""

    ship = Ship(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()
        gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
        gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)

        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))
示例#13
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(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)

    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)

        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)
示例#14
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 the play button.
	play_button = Button(ai_settings,screen, "Play")
	
	# Create an instance to store game stats and create a scoreboard
	stats = GameStats(ai_settings)
	sb = Scoreboard(ai_settings,screen,stats)
	
	#Make a ship, a group of bullets, and a group of aliens.
	ship = Ship(ai_settings,screen)
	bullets = Group()
	aliens = Group()
	
	# Create a fleet of aliens
	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,stats,sb,play_button,ship,aliens,bullets)
		
		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)
示例#15
0
def run_game():
  #inits game and creates 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 the Play Button
  play_button = Button(ai_settings, screen, "Play")

  #Create an instance to store game stats and create a scoreboard 
  stats = GameStats(ai_settings)
  sb = Scoreboard(ai_settings, screen, stats)

  #make a ship
  ship = Ship(ai_settings, screen)
  #Make a group to store bullets in. 
  bullets = Group()
  #make an alien.
  aliens = Group()

  #Creating a fleet of aliens
  gf.create_fleet(ai_settings, screen, ship, aliens)


  #Start the main loop for the game.
  while True:
    gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
    
    if stats.game_active:
      ship.update()
      gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
      gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens, bullets)

    gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
示例#16
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)

    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 创建一个外星人编组
    aliens = Group()

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

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

        # 监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
def run_game():
    #Initialize pygame, settings and 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 the play button
    play_button = Button(ai_settings, screen, "Play")

    #Create a GameStats instance to store game statistics
    stats = GameStats(ai_settings)

    #Make a ship, a group of bullets, and a group of aliens
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

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

    #Start the main loop of the game
    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)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)

        gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets, play_button)
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)
    sb = Scoreboard(ai_settings,screen,stats)

    #创建一艘飞船
    ship = Ship(ai_settings, screen)
    #创建一个用于存储子弹的编组
    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,aliens,bullets)
        #根据移动标志调整飞船的位置
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings,screen,stats,sb,ship,aliens,bullets)
            gf.update_aliens(ai_settings,stats,screen,sb,ship,aliens,bullets)#更新子弹后再更新外星人位置,因为稍后要检查子弹是否撞到外星人
        #更新屏幕上的图像,并切换到新屏幕
        gf.update_screen(ai_settings,screen,stats,sb,ship,aliens,bullets,play_button)
def run_game():
    # Initialize pygame, settings, and 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, a group of bullets, and a group of aliens.
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

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


    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)

        # Redraw the screen during each pass through the loop.
        screen.fill(ai_settings.bg_color)
        ship.blitme()

        # Make the most recently drawn screen visible.
        pygame.display.flip()
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")
    # make a ship
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    alien = Alien(ai_settings, screen)
    gf.create_fleet(ai_settings, screen, aliens)


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

        # Get rid of bullets that have disappeared.
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))
示例#21
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)

    while True:
        gf.check_events(ship)
        ship.update()
        gf.update_screen(ai_settings, screen, ship)
示例#22
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 the Play button.
	play_button = Button(ai_settings, screen, "Play")


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

	# Make an alien.
	aliens = Group()

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

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

	# Create an instance to store game statistics and scoreboard.
	stats = GameStats(ai_settings)
	sb = Scoreboard(ai_settings, screen, stats)




	# Start the main loop for the game.
	while True:

		# Watch for keyboard and mouse events.
		gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)

		if stats.game_active:
			"""run of there are ships left"""
			
			# Redraw the screen during each pass through the loop.
			ship.update()

			#update bullets status
			gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)

			#update aliens position
			gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens, bullets)

		#redraw screen
		gf.update_screen(ai_settings, screen, stats, sb, aliens, ship, bullets, play_button)
示例#23
0
文件: main.py 项目: ravenusmc/pygame
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('Learn PyGame!')

  #This is what will make a ship object:
  ship = Ship(screen)

  while True: 
    gf.check_events(ship)
    gf.update_screen(ai_settings, screen, ship)
    ship.update()
def run_game():
    # Initialise
    pygame.init()
    config = Configuration()
    screen = pygame.display.set_mode((config.screen_width, config.screen_height))
    pygame.display.set_caption("Wizard vs Monster")
    sprites_list = WvmSpritesList(config, screen)
    sprites_list.create_monster()

    # main loop
    while True:
        gf.check_events(config, sprites_list)
        sprites_list.update_all()
        gf.update_screen(config, sprites_list)
示例#25
0
def run_game():
    """Function to set up a game instance."""
    # Initalize opygame, settings, and 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 the Play button.
    play_button = Button(ai_settings, screen, "Play")

    # Create an instance to store game statistics.
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

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

    # Make a group to store aliens in.
    aliens = Group()

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

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

    # Main loop that controls game flow
    while True:
        # Check for mouse/keyboard events
        gf.check_events(
            ai_settings, screen, stats, sb, play_button, ship,
            aliens, bullets
            )

        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
            )
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("Zombie Tower Ultimate Sonic The Next Generation Super EX")
	play_button = Button(ai_settings, screen, "Play")
	# Set the background color
	ship = Ship(screen, ai_settings)
	bullets = Group()
	bomb = Group()
	lasercheat = Group()
	nuke = Nuke(ai_settings, screen, ship)
	block = Block(ai_settings, screen, nuke)
	wall = Wall(ai_settings, screen, ship)
	lift = Lift(ai_settings, screen, nuke)
	aliens = Group()
	alien = Alien(ai_settings, screen)
	# Start the main loop for the game.
	stats = GameStats(ai_settings, bomb, aliens, bullets)
	sb = Scoreboard(ai_settings, screen, stats)
	gf.create_fleet(ai_settings, screen, ship, aliens)

	while True:

		# Watch for keyboard and mouse events.
		gf.check_events(ai_settings, screen, stats, ship, bullets, lasercheat, aliens, nuke, play_button, bomb, wall, lift)
		if stats.game_active:
			ship.update()
			gf.update_aliens(ai_settings, stats, screen, ship, aliens, bomb, wall)
			ai_settings.counterpnts -= 1
			if ai_settings.counterpnts <=0:
				ai_settings.counterpnts = 60
				stats.score += 1
				sb.prep_score()
			bullets.update()
			bomb.update(aliens, ai_settings, screen)
		gf.update_screen(ai_settings, screen, stats, sb, ship, bullets, lasercheat, aliens, nuke, play_button, wall, bomb, lift, block)
		# Get rid of bullets that have disappeared.

		for bullet in bullets.copy():
			if bullet.rect.right >= 1200:
				bullets.remove(bullet)
		print(len(bullets))
示例#27
0
def run_game():
    """
    Initialize game and create a screen object
    """
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode((game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Rebel Defender")
    clock = pygame.time.Clock()

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

    # Store game statistics
    stats = GameStats(game_settings)

    # Scoreboard
    sb = Scoreboard(game_settings, screen, stats)

    # Make a ship
    ship = Ship(game_settings, screen)
    icon_ship = IconShip(game_settings, screen)

    # Make a a group of enemies
    enemies = Group()
    gf.create_fleet(game_settings, screen, ship, enemies)

    # Make a cache of bullets
    bullets = Group()

    # Make starfield
    starfield = Starfield(game_settings).generate_starfield()

    # Start the main loop of the game
    while True:
        clock.tick(50)

        gf.check_events(game_settings, stats, sb, screen, ship, enemies, bullets, play_button)

        if stats.game_active:
            ship.update()
            gf.update_bullets(game_settings, screen, stats, sb, ship, enemies, bullets)
            gf.update_enemies(game_settings, stats, screen, sb, ship, enemies, bullets)

        gf.update_screen(game_settings, screen, stats, sb, starfield, ship, enemies, bullets, play_button)
示例#28
0
def run_game():
    pygame.init()#初始化背景设置
    # screen = pygame.display.set_mode((900,600))#创建一个游戏窗口
    pygame.display.set_caption('Alien Invasion')

    ai_settings =Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
    ship = Ship(screen)
    # bg_color = (230,230,230)
    while True:
        # for event in pygame.event.get():
        #     if   event.type == pygame.QUIT:
        #            sys.exit()
        # screen.fill(bg_color)
        # pygame.display.flip()
        gf.check_events()

        gf.update_screen(ai_settings,screen,ship)
示例#29
0
def run_game():
    #初始化pygame、设置和屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_with,ai_settings.screen_height))
    pygame.display.set_caption("Alien Tnvasion")
    #创建一艘飞船
    ship = Ship(ai_settings,screen)
    #创建一个用于存储子弹的编组
    bullets = Group()

    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings,screen,ship,bullets)
        ship.update()
        gf.updata_bullets(bullets)

        gf.update_screen(ai_settings,screen,ship,bullets)
示例#30
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)

    # Start the main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        gf.check_events(ship)
        # Update the ship's status.
        ship.update()
        # Draw the current screen.
        gf.update_screen(ai_settings, screen, ship)
示例#31
0
def run_game():
    pygame.init()
    settings = Settings()
    stats = GameStats(settings)
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption('Alien Invasion')

    sb = Scoreboard(screen, settings, stats)
    play_button = Button('Play', screen, settings)
    game_objects = GameObjects(screen, settings)
    gf.create_fleet(game_objects, screen, settings)

    while True:
        gf.check_events(game_objects, sb, play_button, screen, settings, stats)

        if stats.game_active:
            game_objects.ship.update()
            gf.update_bullets(game_objects, sb, screen, settings, stats)
            gf.update_aliens(game_objects, sb, screen, settings, stats)

        gf.update_screen(game_objects, screen, play_button, sb, settings,
                         stats)
示例#32
0
def run_game():
    #Initialize pygame, settings,  and 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, a group of bullets, and a group of aliens.
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

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

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(aliens, bullets)
        gf.update_aliens(ai_settings, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
示例#33
0
def run_game():
    # Inicialization Pygame, settings and screen object.
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption("Cosmic War")

    # Create cat, group of bullets and group of dogs.
    cat = Cat(game_settings, screen)
    bullets = Group()
    # Create dog.
    dogs = Group()

    gf.create_pack(game_settings, screen, dogs)

    # Start main loop of game.
    while True:
        gf.check_events(game_settings, screen, cat, bullets)
        cat.update()
        gf.update_bullets(bullets, dogs)
        gf.update_dogs(game_settings, dogs)
        gf.update_screen(game_settings, screen, cat, bullets, dogs)
示例#34
0
def run_game():
    pygame.init()
    target_settings = Settings()
    screen = pygame.display.set_mode(
        (target_settings.screen_width, target_settings.screen_height))
    pygame.display.set_caption("Shoot The Box")

    play_button = Button(target_settings, screen, "Start")
    stats = GameStats(target_settings)
    sb = Scoreboard(target_settings, screen, stats)
    shooter = Shooter(target_settings, screen)
    target = Target(target_settings, screen)
    bullets = Group()
    while True:
        gf.check_events(target_settings, stats, screen, sb, shooter, target,
                        bullets, play_button)
        if stats.game_active:
            shooter.update()
            gf.update_bullets(target_settings, stats, screen, sb, shooter,
                              target, bullets)
            gf.update_target(target_settings, target)
        gf.update_screen(target_settings, stats, screen, sb, shooter, target,
                         bullets, play_button)
示例#35
0
def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()
    alien_settings = Settings()
    screen = pygame.display.set_mode(
        (alien_settings.screen_width, alien_settings.screen_height))
    pygame.display.set_caption('alien_invasion')
    # 创建一艘飞船
    ship = Ship(alien_settings, screen)
    # 创建一个存储子弹的编组
    bullets = Group()
    # 创建一个外星人编组
    aliens = Group()

    # 创建外星人群
    gf.creat_fleet(alien_settings, screen, aliens)

    # 开始游戏主循环
    while True:
        gf.check_events(alien_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullet(bullets)
        gf.update_screen(alien_settings, screen, ship, aliens, bullets)
示例#36
0
def run_game():
    #initialize game and create 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")

    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

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

    #start the main loop for the game
    while True:
        #checks for mouse and keyboard events
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
        gf.update_aliens(ai_settings, aliens)
        #updates the screen
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    ship = Ship(settings, screen)
    # 创建一个用于存储子弹的编组
    bullets = Group()
    aliens = Group()
    # 设置背景色
    pygame.display.set_caption("Alien Invasion")
    gf.create_fleet(settings, screen, aliens, ship)
    stats = GameStats(settings)

    # 开始游戏的主循环
    while True:
        gf.check_events(settings, screen, ship, bullets)
        bullets.update()
        ship.update()
        gf.update_bullets(settings, screen, ship, aliens, bullets)
        gf.update_aliens(settings, stats, screen, bullets, aliens, ship)
        gf.update_screen(screen, settings, ship, bullets, aliens)
示例#38
0
def run_game():
    #初始化pygame 设置 屏幕对象
    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)
    #开始游戏主循坏
    while True:
        # 监视键盘和鼠标事件
        # for event in pygame.event.get():
        #     if event.type == pygame.QUIT:
        #         sys.exit()
        gf.check_events(ship)
        # # #每次循环时重绘屏幕
        # screen.fill(ai_settings.bg_color)
        # ship.blitme()
        # #让最近绘制的屏幕可见
        # pygame.display.flip()
        ship.update()
        gf.update_screen(ai_settings, screen, ship)
示例#39
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)

    #start the main loop for the game
    while True:

        gf.check_events(ship)
        ship.update()
        gf.update_screen(ai_settings, screen, ship)

        #make the Most recently drawn screen visible
        pygame.display.flip()
示例#40
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 Invation')

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

    #开始游戏的主循环
    while True:
        gf.check_events(ship)

        # #监视键盘和鼠标事件
        # for event in pygame.event.get():
        #     if event.type == pygame.QUIT:
        #         sys.exit()
        ship.update()

        gf.update_screen(ai_settings, screen, ship)
示例#41
0
def run_game():
    pygame.init()
    pygame.display.set_caption('4-Sided Pong')
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screenwidth, settings.screenheight))
    ball = Ball(screen, settings)
    player = Player(screen, settings)
    enemy = Enemy(screen, settings, ball)
    play_button = Button(screen, "Play")
    stats = Stats()

    #ball.start_game()
    while True:
        GF.check_key_events(screen, settings, ball, player, play_button, stats)

        if stats.game_active:

            player.update()
            enemy.update()
            GF.update_ball(ball, player, enemy)
        GF.update_screen(screen, settings, ball, player, enemy, play_button,
                         stats)
示例#42
0
def run_game():
    pygame.init()
    print("start")

    ai_settings = Settings()
    screen = pygame.display.set_mode(ai_settings.screen_size)
    pygame.display.set_caption("Alien Invasion")

    #创建一艘飞船
    ship = Ship(ai_settings, screen)
    #创建一个用于存储子弹的编组
    bullets = Group()
    #创建外星人
    aliens = Group()
    gf.creat_fleet(ai_settings, screen, aliens, ship)
    status = Gs(ai_settings)

    while (True):
        gf.check_events(ai_settings, screen, ship, bullets)
        if status.game_active:
            gf.update_bullets(ai_settings, screen, aliens, ship, bullets)
            gf.update_alien(ai_settings, status, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, ship, bullets, aliens)
示例#43
0
def run_game():
    pygame.init()
    ai_settings = Settings()
    pygame.display.set_caption("Alien Invasion")
    screen = pygame.display.set_mode(
        (ai_settings.get_width(), ai_settings.get_height()))
    # print(dir(screen.get_rect()))
    ship = Ship(screen, ai_settings)
    alien = Alien(ai_settings, screen)
    # print("(x=%d, y=%d)" %(ship.get_rect().x, ship.get_rect().y))
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, aliens, ship)

    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullet(bullets, aliens)
        gf.update_aliens(aliens)
        gf.check_fleet_edges_td(ai_settings, aliens)
        gf.check_fleet_edges_lf(ai_settings, aliens)

        gf.update_screen(ai_settings, screen, ship, bullets, aliens)
示例#44
0
def run_game():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, aliens)
    pygame.display.set_caption("Alien Invasion")
    alien = Alien(ai_settings, screen)
    pygame.mixer.init()
    music = '1.ogg'
    pygame.mixer.music.load(music)
    pygame.mixer.music.set_volume(0.1)
    pygame.mixer.music.play(loops=0, start=0.0)

    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
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)
    bullets = Group()
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        gf.update_screen(ai_settings, screen, ship, bullets)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
        screen.fill(ai_settings.bg_color)
        ship.blitme()
        pygame.display.flip()
        bullets.update()
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))
示例#46
0
def run_game():
    pygame.init()
    g_settings = Settings()
    screen = pygame.display.set_mode(
        (g_settings.screen_width, g_settings.screen_height))
    square_positions = g_settings.get_square_positions()
    squares = gf.get_squares(screen, square_positions)[0]
    dict_squares = gf.get_squares(screen, square_positions)[1]
    keys = dict_squares.keys()
    free_squares = []
    for key in keys:
        free_squares.append(key)

    random = Random()
    random_square = RandomSquare(screen)
    arr_numbers = []
    text = Text(screen, g_settings)
    matrix = Matrix(g_settings)
    while True:

        gf.check_events(random, random_square, g_settings)
        gf.update_screen(screen, g_settings, squares, random, random_square,
                         dict_squares, arr_numbers, free_squares, text, matrix)
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(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)
    bg_color = (230,230,230)
    alien = Alien(ai_settings, screen)


    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)
示例#48
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")

    # Make a ship
    ship = Ship(ai_settings, screen)
    # Make a group to store bullets in.
    bullets = Group()
    aliens = Group()
    game_functions.create_fleet(ai_settings, screen, ship, aliens)

    while True:
        game_functions.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        game_functions.update_bullets(ai_settings, screen, ship, aliens,
                                      bullets)
        game_functions.update_aliens(ai_settings, ship, aliens)
        game_functions.update_screen(ai_settings, screen, ship, aliens,
                                     bullets)
示例#49
0
def run_game():

    ##初始化并创建一个屏幕对象
    pygame.init()
    ai_settings = Settings()

    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screenheight))
    pygame.display.set_caption("Alien invasion")
    ship = Ship(ai_settings, screen)
    bullets = Group()

    bg_color = (230, 230, 230)

    while True:

        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()

        #bullets.update()
        gf.update_bullets(bullets)

        gf.update_screen(ai_settings, screen, ship, bullets)
示例#50
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)

    # Start the main loop for the game.
    while True:
    # Watch for keyboard and mouse events.
        gf.check_events(ship)
        ship.update()
        gf.update_screen(ai_settings, screen, ship)

        # Redraw the screen during each pass through the loop.
        screen.fill(ai_settings.bg_color)
        ship.blitme()
        # Make the most recently drawn screen visible.
        pygame.display.flip()
示例#51
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("外星人入侵")

    # 创建一艘飞船
    ship = Ship(ai_settings, screen)
    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 开始游戏主循环
    while True:
        # 监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets)
        # 更新飞船的位置
        ship.update()
        # 更新外星人位置
        gf.update_bullets(bullets)
        # 绘制新屏幕
        gf.update_screen(ai_settings, screen, ship, bullets)
示例#52
0
def run_game():
    # Inicializa o jogo e cria um objeto para a tela
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # Cria uma espaçonave
    ship = Ship(ai_settings, screen)
    # Cria um grupo no qual serão armazenados os projéteis
    bullets = Group()
    aliens = Group()

    # Cria a frota de alienigenas
    gf.create_fleet(ai_settings, screen, aliens)

    # Inicia o laço principal do jogo
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
示例#53
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("Allien Invasion")
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, aliens)
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        gf.update_aliens(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)
        pygame.display.flip()
def run_game():
    # Initialize pygame, settings, and 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")

    # Set the background color.
    bg_color = (230, 230, 230)

    # Make a ship.
    ship = Ship(ai_settings, screen)
    # Make a group to store bullets in.
    bullets = Group()
    alien = Alien(ai_settings, screen)

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, alien, bullets)
def run_game():
    # initialize the pygame, settings and the screen
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption('Alien Invasion')

    # build a ship
    ship = Ship(ai_settings, screen)

    #build a group to store the bullets
    bullets = Group()

    # start the game's main loop
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)
        gf.update_screen(ai_settings, screen, ship, bullets)

        # let the latest screen can be seen
        pygame.display.flip()
示例#56
0
def run_game():
    pygame.init()
    pygame.display.set_caption("Alien Invasion")

    settings = Settings()

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

    ship = Ship(settings, screen)
    alien = Alien(settings, screen)

    bullets = Group()
    aliens = Group()

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

    while True:
        gf.check_events(settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(aliens, bullets)
        gf.update_aliens(settings, aliens)
        gf.update_screen(settings, screen, ship, aliens, bullets)
def run_game():
    # 1.初始化游戏并创建一个屏幕对象
    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)

    # 创建一个用于存储子弹的编组
    bullets = Group()

    # 2.开始游戏的主循环
    while True:
        # 监视键盘、鼠标、子弹事件
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(bullets)

        # 更新屏幕上的图像,并切换到新屏幕
        gf.update_screen(ai_settings, screen, ship, bullets)
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("Carrot  Invasion")
	
	# Make the Play button.
	play_button = Button(ai_settings, screen, "Play")
	
	# Create an instance to store game statistics.
	stats = GameStats(ai_settings)
	
	# Make a ship
	ship = Ship(ai_settings, screen)
	
	# Make a group to store bullets in.
	bullets = Group()
	
	# Make a group of aliens.
	aliens = Group()
	
	# Create the fleet of aliens.
	gf.create_fleet(ai_settings, screen, ship, aliens)
	
	# Start the main loop for the game
	while True:
		# Watch for the keyboard and mouse events
		gf.check_events(ai_settings, screen, stats, play_button, ship, bullets)
		if stats.game_active:
			ship.update()
			gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
			gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
		
		gf.update_screen(ai_settings, screen, stats, ship, aliens, bullets, play_button)
示例#59
0
def run_game():
    #初始化pygame、设置和屏幕对象
    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 = GameStates(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)

    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets)

        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)
示例#60
0
def run_game():
    # Initialize settings, game and screen object
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

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

    # Create an instance to store game statistics and scoreboard
    stats = GameStats(settings)
    scoreboard = Scoreboard(settings, screen, stats)

    # Make a ship
    ship = Ship(settings, screen)
    # Make a group for storing bullets
    bullets = Group()
    # Make a group of aliens
    aliens = Group()
    game_functions.create_fleet(settings, screen, ship, aliens)

    # main loop of the game
    while True:
        game_functions.check_events(settings, screen, stats, scoreboard,
                                    play_button, ship, aliens, bullets)

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

        game_functions.update_screen(settings, screen, stats, scoreboard, ship,
                                     aliens, bullets, play_button)