英雄子弹是否和敌机碰撞

This commit is contained in:
206530321 2021-06-14 23:58:58 +08:00
parent 81b690770d
commit ada6e8dbae
1 changed files with 20 additions and 0 deletions

20
play.py
View File

@ -249,3 +249,23 @@ class MainScene(object):
# 爆炸对象状态设置为True
bomb.visible = True
# # 检测英雄子弹是否和敌机碰撞
for enemy in self.enemy_list:
# 击中敌人飞机的英雄飞机子弹
herobullets = pygame.sprite.spritecollide(
enemy, self.hero.bullets, False, pygame.sprite.collide_mask)
if herobullets:
for bullet in herobullets:
if not bullet.visible:
continue
bullet.visible = False
for bomb in self.bombs:
if not bomb.visible:
bomb.set_pos(enemy.rect[0], enemy.rect[1])
bomb.visible = True
mus = pygame.mixer.Sound('./musics/boom_music.ogg')
mus.set_volume(6)
mus.play()
enemy.visible = False
self.hero_score += enemy.score