pygame飞机大战用精灵组层编写英雄系列(六)英雄不满足于五姑娘了
现在不是流行道具吗?为什么我没看到?也每个杂货店让买一下,只能从飞机身上扒。
好在敌机也是与时俱进,随身携带的东西也多起来了。
在supply.py的初始函数改为
def __init__(self):
self._layer = 8
self.groups = allgroup, supplygroup
pygame.sprite.Sprite.__init__(self, self.groups)
index = random.randint(0, 3)
self.supply_types = ['BULLET', 'BOMB', 'LIFE', 'POWER']
self.animation = Animation()
if index == 0:
self.images = self.animation.load_image(
'images/supply/bulletsupply.png', 249, 81, 1, 3)
elif index == 1:
self.images = self.animation.load_image(
'images/supply/bombsupply.png', 303, 98, 1, 3)
elif index == 2:
self.images = self.animation.load_image(
'images/supply/lifesupply.png', 303, 98, 1, 3)
else:
self.images = self.animation.load_image(
'images/supply/powersupply.png', 249, 81, 1, 3)
#必不可少的两条代码
self.image = self.images[0]
self.rect = self.image.get_rect()
self.mask = pygame.mask.from_surface(self.image)
#初设速度、角度
self.x_speed = 2.00
self.y_speed = 2.00
self.speed = 2
self.duration = 20000
self.start_time = pygame.time.get_ticks()
self.supply_type = self.supply_types[index]
一种变四种了,看看效果如何。
先把BOSS日志里的blast.py搞过来,爆炸效果。
在main.py的碰撞检查里,对供给的碰撞检查改为
hero_collide_supply = pygame.sprite.spritecollide(
self.hero, supplygroup, True)
if hero_collide_supply:
for supplytype in hero_collide_supply:
supply = supplytype.supply_type
if supply == 'BULLET':
self.hero.fire_type += 1
elif supply == 'LIFE':
self.hero.HP = self.hero.HPFULL
elif supply == 'BOMB':
# enemy 在两个group里,不能简单的用group.empty来处理。
for enemy in enemygroup:
blast_pos = enemy.rect.center
blast = Blast()
blast.set_pos(blast_pos[0], blast_pos[1])
supply_pos = enemy.rect.center
if random.randint(0, 1) == 0:
supply = Supply()
supply.set_pos(supply_pos[0], supply_pos[1])
enemy.kill()
elif supply == 'POWER':
self.hero.fire_type += 2
为了显示 生命 的重要,
在heroplane.py 的update()函数里
self.HP -= 1