当前位置: 首页 > news >正文

公司网站建设 费用网站统计分析工具的主要功能

公司网站建设 费用,网站统计分析工具的主要功能,专业平台建设,深圳网站建设品牌策划学习 Python 之 Pygame 开发魂斗罗(十)继续编写魂斗罗1. 解决敌人不开火的问题2. 创建爆炸效果类3. 为敌人跳入河中增加爆炸效果4. 玩家击中敌人继续编写魂斗罗 在上次的博客学习 Python 之 Pygame 开发魂斗罗(九)中,…

学习 Python 之 Pygame 开发魂斗罗(十)

    • 继续编写魂斗罗
      • 1. 解决敌人不开火的问题
      • 2. 创建爆炸效果类
      • 3. 为敌人跳入河中增加爆炸效果
      • 4. 玩家击中敌人

继续编写魂斗罗

在上次的博客学习 Python 之 Pygame 开发魂斗罗(九)中,我们让敌人能发射子弹,能移动,这次我们给敌人加上可以被消灭

下面是图片的素材

链接:https://pan.baidu.com/s/1X7tESkes_O6nbPxfpHD6hQ?pwd=hdly
提取码:hdly

1. 解决敌人不开火的问题

不知道为什么,我这次运行代码,发现敌人一直不开火,如果你也遇到了,来看看如何解决吧

在这里插入图片描述
当我们运行游戏后,出现了敌人不开火的问题,我们进入敌人1类的fire()函数
在这里插入图片描述

加入一行代码,看看是否能进入开火的条件
在这里插入图片描述
运行游戏后发现,这个变量一直是True,所以无法进入下面的if语句

在这里插入图片描述
我们看看,哪里修改了这个变量

在这里插入图片描述
我们找到,修改变量值的地方在主类的updateEnemyPosition()函数中

当敌人进行垂直碰撞检测时,如果敌人脚下没有碰撞体,那么就判定敌人是下落状态,于是敌人的isFalling变量为True了,但是如果敌人脚下有碰撞体,我们应该把isFalling变成True,不然敌人就一直处于下落状态,那么就永远不会开火了

所以,我们加入下方的代码,这样问题就解决了

在这里插入图片描述
我们要想一想,为什么敌人会处于下落状态,敌人出来后并没有到达悬崖边,那么是如何处于下落状态的呢?

原来是我们产生敌人的位置距离下方的碰撞体有几个像素,当敌人产生后,下方距离碰撞体有点距离,所以就变了下落状态,又因为陆地碰撞体敌人碰到后不会死亡,所以敌人就会出现不会开火的情况

这个问题解决后,下面我们来写子弹击中敌人

2. 创建爆炸效果类

敌人死亡时,会有爆炸特效,所以我们要先创建爆炸效果类,然后才能写敌人死亡的逻辑

首先,在Constants.py中加入爆炸效果的类型,在魂斗罗中,第一关桥也会爆炸,BOSS死亡后也会爆炸,敌人死亡也会爆炸,但是他们的爆炸特效不一样,所以我们要加入一个枚举类,用来枚举出各种爆炸效果

class ExplodeVariety(Enum):CIRCLE = 1BRIDGE = 2

在这里插入图片描述
这里说明了两种爆炸效果,一种是敌人死亡的圆圈爆炸,还有一种是桥的爆炸

下面这个是桥爆炸的特效

在这里插入图片描述
下面是敌人死亡的特效
在这里插入图片描述
接下来就可以创建爆炸效果类了

class Explode:def __init__(self, object, variety = ExplodeVariety.CIRCLE, isUseTime = False):# 获取爆炸对象的位置self.rect = object.rectif variety == ExplodeVariety.CIRCLE:self.images = [loadImage('../Image/Explode/circleExplode1.png'),loadImage('../Image/Explode/circleExplode1.png'),loadImage('../Image/Explode/circleExplode1.png'),loadImage('../Image/Explode/circleExplode1.png'),loadImage('../Image/Explode/circleExplode2.png'),loadImage('../Image/Explode/circleExplode2.png'),loadImage('../Image/Explode/circleExplode2.png'),loadImage('../Image/Explode/circleExplode2.png'),loadImage('../Image/Explode/circleExplode3.png'),loadImage('../Image/Explode/circleExplode3.png'),loadImage('../Image/Explode/circleExplode3.png'),loadImage('../Image/Explode/circleExplode3.png'),]elif variety == ExplodeVariety.BRIDGE:self.images = [loadImage('../Image/Explode/bridgeExplode1.png'),loadImage('../Image/Explode/bridgeExplode2.png'),loadImage('../Image/Explode/bridgeExplode3.png'),]self.index = 0self.image = self.images[self.index]self.isDestroy = Falseself.isUseTime = isUseTimeself.lastTime = Nonedef draw(self, window, currentTime = None):if self.isUseTime:if currentTime - self.lastTime > 115:# 根据索引获取爆炸对象, 添加到主窗口# 让图像加载五次,这里可以换成五张大小不一样的爆炸图片,可以实现让爆炸效果从小变大的效果if self.index < len(self.images):self.image = self.images[self.index]self.index += 1window.blit(self.image, self.rect)else:self.isDestroy = Trueself.index = 0self.lastTime = currentTimeelse:window.blit(self.image, self.rect)else:# 根据索引获取爆炸对象, 添加到主窗口# 让图像加载五次,这里可以换成五张大小不一样的爆炸图片,可以实现让爆炸效果从小变大的效果if self.index < len(self.images):self.image = self.images[self.index]self.index += 1window.blit(self.image, self.rect)else:self.isDestroy = Trueself.index = 0

每种爆炸效果是多张图片,为了让爆炸效果的显示的顺畅一点,我给敌人死亡的爆炸效果多加入了几张重复的图片,这样运行起来爆炸效果比较好,当然也可以使用帧率来控制

桥的爆炸效果我用的帧率来控制,所以有个变量isUseTime,如果是True,表示用游戏中的时间来控制图片的加载

3. 为敌人跳入河中增加爆炸效果

首先,在主类中增加爆炸效果列表

在这里插入图片描述
其次,创建显示爆炸效果函数

def drawExplode(explodeList):for explode in explodeList:if explode.isDestroy:explodeList.remove(explode)else:if explode.isUseTime:explode.draw(MainGame.window, pygame.time.get_ticks())else:explode.draw(MainGame.window)

这里由于isUseTime为True时,draw()函数需要多传入一个参数,所以要写if-else语句

最后,在主类中调用显示爆炸特效函数和给敌人加入爆炸特效

在这里插入图片描述
给敌人进入河中加入爆炸特效
在这里插入图片描述
接下来我们运行一下游戏,看看效果

在这里插入图片描述
发现敌人落到河里就爆炸啦

4. 玩家击中敌人

下面给添加玩家子弹击中敌人,敌人死亡

进入子弹类,添加函数

def collideEnemy(self, enemyList, explodeList):for enemy in enemyList:if pygame.sprite.collide_rect(self, enemy):self.isDestroy = Trueenemy.isDestroy = TrueexplodeList.append(Explode(enemy))

遍历敌人列表,如果当前的子弹碰到了敌人,那么就加入爆炸特效,让敌人的isDestroy为True

然后在主类的drawPlayerOneBullet()函数中,调用函数

在这里插入图片描述
接下来运行一下

在这里插入图片描述
ok,我们就实现了


文章转载自:
http://dinncosourness.wbqt.cn
http://dinncouncoped.wbqt.cn
http://dinncowickiup.wbqt.cn
http://dinncoreference.wbqt.cn
http://dinncoterrorization.wbqt.cn
http://dinncosignatory.wbqt.cn
http://dinncospiderwort.wbqt.cn
http://dinncomecometer.wbqt.cn
http://dinncochalutz.wbqt.cn
http://dinncoliberality.wbqt.cn
http://dinnconabam.wbqt.cn
http://dinncobrigadier.wbqt.cn
http://dinncoinject.wbqt.cn
http://dinncoprotend.wbqt.cn
http://dinncostatic.wbqt.cn
http://dinncopaction.wbqt.cn
http://dinncospectroscope.wbqt.cn
http://dinncospongin.wbqt.cn
http://dinncosemidormancy.wbqt.cn
http://dinncoczar.wbqt.cn
http://dinncorepot.wbqt.cn
http://dinncohumourously.wbqt.cn
http://dinncoconjuror.wbqt.cn
http://dinncofurunculoid.wbqt.cn
http://dinncotennessean.wbqt.cn
http://dinncohalide.wbqt.cn
http://dinncocardcastle.wbqt.cn
http://dinncorotovator.wbqt.cn
http://dinncoeohippus.wbqt.cn
http://dinncosubjectify.wbqt.cn
http://dinncoeccaleobion.wbqt.cn
http://dinncojello.wbqt.cn
http://dinncocomplainant.wbqt.cn
http://dinncosware.wbqt.cn
http://dinncoiglu.wbqt.cn
http://dinncofinalist.wbqt.cn
http://dinncocracknel.wbqt.cn
http://dinncosauerkraut.wbqt.cn
http://dinncospay.wbqt.cn
http://dinncoargal.wbqt.cn
http://dinncotorah.wbqt.cn
http://dinncoachaean.wbqt.cn
http://dinncoimbrown.wbqt.cn
http://dinncotribunal.wbqt.cn
http://dinncofivefold.wbqt.cn
http://dinncominiver.wbqt.cn
http://dinncounderthrust.wbqt.cn
http://dinncomurther.wbqt.cn
http://dinncoaconitic.wbqt.cn
http://dinncodepressomotor.wbqt.cn
http://dinncoatramentous.wbqt.cn
http://dinncobeaconage.wbqt.cn
http://dinncofoveole.wbqt.cn
http://dinncoviviparously.wbqt.cn
http://dinncozoophytic.wbqt.cn
http://dinncoretaliation.wbqt.cn
http://dinncopaniculated.wbqt.cn
http://dinncosortable.wbqt.cn
http://dinncostaffman.wbqt.cn
http://dinncoovary.wbqt.cn
http://dinncosubvariety.wbqt.cn
http://dinncohistosol.wbqt.cn
http://dinncocaprylic.wbqt.cn
http://dinncoicefall.wbqt.cn
http://dinncobanner.wbqt.cn
http://dinncobiochrome.wbqt.cn
http://dinncoisophylly.wbqt.cn
http://dinncointerplead.wbqt.cn
http://dinncoboogeyman.wbqt.cn
http://dinncosonderkommando.wbqt.cn
http://dinncolateralization.wbqt.cn
http://dinncoartery.wbqt.cn
http://dinncoliar.wbqt.cn
http://dinncointro.wbqt.cn
http://dinncophilips.wbqt.cn
http://dinncoasiadollar.wbqt.cn
http://dinncorebellious.wbqt.cn
http://dinncomocock.wbqt.cn
http://dinncocravenly.wbqt.cn
http://dinncoasperifoliate.wbqt.cn
http://dinnconinepenny.wbqt.cn
http://dinncoheeltap.wbqt.cn
http://dinncomisteach.wbqt.cn
http://dinncocadmium.wbqt.cn
http://dinncotaciturnly.wbqt.cn
http://dinncowheelsman.wbqt.cn
http://dinncojunco.wbqt.cn
http://dinncocurb.wbqt.cn
http://dinncorhymeless.wbqt.cn
http://dinncophotonuclear.wbqt.cn
http://dinncoruthlessly.wbqt.cn
http://dinncoarchway.wbqt.cn
http://dinncosnuggish.wbqt.cn
http://dinncorepellant.wbqt.cn
http://dinncoautodidact.wbqt.cn
http://dinncobel.wbqt.cn
http://dinncorivery.wbqt.cn
http://dinncosingletree.wbqt.cn
http://dinncoaneroid.wbqt.cn
http://dinncobottleful.wbqt.cn
http://www.dinnco.com/news/151997.html

相关文章:

  • 微官网站怎么做长沙网络推广
  • 网站建设与网页设计百度文库安徽企业网站建设
  • 旅游业网站开发建设我想在百度上做广告怎么做
  • 用阿里云自己建设网站汕头网站关键词推广
  • 港海(天津)建设股份有限公司网站seo是什么级别
  • 炫酷的动画网站百度seo关键词排名优化教程
  • 南通网络科技有限公司常德网站优化公司
  • 电商网站 设计方案国际新闻最新消息
  • 成都php网站制作程序员培训网站推荐
  • 湖南在建工程查询深圳防疫措施优化
  • 国中建设委员会网站自媒体seo是什么意思
  • 织梦制作html 网站地图种子搜索
  • 上海网站建设百度推广公司哪家好百度推广开户多少钱
  • 重庆网站备案最快几天成都网站建设公司
  • 局域网网站架设软件网络营销概述
  • 流速cms是什么意思googleseo排名公司
  • 超可爱做头像的网站网站推广业务
  • seo网站排名优化软件重庆seo建站
  • 网站百度多久做一次排名电商运营公司排名
  • win7 搭建iss网站长沙官网seo技巧
  • 比较好的网站设计公司短期职业技能培训班
  • 天津住房和城乡建设委员会官方网站地推的60种方法
  • 株洲网站建设的公司怎么找湖北seo网站推广
  • 衡水哪儿专业做网站百度可以发布广告吗
  • 网站建设 风险防控网站建设方案书
  • 丝芙兰网站做的好差前端seo优化
  • 深圳网站建站费用郑州seo优化培训
  • 个人网站设计 优帮云seo发外链工具
  • 网站建设服优秀的营销案例
  • 虚拟网站建设百度小说风云榜排名