python实现微信打飞机游戏的方法

  介绍

小编给大家分享一下python实现微信打飞机游戏的方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获、下面让我们一起去了解一下吧!

具体内容如下

import  pygame   import 随机   import 系统   ,   #初始化   pygame.init ()   pygame.display.set_caption(& # 39;飞机火拼& # 39;)#设置窗口标题   屏幕=,pygame.display.set_mode ((320,, 570), 0,, 32)   pygame.mouse.set_visible (False) #隐藏光标   ,   #加载图片   boom1=pygame.image.load(& # 39; . ./游戏/飞/src/boom1.png& # 39;)   boom2=pygame.image.load(“. ./游戏/飞/src/boom2.png")   子弹=pygame.image.load(& # 39; . ./游戏/飞/src/bullet.png& # 39;)   飞机=pygame.image.load(“. ./游戏/飞/src/plane.png") .convert_alpha ()   敌人=pygame.image.load(& # 39; . ./游戏/飞/src/enemy.png& # 39;)   #设置窗口图标   pygame.display.set_icon(飞机)   背景=pygame.image.load(“. ./游戏/飞/src/bg_01.png")   开始=pygame.image.load(& # 39; . ./游戏/飞/src/start.png& # 39;)   暂停=pygame.image.load(“. ./游戏/飞/src/pause.png")   ,   # pygame.mixer.init ()   # Xexplosion=pygame.mixer.Sound (“explosion.mp3")   # Xbullet=pygame.mixer.Sound(“. ./游戏/飞/声音/bullet.mp3")   # XgameOver=pygame.mixer.Sound(“. ./游戏/飞/声音/game_over.mp3")   # Xexplosion.set_volume (1)   ,   # pygame.mixer.music.load(“. ./游戏/飞/声音/game_music.mp3")   # pygame.mixer.music.play (1), 0.0)   # pygame.mixer.music.set_volume (0.25)   ,   我=0   #分数   分数=0   字体=pygame.font.SysFont(& # 39;微软雅黑& # 39;,,36)   #子弹   子弹=[]   #敌机   敌人=[]   #记录敌机爆炸位置   boomplace=[]   #游戏结束   游戏结束=False   pygame.mouse.set_pos (200,, 200)   while 真正的:   ,小姐:+=1   ,if 小姐:祝辞,200:   小姐:才能=0   ,screen.blit(背景,(0,0))   ,#通过鼠标控制飞机   ,x, y=pygame.mouse.get_pos ()   ,#打印(x, y)   -=,x  plane.get_width ()/2   -=,y  plane.get_height ()/2   ,screen.blit(飞机,,(x, y))   ,   ,#每25帧调用一次   ,if 我% 25,==,0:   #才能返回,按下左键,中键,右键   l, m, r=才能pygame.mouse.get_pressed ()   if 才能;l ==True:   ,,#生成子弹位置添加   ,,bullets.append ([x + plane.get_width ()/2, y))   ,,# Xshoot.play ()   ,,for  place 子弹:拷贝   ,,,#子弹位置超出边界   ,,,if  [1] & lt;=0:   ,,,,bullets.remove(地方)   #才能移动子弹位置   for 才能;place 子弹:拷贝   ,,地方[1],-=55   ,#绘制子弹   ,for  place 子弹拷贝:   screen.blit才能(子弹,([0],[1]))   ,#敌机生成,移动,消失   ,if 我% 199,==,0:   enemies.append才能([random.randint (0320 - enemy.get_width ()), -enemy.get_width ()/2))   for 才能;place 拷贝的敌人:   ,,if 地方[1],在=,600:   ,,,enemies.remove(地方)   for 才能;place 拷贝的敌人:   ,,,的地方[1],+=35   ,for  place 拷贝的敌人:   screen.blit才能(敌人([0],[1]))   ,#敌机爆炸   ,for  place  boomplace拷贝:   if 才能;地方[2]在0:   ,,screen.blit (boom1 ([0], [1]))   ,,地方[2],-=1   ,#子弹碰撞检测   ,for  bulletplace 子弹拷贝:   for 才能;enemyplace 拷贝的敌人:   ,,if  (bulletplace[0],祝辞,enemyplace[0],以及bulletplace [0], & lt;, enemyplace [0], +, enemy.get_width()),以及\   ,,,(bulletplace[1],祝辞,enemyplace[1],以及bulletplace [1], & lt;, enemyplace [1], +, enemy.get_height ()):   ,,,boomflag =75   ,,,enemyplace.append (boomflag)   ,,,boomplace.append (enemyplace)   ,,,enemies.remove (enemyplace)   ,,,bullets.remove (bulletplace)   ,,,# Sexplosion.play ()   ,,,score  +=1   ,#飞机碰撞检测   ,for  enemyplace 拷贝的敌人:   if 才能;(x  0.7 +, * plane.get_width(),祝辞,enemyplace[0]),以及(x  0.3 +, * plane.get_width () & lt; enemyplace [0] +, enemy.get_width ()) \   ,,以及(y  0.7 +, * plane.get_height(),祝辞,enemyplace[1]),以及(y  0.3 +, * plane.get_height () & lt; enemyplace [1] +, enemy.get_height ()):   ,,enemies.remove (enemyplace)   ,   ,,screen.blit(停顿,(0,0))   ,,screen.blit (boom2, (x, y))   ,,# for  place 子弹:拷贝   ,,,# screen.blit(子弹,(地方[0],[1]))   ,,# for  place 拷贝的敌人:   ,,,# screen.blit(敌人,,(地方[0],[1]))   ,   ,,文本=font.render(& # 39;分数% d # 39; %的分数,真的,(0,0,0))   ,,screen.blit(文本、(200270))   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

python实现微信打飞机游戏的方法