1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > python飞机大战爆炸效果实现_python飞机大战添加爆炸效果

python飞机大战爆炸效果实现_python飞机大战添加爆炸效果

时间:2023-09-18 00:07:42

相关推荐

python飞机大战爆炸效果实现_python飞机大战添加爆炸效果

#导入Bomb类fromBomb import Bomb

#修改代码

def update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets,bomb):"""更新子弹的位置,并删除已消失的子弹"""# 更新子弹的位置

bullets.update()

# 删除已消失的子弹for bullet inbullets.copy():if bullet.rect.bottom <= 0:

bullets.remove(bullet)

check_bullet_alien_collisions(ai_settings, screen, stats, sb, ship, aliens, bullets,bomb)

def check_bullet_alien_collisions(ai_settings, screen, stats, sb, ship, aliens, bullets,bomb):

# 检查是否有子弹击中了外星人

# 如果是这样,就删除相应的外星人和子弹""" collisions =pygame.sprite.groupcollide(bullets, aliens, True, True)ifcollisions:for aliens incollisions.values():

stats.score+= ai_settings.alien_points *len(aliens)

sb.prep_score()

check_high_score(stats, sb)""" for bullet inbullets:

# 检查子弹与飞机的碰撞,及击中飞机

collisions=pygame.sprite.groupcollide(aliens, bullets, True, True)ifcollisions:

current_pos=pygame.Vector2(bullet.rect.x, bullet.rect.y)ifbullet.rect.collidepoint(current_pos):

bomb.position[0] = (bullet.rect.x - 20)

bomb.position[1] = (bullet.rect.y - 40)

bomb.visible=Trueif len(aliens) == 0:

# 删除现有的子弹, 加快游戏节奏,并新建一群外星人

bullets.empty()

ai_settings.increase_speed()

# 提高等级

stats.level+= 1sb.prep_level()

create_fleet(ai_settings, screen, ship, aliens)

def update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets,bomb):"""检查是否有外星人到达屏幕边缘

然后更新外星人群中的所有外星人位置"""bomb.action()

check_fleet_edges(ai_settings, aliens)

check_alien_bottom(ai_settings, screen, stats, sb, ship, aliens, bullets)

aliens.update()

# 检测外星人和飞船之间的碰撞ifpygame.sprite.spritecollideany(ship, aliens):

ship_hit(ai_settings, screen, stats, sb, ship, aliens, bullets)

def update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button,introduce_button,bomb):"""更新屏幕上的图像,并切换到新屏幕"""# 每次循环时都重绘屏幕

screen.fill(ai_settings.bg_color)

# 在飞船和外星人后面重绘所有子弹for bullet inbullets.sprites():

bullet.draw_bullet()

ship.blitme()

aliens.draw(screen)

# 绘制爆炸图片

# # 绘制爆炸图片

#self.bomb.draw()

bomb.draw()

# 显示得分

sb.show_score()

# 如果游戏处于非活动状态,就绘制Play按钮ifnot stats.game_active:

play_button.draw_button()

introduce_button.drawintroduce_button()

# 让最近绘制的屏幕可见

pygame.display.flip()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。