本文整理汇总了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)
示例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
示例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)
示例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()
示例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