BOSS能力强,想要更多花样,每次不再发射一颗子弹,要两颗,三颗,更多,更多

可以先看下我之前的日子 子弹的花样年华

https://blog.csdn.net/hailler1119/article/details/88607955

发射方式的改变,只是发射点的不同,发射子弹的角度不同而已。

例如同时发射两颗子弹的实现方式

            interval = -self.rect.width // 4for v in range(0,2):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.x - bullet.rect.width//2 + intervalpos_y = boss_fire_pos.ybullet.set_pos(pos_x,pos_y)interval = self.rect.width //4

位置在左右1/4处,新建两颗子弹,计算位置,发射。

为了增加灵活性,在boss.py的fire()函数里增加两个参数,默认值均为零。

def fire(self, firetype=0, bullettype=0):

firetype 设置发射方式,单个、两个,多个等。bullettype 设置子弹类型,这里只是实现了图片的不同。

加了测试,随机产生发射方式和子弹类型,把boss.py改为如下代码:其他的文件依旧不用改。

from setting import *
from animation import *
from lifebar import *
from bossbullet import *class BossPlane(pygame.sprite.Sprite):def __init__(self):self._layer = 2self.groups = allgroup, bossgrouppygame.sprite.Sprite.__init__(self, self.groups)#设置飞机动态图像self.animation = Animation()self.images = self.animation.load_images('images/boss/', 0, 10, '.png')self.image = self.images[1]self.mask = pygame.mask.from_surface(self.image)# 飞机矩形self.rect = self.image.get_rect()self.bullet_speed = 4self.x_speed = 2self.y_speed = 2#默认移动方式self.motion_type = 1# 飞机子弹发射间隔 毫秒self.firetype = 0self.bullettype = 0self.interval = 500# 飞机子弹发射当前时间self.start_time = pygame.time.get_ticks()self.HP = 500self.HPFULL = 500lifebar = Lifebar(self)def update(self):# self.HP -= 1if self.HP <= 0:self.kill()#更新飞机当前图像if random.randint(0, 50) == 1:self.motion_type = random.randint(0, 1)self.x_speed = random.randint(-2, 3)self.y_speed = random.randint(-3, 2)self.image = self.animation.get_current_image()if self.motion_type == 0:if self.rect.x + self.rect.width > SCENEWIDTH or self.rect.x < 0:self.x_speed = -self.x_speed# self.rect.y += self.y_speedself.rect.x += self.x_speedelif self.motion_type == 1:if self.rect.x + self.rect.width > SCENEWIDTH or self.rect.x < 0:self.x_speed = -self.x_speedif self.rect.y + self.rect.height > SCENEHEIGHT or self.rect.y < 0:self.y_speed = -self.y_speedself.rect.x += self.x_speedself.rect.y += self.y_speedself.fire(random.randint(0,8),random.randint(0,12))def fire(self, firetype=0, bullettype=0):#时间判断,不到发射间隔,不射current_time = pygame.time.get_ticks()pass_time = current_time - self.start_timeif pass_time < self.interval:returnself.start_time = current_timeself.firetype = firetypeself.bullettype  = bullettype#boss 子弹的发射位置当然是下部中心boss_fire_pos = vect(self.rect.midbottom[0],self.rect.midbottom[1])#单颗子弹if firetype == 0:bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.x - bullet.rect.width // 2pos_y = boss_fire_pos.ybullet.set_pos(pos_x, pos_y)# 两个elif firetype == 1:interval = -self.rect.width // 4for v in range(0,2):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.x - bullet.rect.width//2 + intervalpos_y = boss_fire_pos.ybullet.set_pos(pos_x,pos_y)interval = self.rect.width //4#三个elif firetype == 2:interval = -self.rect.width // 4for v in range(0,3):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.x - bullet.rect.width//2 + intervalpos_y = boss_fire_pos.ybullet.set_pos(pos_x,pos_y)interval += self.rect.width //4# 向下30度角elif firetype == 3:for angle in range(75,106,10):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.xpos_y = boss_fire_pos.ybullet.set_speed(self.bullet_speed,angle)bullet.set_pos(pos_x,pos_y)#向下 60度角elif firetype == 4:for angle in range(60,121,10):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.xpos_y = boss_fire_pos.ybullet.set_speed(self.bullet_speed,angle)bullet.set_pos(pos_x,pos_y)#向下 90度角elif firetype ==5:for angle in range(45,136,10):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.xpos_y = boss_fire_pos.ybullet.set_speed(self.bullet_speed,angle)bullet.set_pos(pos_x,pos_y)#向下 180度elif firetype ==6:for angle in range(0,181,10):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.xpos_y = boss_fire_pos.ybullet.set_speed(self.bullet_speed,angle)bullet.set_pos(pos_x,pos_y)#360度elif firetype ==7:for angle in range(0,360,10):bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.xpos_y = boss_fire_pos.ybullet.set_speed(self.bullet_speed,angle)bullet.set_pos(pos_x,pos_y)#一顿乱射else:n = random.randint(10,50)for v in range(0,n):if random.randint(0,4) == 1:bullet = BossBullet()bullet.set_bullet_type(bullettype)pos_x = boss_fire_pos.x - bullet.rect.width // 2pos_y = boss_fire_pos.ybullet.set_pos(pos_x+random.randint(-200,200), pos_y)

效果如下:

https://gitee.com/hailler/boss/tree/master  资源链接

pygame飞机大战用精灵组(sprite)的层(layer)编写(八)BOSS要花样,更多花样(附代码资源下载链接)相关推荐

  1. pygame飞机大战用精灵组(sprite)的层(layer)编写(十三)BOSS想看烟火了

    还是有点郁闷,写了那么久,居然没有一个点赞的. 就当写日记了. 接上篇-- BOSS很纳闷,说好的,要看到打中的效果,可为什么子弹消失了,英雄却没反应. 好好的打英雄的游戏,变成了英雄吃子弹的游戏了. ...

  2. pygame飞机大战用精灵组(sprite)的层(layer)编写(二)BOSS登场了

    BOSS的编写方式是最复杂的,编写完这个,其他的飞机都是小菜. 先从BOSS的动态图形开始吧. 大部分的飞机一张从头到尾一张图片解决,也不觉得怎么样,但是BOSS就是得有BOSS的样子,自拍也比别人多 ...

  3. pygame飞机大战用精灵组层编写英雄系列(八)英雄的终极技能

    最近下载了全民飞机大战的素材库,里面有很多动态的图,又玩了下这个游戏,里面打飞机都有大绝技,觉得我们的英雄也得有个大绝技. 利用手上资源,做了下. 新建一个heroskill.py.和supply的实 ...

  4. pygame飞机大战用精灵组层编写英雄系列(一)英雄也问出处,界面的菜单选择

    前言: BOSS系列写完了,还可以增加些BOSS子弹的发射方式,例如螺旋线,就是把射击的间隔缩短,每颗子弹按照时间间隔发射,每次的发射角度在前次上递增.看起来就是螺旋线发射了. 我的代码发射的子弹和发 ...

  5. pygame飞机大战关于子弹的设计(一)(含源码)

    Exe如下,欢迎试玩! 链接:https://pan.baidu.com/s/1Hw-DP98Jayr-jmE3ZCe9NA 提取码:2xsq 先上图,终极子弹: 我方子弹共有三种模型:基础子弹.双发 ...

  6. 小甲鱼python游戏代码_【小甲鱼】零基础学习python pygame 飞机大战可执行源代码...

    [实例简介] [小甲鱼]零基础学习python pygame 飞机大战可执行源代码,觉得挺有意思,故此分享. [实例截图] [核心代码] 飞机大战 └── 飞机大战 ├── bullet.py ├── ...

  7. pygame之飞机大战 sprite精灵类实现源代码和资源下载链接

    用pygame的sprite 重写了飞机大战 实现功能: 英雄机:按住按键连续发射 子弹:各种子弹,静态的,动态的,不同的子弹不同的伤害. 发射方式:花样的发射方式,单.双.三.45度--,各种发射方 ...

  8. pygame 飞机大战碰撞检查的运用(三)用sprite,实现完美碰撞检查

    目标:实现完美的碰撞检查 前面的只是普通的碰撞检查,用到了矩形框的范围.图像如果都不是矩形,用普通检查,两种已经相碰,但画面显示还未相碰,这就很尴尬了. sprite模块中,有个collide_mas ...

  9. Python程序设计,pygame飞机大战课程设计

    *飞机大战游戏设计 摘 要:根据课程要求,以及面向对象程序设计的编程思想,在Windows操作系统环境下,运用PyCharm编译程序,以Python语言为开发语言,最终实现飞机大战游戏相应的游戏操作功 ...

最新文章

  1. 【ACM】杭电OJ 2048 2049
  2. PyTorch 多机多卡训练:DDP 实战与技巧
  3. Spring IoC 源码系列(一)BeanDefinition 初始化与注册
  4. 数据中台技术及业务发展史与未来趋势展望
  5. 4.4 Triplet 损失
  6. viper4android2.3.1.1,【资源】ViPER4Android FX 音效驱动 v2.3.0.1
  7. 多表连接的三种方式 HASH MERGE NESTED
  8. 压力变送器自动检测系统 技术设计说明书
  9. Python可视化 | 风玫瑰图可视化示例
  10. css 背景颜色默认,css改变文字选择时的默认背景颜色
  11. python在windows与linux下读取doc文件
  12. python的符号怎么打_python plt可视化――打印特殊符号和制作图例代码
  13. 超级计算机预测2月有雪寒潮,寒潮连续南下,冷冬毋庸置疑?权威专家:到明年二月底最终确定...
  14. 汽车UDS诊断详解及Vector相关工具链使用说明——6.1 使用DiVa进行诊断自动化测试
  15. python 中的butter函数
  16. Instant Client package is required for Baic and TNS connection
  17. 初入职场-面试官都会问些什么?(结尾附视频)
  18. 计算机辅助技术基础知识点,计算机辅助设计技术基础知识.PPT
  19. java获取tcpdump_TCPDUMP——抓包、筛选、高级筛选
  20. 艾美捷 IgM (大鼠) ELISA试剂盒实验原理

热门文章

  1. lisp pause 坐标值_lisp 已知坐标绘断面图_测量并写坐标(表格方式) - AutoLISP/Visual LISP...
  2. 【深度相机系列八】结构光深度相机探讨
  3. Linux笔记之浅析关闭防火墙和selinux
  4. webpack开发Vue配置 1
  5. 记录一次idea断点进不去的解决办法和猜测原因
  6. vue3中引入jQuery
  7. 百度一面二面三面 总结
  8. Android 与蓝牙设备配对连接
  9. 杜永光老师讲述微信小店将是电商的新开始
  10. 成都富华力鼎:商家怎么把抖音小店运营起来