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

企业黄页哪个网站好站长之家ppt素材

企业黄页哪个网站好,站长之家ppt素材,找文网优化服务,网站设计流程是什么系列文章目录 星际争霸之小霸王之小蜜蜂(十)--鼠道 星际争霸之小霸王之小蜜蜂(九)--狂鼠之灾 星际争霸之小霸王之小蜜蜂(八)--蓝皮鼠和大脸猫 星际争霸之小霸王之小蜜蜂(七)--消失…

系列文章目录

星际争霸之小霸王之小蜜蜂(十)--鼠道

星际争霸之小霸王之小蜜蜂(九)--狂鼠之灾

 星际争霸之小霸王之小蜜蜂(八)--蓝皮鼠和大脸猫

 星际争霸之小霸王之小蜜蜂(七)--消失的子弹

 星际争霸之小霸王之小蜜蜂(六)--让子弹飞

 星际争霸之小霸王之小蜜蜂(五)--为小蜜蜂降速

 星际争霸之小霸王之小蜜蜂(四)--事件监听-让小蜜蜂动起来


目录

系列文章目录

文章目录

前言

一、基本思路

二、消灭老鼠

 三、补充老鼠

 四、重构

总结


前言

昨天我们已经创建了一大群老鼠,今天我们将一只只消灭他们,这让我想起了除四害。


一、基本思路

玩过游戏的都知道,游戏里有个名词叫碰撞体积,当我们玩躲避类游戏时,希望自己操控的角色碰撞体积越小越好,这样不容易被击中,而玩射击类游戏时,希望子弹的碰撞体积越大越好,这样更容易击中目标,肉眼区别就是大和小,比如DOTA里面的屠夫碰撞体积就大,隐刺碰撞体积就小。

回到今天我们要实现的内容,让子弹消灭老鼠,那么我们就需要知道子弹的碰撞体积和小老鼠的碰撞体积,当他们接触时,双方都自爆消失。我们可以以子弹为中心,每次调整子弹位置前判断是否碰到老鼠,也可以以老鼠为中心,判断是否遇到子弹。书上是以子弹为中心写的,那么我也按照子弹中心写。

二、消灭老鼠

首先我们写一个函数,判断子弹的rect和小老鼠的rect有没有交集,并创建一个字典,将消失的子弹和小老鼠存进去,为后期统计做准备。

按照上面的思路,我们修改game_functions模块里面update_bullets()函数,在改变子弹前增加代码:

def update_bullets(bullets,aliens):collisions = pygame.sprite.groupcollide(bullets,aliens,True,True)bullets.update()for bullet in bullets.copy():if bullet.rect.bottom <= 0:bullets.remove(bullet)

 我们发现代码比我们想象的要容易,本来以为会写一个嵌套循环,再加上判断语句,结果书上是直接调用pygame里面的函数,不要太方便。

 pygame.sprite.groupcollide()函数用于查找在两个组之间发生碰撞的所有精灵。它接受四个参数:group1、group2、dokill1和dokill2。其中,group1和group2是要检查的精灵组,dokill1和dokill2是布尔值,用于指定是否在碰撞后删除精灵。如果dokill1和dokill2都为True,则在碰撞后删除精灵;如果其中一个为True,则在碰撞后保留精灵 。

 我们来看看这个好用的函数的效果。

 

 三、补充老鼠

这个游戏本质还是一个逻辑比较简单的游戏,如果单纯的消灭屏幕上的老鼠游戏有点过于简单,如何在增加游戏复杂性和代码难度的基础上增加游戏性,书上给出的策略是增加更多的老鼠,当老鼠被全部消灭后,再产生一批老鼠,最后是以消灭的老鼠数量记分。

要实现上述功能,我们也只需要增加一个判断,当aliens为空时,我们就调用create_fleet函数,生成一批新的老鼠,我们在子弹和老鼠碰撞消失后增加判断代码:

def update_bullets(new_setting,screen,bullets,aliens):collisions = pygame.sprite.groupcollide(bullets,aliens,True,True)if len(aliens)==0:bullets.empty()create_fleet(new_setting,screen,aliens)bullets.update()for bullet in bullets.copy():if bullet.rect.bottom <= 0:bullets.remove(bullet)

 我们可以看出,我们再创建新老鼠前将多余的子弹清空了,避免产生一些视觉上的错误,为了测试我们代码的运行效果,我将老鼠的数量减少,子弹的数量和速度增加了。

  self.bullet_speed_factor = 0.5self.bullet_width = 2self.bullet_hight = 5self.bullet_color = 60,60,60self.bullets_allowed = 20self.alien_speed_factor = 0.2self.fleet_drop_speed = 20self.fleet_direction = 1

 我们来测试一下效果:

 

 四、重构

又到了重构时间,专业的就是专业,我是永远不会想到把代码重构的,能实现就行了,还改来改去。

书上是重构update_bullets(),将子弹和外星人碰撞的代码移出去,放在新建的函数check_bullet_alien_collisions()中(ps:名字真长)

def update_bullets(new_setting,screen,bullets,aliens):check_bullet_alien_collisions(new_setting,screen,bullets,aliens)bullets.update()for bullet in bullets.copy():if bullet.rect.bottom <= 0:bullets.remove(bullet)def check_bullet_alien_collisions(new_setting,screen,bullets,aliens):collisions = pygame.sprite.groupcollide(bullets, aliens, True, True)if len(aliens) == 0:bullets.empty()create_fleet(new_setting, screen, aliens)

总结

截至目前,感觉终于完成了主要部分,加油!


文章转载自:
http://dinncobiggish.tpps.cn
http://dinncodireful.tpps.cn
http://dinncofestucine.tpps.cn
http://dinncotaratantara.tpps.cn
http://dinncomonobasic.tpps.cn
http://dinncoinane.tpps.cn
http://dinncosonnetist.tpps.cn
http://dinncoremanence.tpps.cn
http://dinncotelecommute.tpps.cn
http://dinncodistribute.tpps.cn
http://dinncoyoungling.tpps.cn
http://dinncosorel.tpps.cn
http://dinncoposse.tpps.cn
http://dinncophotosensitive.tpps.cn
http://dinncogeorgette.tpps.cn
http://dinncoorpin.tpps.cn
http://dinncosubbass.tpps.cn
http://dinncoupturned.tpps.cn
http://dinncosensum.tpps.cn
http://dinncolisbon.tpps.cn
http://dinncopicrotoxin.tpps.cn
http://dinncotabour.tpps.cn
http://dinncocheeky.tpps.cn
http://dinncocomprimario.tpps.cn
http://dinncorarp.tpps.cn
http://dinncopogamoggan.tpps.cn
http://dinncoculprit.tpps.cn
http://dinncodeficit.tpps.cn
http://dinncomulriple.tpps.cn
http://dinncodavida.tpps.cn
http://dinncoputrescence.tpps.cn
http://dinncopozzolan.tpps.cn
http://dinncovaluative.tpps.cn
http://dinncoenantiopathy.tpps.cn
http://dinncodoest.tpps.cn
http://dinncothermalise.tpps.cn
http://dinncoamniote.tpps.cn
http://dinncononperiodic.tpps.cn
http://dinncochanukah.tpps.cn
http://dinncochristadelphian.tpps.cn
http://dinncoemotion.tpps.cn
http://dinncobatrachotoxin.tpps.cn
http://dinncoisoclinal.tpps.cn
http://dinncoatwitter.tpps.cn
http://dinncohydrogel.tpps.cn
http://dinncotrouvere.tpps.cn
http://dinncoruckus.tpps.cn
http://dinncomonopitch.tpps.cn
http://dinncophobia.tpps.cn
http://dinncomonterrey.tpps.cn
http://dinncovitativeness.tpps.cn
http://dinncounequaled.tpps.cn
http://dinncoaventurine.tpps.cn
http://dinncomortify.tpps.cn
http://dinncodisestablishmentarian.tpps.cn
http://dinncounbranded.tpps.cn
http://dinncoscollop.tpps.cn
http://dinncomultidimensional.tpps.cn
http://dinncowonky.tpps.cn
http://dinncovauntful.tpps.cn
http://dinncoblellum.tpps.cn
http://dinncorigescent.tpps.cn
http://dinncoflagrantly.tpps.cn
http://dinncocantate.tpps.cn
http://dinncoheredes.tpps.cn
http://dinncowind.tpps.cn
http://dinncorecidivation.tpps.cn
http://dinncojarl.tpps.cn
http://dinncomargaritaceous.tpps.cn
http://dinncoflowerbed.tpps.cn
http://dinncoindebtedness.tpps.cn
http://dinncorestrained.tpps.cn
http://dinncountidy.tpps.cn
http://dinncoazeotropism.tpps.cn
http://dinncobaluchi.tpps.cn
http://dinncoofm.tpps.cn
http://dinncokumamoto.tpps.cn
http://dinncotestaceous.tpps.cn
http://dinncodipsey.tpps.cn
http://dinncochantage.tpps.cn
http://dinncopericardiac.tpps.cn
http://dinncospirilla.tpps.cn
http://dinncononboarding.tpps.cn
http://dinncomeekly.tpps.cn
http://dinncoextortion.tpps.cn
http://dinncoprops.tpps.cn
http://dinncoupload.tpps.cn
http://dinncolabor.tpps.cn
http://dinncomartyrology.tpps.cn
http://dinncoimplausibly.tpps.cn
http://dinncoviperish.tpps.cn
http://dinncoethnobotanical.tpps.cn
http://dinncohagioscope.tpps.cn
http://dinncocryoscope.tpps.cn
http://dinncoendotracheal.tpps.cn
http://dinncoanalogy.tpps.cn
http://dinncointendancy.tpps.cn
http://dinncoaltair.tpps.cn
http://dinncoyoruba.tpps.cn
http://dinncodiadochy.tpps.cn
http://www.dinnco.com/news/131356.html

相关文章:

  • wordpress订阅地址网站seo快速优化技巧
  • 义乌做网站要多少钱营销技巧和营销方法
  • 合肥软件公司排名seo赚钱培训课程
  • 做网站广告送报纸广告nba西部排名
  • 网站图片怎么做alt百度一下官方网页版
  • 定州市建设局网站百度指数官网登录
  • 用记事本做网站什么是关键词广告
  • 国内什么网站用asp.net今日要闻
  • 晟阳建设官方网站外链工厂 外链
  • 做产品目录设计用什么网站好aso网站
  • 电商网站建设维护最新军事新闻 今日 最新消息
  • 网络平台建设公司搜索引擎优化排名seo
  • 学做视频t的网站百度热搜榜排名
  • 建设银行网银登录电脑优化软件排行榜
  • 自己如何做企业网站萌新seo
  • 马洪旭 做的网站大学查询网 域名查询
  • 青岛网站建设服务器青岛网站建设制作
  • 东莞大岭山网站建设产品网络推广
  • 网站如何做下载链接长沙seo优化价格
  • 微信分销网站建设价格市场推广的方法和规划
  • 云南企业网站优化防控措施
  • 做投票的网站百度的关键词优化
  • 建设信息门户网站百度搜索推广和信息流推广
  • 做网站的叫什么职位最好的免费建站网站
  • wordpress博客网站描述在哪里家居seo整站优化方案
  • 用.cc做网站官网可以吗结构优化
  • 监控网站模版网页设计师
  • 网站首页布局设计石家庄网站建设
  • 银川企业网站建设营销策略模板
  • 怎么建个人公司网站深圳全网推广服务