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


Python pygame.sprite方法代码示例

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


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

示例1: check_bullet_alien_collision

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import sprite [as 别名]
def check_bullet_alien_collision(ai_settings: Settings, stats: GameStats, game_items: GameItems):
    """Update the game when a bullet hits an alien(s)."""

    # Get rid of bullet and aliens that have collided.
    collision = pygame.sprite.groupcollide(game_items.bullets, game_items.aliens, True, True)
    if collision:
        for aliens_hit_list in collision.values():
            stats.score += ai_settings.alien_points * len(aliens_hit_list)
            game_items.sb.prep_score()
        check_high_score(stats, game_items)

    # Create new fleet after fleet is empty.
    if len(game_items.aliens.sprites()) == 0:
        game_items.bullets.empty()
        ai_settings.increase_speed()
        stats.level += 1
        game_items.sb.prep_level()
        create_fleet(ai_settings, game_items) 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:20,代码来源:game_functions.py

示例2: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import sprite [as 别名]
def update(self):
        # if self.just_happened is not None:
        #     print(self.just_happened)
        from_top = 100

        if self.just_happened == 'offscreen':
            self.dirty = True
            self.rect.x = -1000
            self.rect.y = -1000
            sfx('foot_elephant.ogg', stop=1)
        elif self.just_happened == 'poise left':
            self.rect.x = 0
            self.rect.y = from_top - self.height
            self.dirty = True
            sfx('foot_elephant.ogg', play=1)
        elif self.just_happened == 'stomp left':
            self.rect.y = self.scene.cat_wire_height - self.height#(self.height - self.image.get_height()) - self.scene.cat_wire_height
            self.rect.x = 0
            self.dirty = True

            if pygame.sprite.collide_rect(self, self.scene.cat):
                self.scene.reset_on_death()
                self.dirty = True

        elif self.just_happened == 'poise right':
            self.rect.x = self.width//2
            self.rect.y = from_top - self.height
            self.dirty = True
            sfx('foot_elephant.ogg', play=1)
        elif self.just_happened == 'stomp right':
            self.rect.x = self.width//2
            self.rect.y = self.scene.cat_wire_height - self.height
            self.dirty = True
            if pygame.sprite.collide_rect(self, self.scene.cat):
                self.scene.reset_on_death()
                self.dirty = True 
开发者ID:pygame,项目名称:stuntcat,代码行数:38,代码来源:cat3.py

示例3: update_aliens

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import sprite [as 别名]
def update_aliens(ai_settings: Settings, stats: GameStats, game_items: GameItems):
    """Update position for each alien."""
    check_fleet_edges(ai_settings, game_items.aliens)
    game_items.aliens.update(stats)

    # Collision between ship and aliens.
    if pygame.sprite.spritecollideany(game_items.ship, game_items.aliens):
        ship_hit(ai_settings, stats, game_items)
    check_aliens_bottom(ai_settings, stats, game_items) 
开发者ID:goswami-rahul,项目名称:alien-invasion-game,代码行数:11,代码来源:game_functions.py

示例4: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import sprite [as 别名]
def __init__(self, imagepath):
        pygame.sprite.DirtySprite.__init__(self)
        self.image = pygame.image.load(imagepath).convert()
        self.rect = self.image.get_rect() 
开发者ID:tobykurien,项目名称:rpi_lcars,代码行数:6,代码来源:demo.py

示例5: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import sprite [as 别名]
def __init__(self):
##        pygame.sprite.Sprite.__init__(self)
        FRG.DirtySprite.__init__(self)
        self.image = Thingy.images[0]
        self.rect = self.image.get_rect()
        self.rect.x = randint(0, screen_dims[0])
        self.rect.y = randint(0, screen_dims[1])
        #self.vel = [randint(-10, 10), randint(-10, 10)]
        self.vel = [randint(-1, 1), randint(-1, 1)]
        self.dirty = 2 
开发者ID:wistbean,项目名称:fxxkpython,代码行数:12,代码来源:testsprite.py


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