小学生python游戏编程arcade----动画图片实现爆炸效果
前言
接上篇文章继续解绍arcade游戏编程的基本知识。以前子弹射击树木利用粒子实现了爆炸效果,今天注重学习一下,利用图片实现爆炸效果,即管理多组爆炸图片
动画图片实现爆炸效果
1、爆炸类的的实现
1.1爆炸图片
1.2 类的定义
init及update两部分,注释很清楚了
class Explosion(arcade.Sprite):
""" 爆炸动画 """
def __init__(self, texture_list):
super().__init__()
#开始的第一幁
self.current_texture = 0
self.textures = texture_list
def update(self):
# 更新到动画的下一帧。如果我们到了终点,然后删除这个精灵。
self.current_texture += 1
if self.current_texture < len(self.textures):
self.set_texture(self.current_texture)
else:
self.remove_from_sprite_lists()
1.3 爆炸类的引用
def init_explosion(self):
columns = 16
count = 60
sprite_width = 256
sprite_height = 256
file_name = "images/爆炸动画图.png"
# 从精灵表加载爆炸
self.explosion_texture_list = []
self.explosion_texture_list = arcade.load_spritesheet(file_name, sprite_width, sprite_height, columns, count)
1.4 爆炸类的更新
定义一个子弹爆炸类的更新
def update_player_bullet(self):
# 调用更新
self.bullet_list_player.update()
self.explosions_list.update()
for bullet in self.bullet_list_player:
# 检测子弹与敌人碰撞
hit_list = arcade.check_for_collision_with_list(bullet, self.enemy_list)
# 如碰到.
if len(hit_list) > 0:
# 制造爆炸
explosion = Explosion(self.explosion_texture_list)
# 位置
explosion.center_x = hit_list[0].center_x
explosion.center_y = hit_list[0].center_y
# 更新爆炸
explosion.update()
# 添加列表
self.explosions_list.append(explosion)
# 消除子弹
bullet.remove_from_sprite_lists()
# 消除击中敌人
for coin in hit_list:
coin.remove_from_sprite_lists()
# self.score += 1
# 爆炸声音
arcade.sound.play_sound(self.hit_sound)
# 子弹出界
if bullet.bottom > SCREEN_height:
bullet.remove_from_sprite_lists()
def on_update(self, delta_time):
self.update_enemy_bullet()
self.