大旗谷资源网 Design By www.zqyou.com
本文实例为大家分享了python实现微信打飞机游戏的具体代码,供大家参考,具体内容如下
import pygame
import random
import sys
#初始化
pygame.init()
pygame.display.set_caption('飞机火拼')#设置窗口标题
screen= pygame.display.set_mode((320, 570), 0, 32)
pygame.mouse.set_visible(False)#隐藏光标
#加载图片
boom1=pygame.image.load('../Game/fly/src/boom1.png')
boom2=pygame.image.load("../Game/fly/src/boom2.png")
bullet=pygame.image.load('../Game/fly/src/bullet.png')
plane=pygame.image.load("../Game/fly/src/plane.png").convert_alpha()
enemy=pygame.image.load('../Game/fly/src/enemy.png')
#设置窗口图标
pygame.display.set_icon(plane)
background=pygame.image.load("../Game/fly/src/bg_01.png")
start=pygame.image.load('../Game/fly/src/start.png')
pause=pygame.image.load("../Game/fly/src/pause.png")
#pygame.mixer.init()
#Xexplosion=pygame.mixer.Sound("explosion.mp3")
#Xbullet=pygame.mixer.Sound("../Game/fly/sound/bullet.mp3")
#XgameOver=pygame.mixer.Sound("../Game/fly/sound/game_over.mp3")
#Xexplosion.set_volume(1)
#pygame.mixer.music.load("../Game/fly/sound/game_music.mp3")
#pygame.mixer.music.play(-1, 0.0)
#pygame.mixer.music.set_volume(0.25)
i=0
#分数
score=0
font=pygame.font.SysFont('微软雅黑', 36)
#子弹
bullets=[]
#敌机
enemies=[]
#记录敌机爆炸位置
boomplace=[]
#游戏结束
gameover=False
pygame.mouse.set_pos(200, 200)
while True:
i += 1
if i > 200:
i =0
screen.blit(background, (0, 0))
#通过鼠标控制飞机
x, y=pygame.mouse.get_pos()
#print(x, y)
x -= plane.get_width()/2
y -= plane.get_height()/2
screen.blit(plane, (x, y))
#每25帧 调用一次
if i%25 == 0:
#返回 按下左键 中键 右键
l,m,r=pygame.mouse.get_pressed()
if l ==True:
#生成子弹位置添加
bullets.append([x+plane.get_width()/2, y])
#Xshoot.play()
for place in bullets:
#子弹位置超出边界
if place[1]<=0:
bullets.remove(place)
#移动子弹位置
for place in bullets:
place[1] -= 55
#绘制子弹
for place in bullets:
screen.blit(bullet,(place[0],place[1]))
#敌机生成 移动 消失
if i%199 == 0:
enemies.append([random.randint(0,320-enemy.get_width()),-enemy.get_width()/2])
for place in enemies:
if place[1] >= 600:
enemies.remove(place)
for place in enemies:
place[1] += 35
for place in enemies:
screen.blit(enemy,(place[0],place[1]))
#敌机爆炸
for place in boomplace:
if place[2]>0:
screen.blit(boom1,(place[0],place[1]))
place[2] -=1
#子弹碰撞检测
for bulletplace in bullets:
for enemyplace in enemies:
if (bulletplace[0] > enemyplace[0] and bulletplace[0] < enemyplace[0] + enemy.get_width()) and (bulletplace[1] > enemyplace[1] and bulletplace[1] < 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 in enemies:
if (x + 0.7*plane.get_width() > enemyplace[0]) and (x + 0.3*plane.get_width()<enemyplace[0]+ enemy.get_width()) and (y + 0.7*plane.get_height() > enemyplace[1]) and (y + 0.3*plane.get_height()<enemyplace[1]+ enemy.get_height()):
enemies.remove(enemyplace)
screen.blit(pause,(0,0))
screen.blit(boom2, (x, y))
#for place in bullets:
#screen.blit(bullet, (place[0], place[1]))
#for place in enemies:
#screen.blit(enemy, (place[0], place[1]))
text=font.render('Score%d'%score,True,(0,0,0))
screen.blit(text,(200,270))
text=font.render("Right ReStart",True,(0, 0,0))
screen.blit(text,(30,310))
pygame.display.update()#重新绘制窗口
gameover=True
while gameover == True and r == False :
l, m, r = pygame.mouse.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
#重置游戏
i=0
score=0
bullets=[]
enemies=[]
boomplace=[]
x, y=185-plane.get_width()/2,550 - plane.get_height()/2
#检测 暂停 继续
l,m,r=pygame.mouse.get_pressed()
if r == True:
screen.blit(background,(0,0))
screen.blit(start,(0,0))
screen.blit(plane,(x,y))
for place in bullets:
screen.blit(bullet,(place[0],place[1]))
for place in enemies:
screen.blit(enemy,(place[0],place[1]))
for place in boomplace:
if place[2] >0:
screen.blit(boom1,(place[0],place[1]))
place[2] -=1
text=font.render(u'Score %d'%score,1,(0,0,0))
screen.blit(text,(50,0))
if gameover == True:
x,y =185,550
gameover =False
text =font.render(' left to start',True,(0,0,0))
screen.blit(text,(35,300))
else:
x,y=pygame.mouse.get_pos()
text=font.render(' left to continue ',True,(0,0,0))
screen.blit(text,(10,300))
pygame.display.update()
while True :
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
l, m, r = pygame.mouse.get_pressed()
if l == True:
pygame.mouse.set_pos(x,y)
break
text=font.render(u"%d"%score, True, (0, 0, 0))
screen.blit(text,(50, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
效果图:
更多关于python游戏的精彩文章请点击查看以下专题:
python俄罗斯方块游戏集合
python经典小游戏汇总
python微信跳一跳游戏集合
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
大旗谷资源网 Design By www.zqyou.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
大旗谷资源网 Design By www.zqyou.com
暂无python实现微信打飞机游戏的评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
2025年11月23日
2025年11月23日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
