Exemplo n.º 1
0
def runGame():  #funcion que iniciara el juego
    pygame.init()
    aiSettings = Config()
    screen = pygame.display.set_mode(
        (aiSettings.screenW, aiSettings.screenH
         ))  #instanciamos el objeto para definir las dimensiones de la ventana
    imagen_defondo = pygame.image.load("images/space.jpg").convert()
    rectangulo = imagen_defondo.get_rect()
    screen.blit(imagen_defondo, (0, 0))
    pygame.display.set_caption("ALIEN INVASION")  #Titulo de nuestra ventana
    pygame.mixer.init()
    pygame.display.init()

    bgCOLOR = (230, 230, 230)

    ship = Ship(aiSettings, screen)
    meteor = Meteor(aiSettings, screen)
    bullets = Group()
    meteoritos = Group()

    tiempo = 1
    puntuacion = 0

    letra = pygame.font.SysFont("Arial", 18)

    while True:

        if tiempo == 1 or tiempo % 100 == 0:
            meteor = Meteor(aiSettings, screen)
            meteoritos.add(meteor)

        gf.check_events(ship, aiSettings, screen, bullets)
        ship.update()
        bullets.update()
        meteoritos.update()
        gf.updateScreen(aiSettings, screen, ship, meteoritos, bullets)

        ship.animation()

        for bullet in bullets.copy():
            if bullet.rect.left >= 1200:
                bullets.remove(bullet)

        for x in meteoritos.copy():
            if x.rect.right <= 0:
                meteoritos.remove(x)

        if pygame.sprite.groupcollide(meteoritos, bullets, True, True):
            puntuacion += 1

            print(puntuacion)

        gf.updateScreen(aiSettings, screen, ship, meteoritos, bullets)
        screen.blit(imagen_defondo, (0, 0))

        tiempo += 1
Exemplo n.º 2
0
def run_game():
    pygame.init()
    # параметры времени (нужно внести в настройки)
    dt = 0
    clock = pygame.time.Clock()

    # создаем объект настроек.
    all_settings = Settings()
    # параметры экрана
    screen = pygame.display.set_mode(
        (all_settings.screen_width, all_settings.screen_height))  # экран

    # создание героя
    hero = Hero(all_settings, screen)

    # создание группы персонажей
    characters = Group()

    # создание группы для хранения пуль
    bullets = Group()
    bullets_right = bullets.copy()  # ?
    bullets_left = bullets.copy()  # ?
    bullets_up = bullets.copy()  # ?
    bullets_down = bullets.copy()  # ?

    # основной цикл
    while True:

        # обновление песонажей
        if len(characters) < 60:
            # размещение группы персонажей
            create_chatacters(all_settings, screen, characters, hero)
        # события
        game_functiun.check_events(all_settings, screen, hero, bullets_right,
                                   bullets_left, bullets_up, bullets_down)
        # обновление
        # герой
        hero.update_hero(dt)
        # группа *патрон*
        bullets.update()
        # группа персонажей
        # characters.update()

        # отображение
        game_functiun.update_screen(all_settings, screen, hero, bullets,
                                    bullets_right, bullets_left, bullets_up,
                                    bullets_down, characters)

        # счетчик времени для отображения кадра
        dt = clock.tick(all_settings.fps)
Exemplo n.º 3
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(screen)
    bullets = Group()

    # alien = Alien(ai_settings, screen)
    aliens = Group()
    gf.create_fleet(ai_settings, screen, aliens)

    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        gf.update_aliens(ai_settings, aliens)
        pygame.sprite.groupcollide(bullets, aliens, True, True)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
        pygame.display.flip()
def run_game():
    #初始化游戏并创建一个屏幕对象
    pygame.init()
    #创建Settings实例存储在ai_settings变量中
    ai_settings = Settings()
    #使用ai_settings的属性screen_width和screen_height
    screen = pygame.display.set_mode(
        (ai_settings.screen_width,ai_settings.screen_height)
    )
    pygame.display.set_caption("Alien Invasion")
    #创建一艘飞船
    #需要传入实参ai_settings
    ship = Ship(ai_settings,screen)
    #创建一个用于存储子弹的编组
    #pygame.sprite.Group类创建一个编组,存储所有有效子弹,类似列表。
    bullets = Group()
    #开始游戏的循环
    while True:
        gf.check_events(ai_settings,screen,ship,bullets)
        #飞船的位置在检测到键盘事件后(但在更新屏幕前)更新。
        ship.update()
        #当对编组调用update()时,编组将自动对其中每个精灵(子弹)调用update()
        bullets.update()
        #删除已消失的子弹
        #不应从列表或编组中删除条目,因此必须遍历编组的副本
        #我们使用了方法copy()来设置for循环
        for bullet in bullets.copy():
            #检查每颗子弹,看看它是否已从屏幕消失。
            if bullet.rect.bottom <= 0:
                #从bullets中删除
                bullets.remove(bullet)
                #显示还有多少子弹
                print(len(bullets))
        gf.update_screen(ai_settings,screen,ship,bullets)
Exemplo n.º 5
0
def run_game():
    # 初始化游戏并创建一个屏幕对象:初始化背景设置,让Pygame能够正确地工作
    pygame.init()

    pw_settings = Settings()
    """调用pygame.display.set_mode()来创建一个名为screen的显示窗口,
    这个游戏的所有图形元素都将在其中绘制。每个元素(如外星人或飞船)都是一个surface对象"""
    screen = pygame.display.set_mode(
        (pw_settings.screen_width, pw_settings.screen_height))

    # 窗口标题
    pygame.display.set_caption('Plane War')

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

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

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

        # 删除已消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))

        gf.update_screen(pw_settings, screen, ship, bullets)
Exemplo n.º 6
0
def run_game():
    # 初始化游戏并建立一个屏幕对象
    pygame.init()  # 初始化pygame
    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()

        # 删除已消失的炮弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        #print(len(bullets))

        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo n.º 7
0
class BulletManager:
    def __init__(self, bullet_stats: BulletStats):
        self._bullets = Group()
        self._bullet_stats = bullet_stats

    def add(self, bullet):
        self._bullets.add(bullet)

    def update(self, elapsed):
        self._bullets.update(elapsed)

        # Get rid of bullets that have disappeared
        for bullet in self._bullets.copy():
            if bullet.rect.bottom <= 0 or bullet.rect.top >= config.screen_height:
                self._bullets.remove(bullet)

    def empty(self):
        self._bullets.empty()

    def draw(self, screen):
        self._bullets.draw(screen)

    def sprites(self):
        return self._bullets.sprites()

    def __iter__(self):
        return self._bullets.__iter__()
Exemplo n.º 8
0
def run_game():
    # 初始化pygame、设置和屏幕对象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_hegiht))
    pygame.display.set_caption("Alien Invasion")

    #创建一艘飞船
    ship = Ship(ai_settings, screen)
    # 创建一个用于存储子弹的编组
    bullets = Group()
    #设置背景颜色
    bg_color = (ai_settings.bg_color)
    #开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        # 删除已消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))
        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo n.º 9
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("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 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(ai_settings, screen, ship, aliens, bullets)
       
        # Get rid of bullets that have disappeared.
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))
        gf.update_aliens(ai_settings, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Exemplo 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("Corona Python")
    play_button = Button(ai_settings, screen, "Play")
    doctor = Doctor(ai_settings, screen)
    bullets = Group()
    viruses = Group()

    stats = GameStats(ai_settings)
    sb = ScoreBoard(ai_settings, screen, stats)

    gf.create_fleet(ai_settings, screen, doctor, viruses)

    while True:
        gf.check_events(ai_settings, screen, stats,
                        sb, play_button, doctor, viruses, bullets)

        if stats.game_active:
            doctor.update()
            gf.update_bullets(ai_settings, screen, stats,
                              sb, doctor, viruses, bullets)
            gf.update_bullets(ai_settings, screen, stats,
                              sb, doctor, viruses, bullets)
            gf.update_viruses(ai_settings, stats, screen,
                              doctor, viruses, bullets)
            for bullet in bullets.copy():
                if bullet.rect.bottom <= 0:
                    bullets.remove(bullet)
            gf.update_screen(ai_settings, screen, stats, sb, doctor,
                             viruses, bullets, play_button)
Exemplo n.º 11
0
def run_game():
    #initial game and make a screen target
    pygame.init()
    setting = Setting()
    screen = pygame.display.set_mode((setting.screen_width, setting.screen_height))
    ship = Ship(setting, screen)
    bullets = Group()
    aliens = Group()
    gf.creat_fleet(setting, screen, aliens)
    pygame.display.set_caption(setting.caption)

    #begin main loop 
    while True:
        #watch keyboard and mouse
        gf.check_events(ship, bullets, setting, screen)

        ship.update_position()
        bullets.update()
        aliens.update()
     
        #delete bullet outside of the screen
        for bullet in bullets.copy():
            if bullet.rect.bottom < 0:
                bullets.remove(bullet)       

        #move aliens
        gf.get_fleet_direction(aliens, setting)

        #kill aliens
        gf.kill(aliens, bullets)

        #refresh screen
        gf.update_screen(screen, setting, ship, bullets, aliens)
Exemplo n.º 12
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()

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

        #监视鼠标键盘事件
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()

        # 删除已消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo 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()
    # Set the background color.
    bg_color = (50, 20, 10)
    # 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, bullets)
        # Get rid of bullets that have disappeared.
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))

        # Watch for keyboard and mouse events.
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
    # 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()
Exemplo n.º 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 a ship.
    ship = Ship(ai_settings, screen)
    # Make a group to store bullets in.
    bullets = Group()

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        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))

        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo 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("Alien Invasion")
    bg_color = (230,230,230)

    ship = Ship(ai_settings,screen)

    bullets = Group()

    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        # 每次循环,都调用ship的update
        ship.update()
        bullets.update()##这个子弹的跟新,子弹往前飞

        ##删除已经消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom<=0:
                bullets.remove(bullet)
        # print(len(bullets)) #用于确认子弹确实消失了

        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo n.º 16
0
def run_game():
    #initialize game and create a screen object.
    pygame.init()
    gamesettings = Settings()
    screen = pygame.display.set_mode(
        (gamesettings.screen_width, gamesettings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    #make a ship
    ship = Ship(gamesettings, screen)
    #make a group to store bullets
    bullets = Group()
    aliens = Group()
    #make an alien
    alien = Alien(gamesettings, screen)
    #create the fleet of aliens
    gf.create_fleet(gamesettings, screen, ship, aliens)

    #start main loop for game
    while True:
        gf.check_events(gamesettings, screen, ship, bullets)
        ship.update()
        bullets.update()

        #get rid of excess bullets
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))
        gf.update_screen(gamesettings, screen, ship, aliens, bullets)
Exemplo n.º 17
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(screen,ai_settings)

	#创建一个子弹编组
	bullets = Group()

	#开始游戏主循环
	while True:

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

		#删除已经消失的子弹
		for bullet in bullets.copy():
			if bullet.rect.bottom <= 0:
				bullets.remove(bullet)
		print(len(bullets) ,end='')

		gf.update_screen(ai_settings, screen, ship, 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")
    # 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))
Exemplo n.º 19
0
def run_game():
    # initialise a game and create a screen object
    pygame.init()
    # initialize pygame settings, and screen settings
    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 a bullet
    bullets = Group()

    # start the main loop of the run_game
    while True:
        # Watch for keyboard and mouse events.
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        # get rid of the bullet that disappear
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
            print(len(bullets))
        gf.update_screen(ai_settings, screen, ship, bullets)

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


          # make the most recently draw screen visible
        pygame.display.flip()
Exemplo n.º 20
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,"Begin")
    stats = GameStats(ai_settings)
    bg_color = (0,255,255)
    sb = Scoreboard(ai_settings,screen,stats)
    #创建船
    ship = Ship(ai_settings,screen)
    #创建储存子弹的数组
    bullets = Group()
    aliens = Group()
    alien = Alien(ai_settings, screen)

    #创建外星人群
    gf.create_fleet(ai_settings, screen, ship, aliens)
    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,stats,sb, ship, aliens, bullets)
            gf.update_aliens(ai_settings, stats,screen,ship, aliens,bullets)

        bullets.update()
        gf.update_screen(ai_settings, screen, stats,sb,ship, aliens, bullets,play_button)


        #删除消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
Exemplo n.º 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 Invasion1.1")
    # 创建一艘飞船
    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()
        bullets.update()
        # gf.update_bullets(bullets)
        # 删除已消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        # gf.update_bullets(bullets)
        gf.update_aliens(ai_settings, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
Exemplo n.º 22
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()

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

        #删除已经消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        #print(len(bullets))

        gf.update_screen(ai_settings, screen, ship, bullets)

        #让最近绘制的屏幕可见
        pygame.display.flip()
Exemplo n.º 23
0
def run_game():
	#Initialize game
	pygame.init()

	ai_settings = Settings()

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

	# Make a ship.
	ship = Ship(screen)	

	stats = GameStats(ai_settings)

	bullets = Group()
	aliens = Group()

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

	#Main loop for the game:
	while  True:
		gf.check_events(ai_settings, ship, bullets)
		gf.update_screen(ai_settings, screen, ship, aliens, bullets)
		gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)

		for bullet in bullets.copy():
			if bullet.rect.bottom <= 0:
				bullets.remove(bullet)
Exemplo n.º 24
0
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))
Exemplo n.º 25
0
def run_game():
    # 初始化屏幕对象
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode(settings.screen_size)
    pygame.display.set_caption(settings.game_name)

    # 创建飞船对象
    ship = Ship(screen)

    # 创建外星人对象
    alien = Alien(screen)

    # 创建子弹的集合列表
    bullets = Group()

    # 创建外星人集合
    aliens = Group()
    while True:
        gf.check_events(ship, bullets, settings)
        ship.update_position()
        bullets.update()
        alien.update()
        gf.update_screen(screen, settings, ship, bullets, alien)

        # 删除超出屏幕的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
Exemplo n.º 26
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")
    ship = Ship(ai_settings, screen)
    stats = GameStats(ai_settings)
    score = Score(ai_settings, screen, stats)
    stats.score = 0
    aliens = Group()
    bullets = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)
    screen.fill(ai_settings.bg_color)
    ship.blitme()
    pygame.display.update()

    while True:
        gf.check_events(ai_settings, screen, stats, score, play_button, ship,
                        aliens, bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, score, ship, aliens,
                              bullets)
            gf.update_aliens(ai_settings, stats, screen, ship, aliens, bullets)
            for bullet in bullets.copy():
                if bullet.rect.bottom <= 0:
                    bullet.remove(bullets)
                    print(len(bullets))
        gf.update_screen(ai_settings, screen, stats, score, ship, aliens,
                         bullets, play_button)
Exemplo n.º 27
0
def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()
    ai_settings = Setting()
    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()
        if ship.bullet_on:
            # 创建一个子弹,并将其加入编组bullet中
            new_bullet = Bullet(ai_settings, screen, ship)
            bullets.add(new_bullet)
        bullets.update()

        # 删除已经消失的子弹
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))

        # 每次循环时都重绘整个屏幕
        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo n.º 28
0
def run_game():
    # Initl 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")

    # create ship
    ship = Ship(ai_settings, screen)
    #create bullet
    bullets = Group()

    # Start game
    while True:

        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        # delect bullet
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        print(len(bullets))

        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo n.º 29
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(ai_settings.caption)
    #创建飞船
    ship = Ship(screen, ai_settings)
    #创建子弹列表
    bullets = Group()
    #开始游戏的主循环
    while True:
        screen.fill(ai_settings.bg_color)
        #监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets)
        #更新飞船位置
        ship.update()
        #更新子弹位置
        bullets.update()
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                bullets.remove(bullet)
        #更新屏幕
        gf.update_screen(ai_settings, screen, ship, bullets)
Exemplo n.º 30
0
def run_game():
    pygame.init()
    # 设置size
    screen = pygame.display.set_mode((1200, 800))
    # 设置title
    pygame.display.set_caption('Alien')
    # init ship
    ship = Ship(screen)
    # init monster
    monster = Group()
    bullets = Group()
    # 随机怪物的数量
    monsters_num = random.uniform(0, 10)
    gf.create_alien(screen, monster, monsters_num)
    while True:
        # 检测键盘事件
        gf.check_events(ship, screen, bullets)
        # 改变自己位置
        ship.update()
        bullets.update()
        monster.update()
        for bullet in bullets.copy():
            if bullet.rect.bottom <= 0:
                print("删除消失的子弹")
                bullets.remove(bullet)
        # 判断怪物是不是被杀死了
        gf.check_bullet_alien_collisions(screen, monster, bullets)
        # 如果自己移动,重绘屏幕
        gf.update_screen(screen, ship, bullets, monster)
Exemplo n.º 31
0
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))
Exemplo n.º 32
0
def run_game():
    target = Target(screen)
    targets = Group()
    charactor = Charactor(screen)
    bullets = Group()
    targets.add(target)
    stats = Game_stat()
    play_button = Button(screen, "play")
    while True:
        check_events(charactor, bullets, stats, play_button, targets)
        screen.fill(bg_color)
        charactor.blitme()
        if stats.game_active:
            check_boundaries(target)
            targets.update()
            charactor.update()
            bullets.update()
            bullet_target(targets, bullets, stats)
            check_fail(bullets, stats)
            for bullet in bullets.copy():
                if bullet.rect.x >= bullet.screen_rect.right:
                    bullets.remove(bullet)
            for bullet in bullets:
                bullet.blitme()
            for target in targets:
                target.blitme()
        if not stats.game_active:
            play_button.draw_button()
        pygame.display.flip()
Exemplo n.º 33
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("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))
Exemplo n.º 34
0
class WvmSpritesList():
    """A class listing all the Sprites of the game."""

    def __init__(self, config, screen):
        """Initialize the sprite list."""
        self.config = config
        self.screen = screen

        #initialize the sprites
        self.wiz = Wizard(config, self)
        self.monsters = Group()
        self.missiles = Group()

    def update_all(self):
        """Update the positions of all sprites."""
        self.update_missiles()
        self.wiz.update()
        self.monsters.update()

    def update_missiles(self):
        """update magic missiles positions"""
        self.missiles.update()
        # remove the missiles that have left the screen
        for mi in self.missiles.copy():
            if mi.rect.left >= self.screen.get_rect().right:
                self.missiles.remove(mi)

    def draw(self):
        self.screen.fill(self.config.bg_color)
        for mi in self.missiles:
            mi.draw_missile()
        self.wiz.blitme()
        for mo in self.monsters:
            mo.blitme()

    def fire_missile(self):
        """Fire a missile if limit not reached yet."""
        if len(self.missiles) < self.wiz.magic_missile_allowed:
            self.missiles.add(MagicMissile(self.config, self))

    def create_monster(self):
        """Create a new monster and place it randomly at the right."""
        monster=Monster(self.config, self)
        #TODO move the monster
        self.monsters.add(monster)
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))