本文整理汇总了Python中sprite.Sprite.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Sprite.clone方法的具体用法?Python Sprite.clone怎么用?Python Sprite.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from sprite import Sprite [as 别名]
# 或者: from sprite.Sprite import clone [as 别名]
def update(self):
# Add new zombies at the top of the screen, if needed.
self.zombieAddCounter += 1
if self.zombieAddCounter == ADDNEWKINDZOMBIE:
self.zombieAddCounter = 0
zombieSize = ZOMBIESIZE
newZombie = Sprite.clone(self.zombieImage, (zombieSize, zombieSize))
newZombie.x = self.s.size[0]
newZombie.y = random.randint(10, self.s.size[1] - zombieSize - 10)
self.zombies.append(newZombie)
# Add new newKindZombies at the top of the screen, if needed.
self.newKindZombieAddCounter += 1
if self.newKindZombieAddCounter == ADDNEWZOMBIERATE:
self.newKindZombieAddCounter = 0
newKindZombiesize = ZOMBIESIZE
newCrawler = Sprite.clone(self.newKindZombieImage, (newKindZombiesize, newKindZombiesize))
newCrawler.x = self.s.size[0]
newCrawler.y = random.randint(10, self.s.size[1] - newKindZombiesize - 10)
self.newKindZombies.append(newCrawler)
# add new bullet
self.bulletAddCounter += 1
if self.bulletAddCounter >= ADDNEWBULLETRATE and self.shoot == True:
self.bulletAddCounter = 0
newBullet = Sprite.clone(self.bulletImage, (self.bulletRect.width, self.bulletRect.height))
newBullet.x = self.playerRect.centerx + 10
newBullet.y = self.playerRect.centery - 25
self.bullets.append(newBullet)
# Move the player around.
if self.moveUp and self.playerRect.top > 30:
self.playerRect.move_ip(0, -1 * PLAYERMOVERATE)
if self.moveDown and self.playerRect.bottom < self.s.size[1] - 10:
self.playerRect.move_ip(0, PLAYERMOVERATE)
# Move the zombies down.
for z in self.zombies:
z.x = z.x - NORMALZOMBIESPEED
# Move the newKindZombies down.
for c in self.newKindZombies:
c.x = c.x - NEWKINDZOMBIESPEED
# move the bullet
for b in self.bullets:
b.x = b.x + BULLETSPEED
# Delete zombies that have fallen past the bottom.
for z in self.zombies[:]:
if z.rect().left < 0:
self.zombies.remove(z)
self.zombiesGottenPast += 1
# Delete newKindZombies that have fallen past the bottom.
for c in self.newKindZombies[:]:
if c.rect().left < 0:
self.newKindZombies.remove(c)
self.zombiesGottenPast += 1
for b in self.bullets[:]:
if b.rect().right > self.s.size[0]:
self.bullets.remove(b)
# check if the bullet has hit the zombie
for z in self.zombies:
if self.bulletHasHitZombie(z, self.bullets, self.zombies):
self.score += 1
self.zombies.remove(z)
for c in self.newKindZombies:
if self.bulletHasHitCrawler(c, self.bullets, self.newKindZombies):
self.score += 1
self.newKindZombies.remove(c)
# Check if any of the zombies has hit the player.
if self.playerHasHitZombie(self.playerRect, self.zombies):
self.death_by_zombie = True
self.game_over = True
if self.playerHasHitZombie(self.playerRect, self.newKindZombies):
self.death_by_zombie = True
self.game_over = True
# check if score is over MAXGOTTENPASS which means game over
if self.zombiesGottenPast >= MAXGOTTENPASS:
self.game_over = True