当前位置: 首页>>代码示例>>Python>>正文


Python sprite.Group方法代码示例

本文整理汇总了Python中pygame.sprite.Group方法的典型用法代码示例。如果您正苦于以下问题:Python sprite.Group方法的具体用法?Python sprite.Group怎么用?Python sprite.Group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.sprite的用法示例。


在下文中一共展示了sprite.Group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_has

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def test_has( self ):
        " See if AbstractGroup.has() works as expected. "

        self.assertEqual(True, self.s1 in self.ag)

        self.assertEqual(True, self.ag.has(self.s1))

        self.assertEqual(True, self.ag.has([self.s1, self.s2]))

        # see if one of them not being in there.
        self.assertNotEqual(True, self.ag.has([self.s1, self.s2, self.s3]))
        self.assertNotEqual(True, self.ag.has(self.s1, self.s2, self.s3))
        self.assertNotEqual(True, self.ag.has(self.s1,
                                              sprite.Group(self.s2, self.s3)))
        self.assertNotEqual(True, self.ag.has(self.s1, [self.s2, self.s3]))

        # test empty list processing
        self.assertFalse(self.ag.has(*[]))
        self.assertFalse(self.ag.has([]))
        self.assertFalse(self.ag.has([[]]))

        # see if a second AbstractGroup works.
        self.assertEqual(True, self.ag2.has(self.s3)) 
开发者ID:it2school,项目名称:Projects,代码行数:25,代码来源:sprite_test.py

示例2: test_remove

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def test_remove(self):

        # Test removal of 1 sprite
        self.ag.remove(self.s1)
        self.assertFalse(self.ag in self.s1.groups())
        self.assertFalse(self.ag.has(self.s1))

        # Test removal of 2 sprites as 2 arguments
        self.ag2.remove(self.s3, self.s4)
        self.assertFalse(self.ag2 in self.s3.groups())
        self.assertFalse(self.ag2 in self.s4.groups())
        self.assertFalse(self.ag2.has(self.s3, self.s4))

        # Test removal of 4 sprites as a list containing a sprite and a group
        # containing a sprite and another group containing 2 sprites.
        self.ag.add(self.s1, self.s3, self.s4)
        self.ag2.add(self.s3, self.s4)
        g = sprite.Group(self.s2)
        self.ag.remove([self.s1, g], self.ag2)
        self.assertFalse(self.ag in self.s1.groups())
        self.assertFalse(self.ag in self.s2.groups())
        self.assertFalse(self.ag in self.s3.groups())
        self.assertFalse(self.ag in self.s4.groups())
        self.assertFalse(self.ag.has(self.s1, self.s2, self.s3, self.s4)) 
开发者ID:it2school,项目名称:Projects,代码行数:26,代码来源:sprite_test.py

示例3: __init__

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def __init__(self, settings, screen):
        """Initialize the level timer state"""
        self.settings = settings
        self.screen = screen
        self.screen_rect = self.screen.get_rect()
        self.clock = pygame.time.Clock()
        self.frame_image = self.settings.image_res.lcd_frame_image
        self.rect = self.frame_image.get_rect()
        self.digits = Group()
        self.running = True
        self.elapsed_time_ms = 0
        self.last_rect = self.rect
        
        # Create the digits MM:SS:hh
        self.digit_M1 = self.create_and_add_digit(self.digits)
        self.digit_M2 = self.create_and_add_digit(self.digits)
        self.digit_S1 = self.create_and_add_digit(self.digits)
        self.digit_S2 = self.create_and_add_digit(self.digits)
        self.digit_h1 = self.create_and_add_digit(self.digits)
        self.digit_h2 = self.create_and_add_digit(self.digits)

        # Each digit is positioned relative to the frame
        self.position_digits() 
开发者ID:manixaist,项目名称:pyclimber,代码行数:25,代码来源:level_timer.py

示例4: __init__

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def __init__(self, settings, screen, map_indicies, images, block_image, exit_images, player_images, blob_images):
        """Initialize the map and all of its owned objects"""
        self.settings = settings
        self.screen = screen
        self.images = images
        self.indicies = map_indicies
        self.screen_rect = screen.get_rect()
        self.player_bounds_rect = pygame.Rect((0,0), (0,0))
        self.block_image = block_image
        self.block_group = Group()
        self.x_offset = 0
        self.drainrect = pygame.Rect((0,0), (0,0))
        self.blob_exit = None
        self.exit_images = exit_images
        self.player = None
        self.player_images = player_images
        self.blob_images = blob_images
        self.enemies = Group()
        self.new_enemy_counter = 0
        self.level_info = LevelInfo(self.settings, self.screen)
        self.level_timer = LevelTimer(self.settings, self.screen)
        self.bonuses = [] 
开发者ID:manixaist,项目名称:pyclimber,代码行数:24,代码来源:tilemap.py

示例5: run_game

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
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("COMP140??--???????")
    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, sb, screen, ship, aliens, bullets)
        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button) 
开发者ID:tomjlw,项目名称:Galaxian-Against-COMP140,代码行数:22,代码来源:game.py

示例6: run_game

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
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()

    # 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) 
开发者ID:godzoco,项目名称:Pythonlearn,代码行数:24,代码来源:alien_invasion.py

示例7: run_game

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
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()
    
    # 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) 
开发者ID:godzoco,项目名称:Pythonlearn,代码行数:24,代码来源:alien_invasion.py

示例8: run_game

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
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()
    
    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        bullets.update()
        gf.update_screen(ai_settings, screen, ship, bullets) 
开发者ID:godzoco,项目名称:Pythonlearn,代码行数:24,代码来源:alien_invasion.py

示例9: todo_test_update

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def todo_test_update(self):
    
        # __doc__ (as of 2008-08-02) for pygame.sprite.Sprite.update:
    
          # method to control sprite behavior
          # Sprite.update(*args):
          # 
          # The default implementation of this method does nothing; it's just a
          # convenient "hook" that you can override. This method is called by
          # Group.update() with whatever arguments you give it.
          # 
          # There is no need to use this method if not using the convenience 
          # method by the same name in the Group class.
          # 
          # The default implementation of this method does nothing; it's just a
          # convenient "hook" that you can override. This method is called by
          # Group.update() with whatever arguments you give it.
          # 
          # There is no need to use this method if not using the convenience
          # method by the same name in the Group class.
    
        self.fail() 
开发者ID:Plottel,项目名称:AIFun,代码行数:24,代码来源:sprite_test.py

示例10: run_game

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
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)
    # ??????????????
    aliens = Group()
    # ??????
    gf.create_fleet(ai_settings, screen, aliens)
    # ?????????????
    bullets = Group()

    # ????????
    while True:
        # ?????????
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullet(bullets)
        # ????
        gf.update_screen(ai_settings, screen, ship, bullets,aliens) 
开发者ID:langzi1949,项目名称:funing,代码行数:26,代码来源:alien_invasion.py

示例11: setUp

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def setUp(self):
        self.groups = []
        for Group in self.Groups:
            self.groups.append(Group())

        self.sprite = self.Sprite() 
开发者ID:it2school,项目名称:Projects,代码行数:8,代码来源:sprite_test.py

示例12: run_game

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
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()
            # bullets.update()

            # #????????
            # for bullet in bullets.copy():
            #     if bullet.rect.bottom <= 0:
            #         bullets.remove(bullet)
            # #print(len(bullets))
            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) 
开发者ID:samnew,项目名称:alien_invasion,代码行数:43,代码来源:alien_invasion.py

示例13: prep_ships

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def prep_ships(self):
        """??????????"""
        self.ships = Group()
        for ship_number in range(self.stats.ships_left):
            ship = Ship(self.ai_settings, self.screen)
            ship.rect.x = 10 + ship_number * ship.rect.width
            ship.rect.y = 10
            self.ships.add(ship) 
开发者ID:samnew,项目名称:alien_invasion,代码行数:10,代码来源:scoreboard.py

示例14: generate_platforms

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def generate_platforms(self):
        """Make groups of sprites that contain the blocks for the player to stand on"""

        # Every block is contained within the self.player_bounds_rect

        # Find each "row" of tiles that can contain blocks and add some
        # Eligible rows are every 3rd row starting from the 2nd to top, except the very bottom floor
        row_rect = pygame.Rect((self.player_bounds_rect.left, self.player_bounds_rect.top + (self.settings.tile_height * 2)), 
            (self.player_bounds_rect.width, self.settings.tile_width)) 
        
        
        self.block_group.empty()
        for row in range(0, (self.settings.map_number_floors-1)):
            new_group = Group()

            # Each column in the eligble row has 4 valid placements for a block
            # Note - there are more permutations, these are just the ones allowed
            # OO OO OO OO
            # XX OX OX OO
            for col in range(0, self.settings.map_playable_width):
                bounding_rect = pygame.Rect(0, 0, 0,0)
                bounding_rect.top = row_rect.top
                bounding_rect.left = row_rect.left + col * self.settings.tile_width
                self.generate_blocks(bounding_rect, new_group, random.choice([True, False]), random.choice([True, False]))
            
            # Each row is its own group.  This could limit collision checks later
            self.block_group.add(new_group.sprites())
            # Shif the bounding rect down one floor
            row_rect = row_rect.move(0, self.settings.tile_height * 3) 
开发者ID:manixaist,项目名称:pyclimber,代码行数:31,代码来源:tilemap.py

示例15: prep_ships

# 需要导入模块: from pygame import sprite [as 别名]
# 或者: from pygame.sprite import Group [as 别名]
def prep_ships(self):
        self.ships = Group()
        for ship_number in range(self.stats.ships_left):
            ship = Ship(self.ai_settings, self.screen)
            ship.rect.x = 10 + ship_number * ship.rect.width
            ship.rect.y = 10
            self.ships.add(ship) 
开发者ID:tomjlw,项目名称:Galaxian-Against-COMP140,代码行数:9,代码来源:scoreboard.py


注:本文中的pygame.sprite.Group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。