小学生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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

信息化未来

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值