當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。