Python全系列 教程
3567个小节阅读:5929.3k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
实现发射子弹方法
xxxxxxxxxx
41 def shot(self):
2 num = random.randint(1,1000)
3 if num <= 20:
4 return Bullet(self)
敌方坦克加入窗口后,发射子弹,并将子弹添加到敌方子弹列表中
xxxxxxxxxx
121 #将敌方坦克加入到窗口中
2 def blitEnemyTank(self):
3 for eTank in MainGame.EnemyTank_list:
4 eTank.displayTank()
5 #坦克移动的方法
6 eTank.randMove()
7 #调用敌方坦克的射击
8 eBullet = eTank.shot()
9 #如果子弹为None。不加入到列表
10 if eBullet:
11 # 将子弹存储敌方子弹列表
12 MainGame.Enemy_bullet_list.append(eBullet)
将敌方发射的子弹添加到窗口
xxxxxxxxxx
101 #将敌方子弹加入到窗口中
2 def blitEnemyBullet(self):
3 for eBullet in MainGame.Enemy_bullet_list:
4 # 如果子弹还活着,绘制出来,否则,直接从列表中移除该子弹
5 if eBullet.live:
6 eBullet.displayBullet()
7 # 让子弹移动
8 eBullet.bulletMove()
9 else:
10 MainGame.Enemy_bullet_list.remove(eBullet)
运行结果