本文整理匯總了Python中pygame.sprite.Group.copy方法的典型用法代碼示例。如果您正苦於以下問題:Python Group.copy方法的具體用法?Python Group.copy怎麽用?Python Group.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pygame.sprite.Group
的用法示例。
在下文中一共展示了Group.copy方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import copy [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")
# 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))
示例2: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import copy [as 別名]
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))
示例3: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import copy [as 別名]
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))
示例4: WvmSpritesList
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import copy [as 別名]
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)
示例5: run_game
# 需要導入模塊: from pygame.sprite import Group [as 別名]
# 或者: from pygame.sprite.Group import copy [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)
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))