鱼C论坛

 找回密码
 立即注册
查看: 1639|回复: 13

[已解决]怎么把python文件做成exe文件啊

[复制链接]
发表于 2020-8-4 11:14:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
怎么把python文件做成exe文件啊,求解
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-8-4 11:14:37 | 显示全部楼层



用 pyinstaller 可以将 py 文件打包成 exe


安装 pyinstaller 模块:
  1. python -m pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
复制代码


打包流程:

将 需要打包的文件放一起   比如 我在 C盘创个  py  文件夹  脚本为 x.py 图标为 z.ico(图标如果没有可以不用,就去掉下面代码中的 -i 和 z.ico )

1. 打开 cmd 窗口 输入将工作目录切换到py文件夹下
  1. cd C:\py
复制代码


2.输入
  1. pyinstaller -F -i z.ico x.py
复制代码
回车进行打包操作

3.打包完成后在 dist 文件夹下可找到 exe 程序

Ps: 若是 gui 界面程序 建议 -F前面加上 -w 可隐藏 cmd 窗口运行



小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-4 11:17:42 | 显示全部楼层
Twilight6 发表于 2020-8-4 11:14
用 pyinstaller 可以将 py 文件打包成 exe

多个文件怎么打包成一个文件啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 11:19:02 | 显示全部楼层
fytfytf 发表于 2020-8-4 11:17
多个文件怎么打包成一个文件啊

打包主程序即可
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-4 11:28:28 | 显示全部楼层

图片等素材也会打包进去吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 11:29:05 | 显示全部楼层
fytfytf 发表于 2020-8-4 11:28
图片等素材也会打包进去吗



图片不会的,你需要和 exe 打包,而且目录建议设置再 exe 同目录下,否则其他电脑会报错的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-4 11:33:29 | 显示全部楼层
本帖最后由 fytfytf 于 2020-8-4 11:55 编辑
Twilight6 发表于 2020-8-4 11:29
图片不会的,你需要和 exe 打包,而且目录建议设置再 exe 同目录下,否则其他电脑会报错的


被引用的的文件都会打包进来吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 12:02:13 | 显示全部楼层
fytfytf 发表于 2020-8-4 11:33
被引用的的文件都会打包进来吗

不会,需要另外复制到程序文件夹下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-4 12:30:28 | 显示全部楼层
zltzlt 发表于 2020-8-4 12:02
不会,需要另外复制到程序文件夹下

把.py文件放到exe目录吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 12:34:20 | 显示全部楼层
fytfytf 发表于 2020-8-4 12:30
把.py文件放到exe目录吗

不是,那些程序需要用到的资源需要放在 .exe 同文件夹下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-4 13:31:42 | 显示全部楼层
zltzlt 发表于 2020-8-4 12:34
不是,那些程序需要用到的资源需要放在 .exe 同文件夹下

我把.py文件和图片都放在exe的同文件夹下,但是exe文件点了没反应,求解
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 13:32:36 | 显示全部楼层
fytfytf 发表于 2020-8-4 13:31
我把.py文件和图片都放在exe的同文件夹下,但是exe文件点了没反应,求解

把代码发上来看看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-8-4 13:33:52 | 显示全部楼层
zltzlt 发表于 2020-8-4 13:32
把代码发上来看看
  1. import pygame
  2. import sys
  3. from pygame.locals import *
  4. import traceback
  5. import myplane
  6. import enemy as e
  7. import bullet
  8. import supply

  9. pygame.init()
  10. pygame.mixer.init()

  11. clock=pygame.time.Clock()

  12. bg_size=width,height=480,700
  13. screen=pygame.display.set_mode(bg_size)
  14. pygame.display.set_caption('The battle of the plane')
  15. bg_image=pygame.image.load('./images/background.png').convert_alpha()

  16. #载入结束画面图片
  17. again_image=pygame.image.load('./images/again.png').convert_alpha()
  18. again_rect=again_image.get_rect()
  19. again_rect.left,again_rect.top=(bg_size[0]-again_rect.width)//2,300
  20. gameover_image=pygame.image.load('./images/gameover.png').convert_alpha()
  21. gameover_rect=gameover_image.get_rect()
  22. gameover_rect.left,gameover_rect.top=(bg_size[0]-gameover_rect.width)//2,350

  23. #载入炸弹
  24. bomb_image=pygame.image.load('./images/bomb.png').convert_alpha()
  25. bomb_rect=bomb_image.get_rect()
  26. bomb_rect.left,bomb_rect.top=0,bg_size[1]-bomb_rect.height
  27. bomb_font=pygame.font.Font('./font/font.ttf',36)


  28. #载入暂停按钮
  29. pause_nor=pygame.image.load('./images/pause_nor.png').convert_alpha()
  30. pause_pressed=pygame.image.load('./images/pause_pressed.png').convert_alpha()
  31. resume_nor=pygame.image.load('./images/resume_nor.png').convert_alpha()
  32. resume_pressed=pygame.image.load('./images/resume_pressed.png').convert_alpha()
  33. pause_rect=pause_nor.get_rect()
  34. pause_rect.left,pause_rect.top=bg_size[0]-60,0
  35. pause_image=pause_nor

  36. #载入音乐
  37. pygame.mixer.music.load('./sound/game_music.ogg')
  38. bullet_sound=pygame.mixer.Sound('./sound/bullet.wav')
  39. bullet_sound.set_volume(0.2)
  40. button_sound=pygame.mixer.Sound('./sound/button.wav')
  41. button_sound.set_volume(0.2)
  42. enemy1_down=pygame.mixer.Sound('./sound/enemy1_down.wav')
  43. enemy1_down.set_volume(0.5)
  44. enemy2_down=pygame.mixer.Sound('./sound/enemy2_down.wav')
  45. enemy2_down.set_volume(0.5)
  46. enemy3_down=pygame.mixer.Sound('./sound/enemy3_down.wav')
  47. enemy3_down.set_volume(0.5)
  48. enemy3_flying=pygame.mixer.Sound('./sound/enemy3_flying.wav')
  49. enemy3_flying.set_volume(0.3)
  50. get_bomb=pygame.mixer.Sound('./sound/get_bomb.wav')
  51. get_bomb.set_volume(0.2)
  52. get_bullet=pygame.mixer.Sound('./sound/get_bullet.wav')
  53. get_bullet.set_volume(0.2)
  54. me_down=pygame.mixer.Sound('./sound/me_down.wav')
  55. me_down.set_volume(0.2)
  56. supply_sound=pygame.mixer.Sound('./sound/supply.wav')
  57. supply_sound.set_volume(0.2)
  58. upgrade=pygame.mixer.Sound('./sound/upgrade.wav')
  59. upgrade.set_volume(0.2)
  60. use_bomb=pygame.mixer.Sound('./sound/use_bomb.wav')
  61. use_bomb.set_volume(0.2)


  62. pygame.mixer.music.set_volume(0.2)
  63. pygame.key.set_repeat(100,100)

  64. def add_small(num,group1,group2):
  65.     for i in range(num):
  66.         small_plane=e.Xiao(bg_size)
  67.         group1.add(small_plane)
  68.         group2.add(small_plane)

  69. def add_middle(num,group1,group2):
  70.     for i in range(num):
  71.         middle_plane=e.Zhong(bg_size)
  72.         group1.add(middle_plane)
  73.         group2.add(middle_plane)

  74. def add_big(num,group1,group2):
  75.     for i in range(num):
  76.         big_plane=e.Da(bg_size)
  77.         group1.add(big_plane)
  78.         group2.add(big_plane)

  79. def speed_inc(group,num):
  80.     for i in group:
  81.         i.speed+=num

  82. def main():
  83.     pygame.mixer.music.play(-1)#循环播放bgm
  84.     level=1#表示难度等级
  85.     bomb_num=3#表示炸弹数量
  86.     pause=False#表示是否暂停
  87.     running=True
  88.     switch=True#用于切换图片
  89.     recorded=False#用于存档
  90.     delay=60#用于延迟
  91.     #创建自己的飞机
  92.     me=myplane.Myplane(bg_size)
  93.     #创建敌人的飞机
  94.     enemies=pygame.sprite.Group()

  95.     smalls=pygame.sprite.Group()
  96.     middles=pygame.sprite.Group()
  97.     bigs=pygame.sprite.Group()
  98.    
  99.     add_small(20,enemies,smalls)
  100.     add_middle(10,enemies,middles)
  101.     add_big(2,enemies,bigs)
  102.     #创建子弹
  103.     bullet1=[]
  104.     bullet1_index=0
  105.     for i in range(4):
  106.         bullet1.append(bullet.Bullet1(bg_size,me.rect.midtop))

  107.     #创建超级子弹
  108.     bullet2=[]
  109.     bullet2_index=0
  110.     for i in range(8//2):
  111.         bullet2.append(bullet.Bullet2(bg_size,(me.rect.centerx-33,me.rect.centery)))
  112.         bullet2.append(bullet.Bullet2(bg_size,(me.rect.centerx+30,me.rect.centery)))
  113.     #我方生命数
  114.     life=pygame.image.load('./images/life.png').convert_alpha()
  115.     life_num=3
  116.     life_font=pygame.font.Font('./font/font.ttf',36)
  117.     life_rect=life.get_rect()
  118.     life_rect.left,life_rect.top=bg_size[0]-life_rect.width,bg_size[1]-life_rect.height
  119.     life_text=life_font.render('× %s'%life_num,True,(255,255,0))
  120.     #创建中弹图片索引
  121.     small_index=0
  122.     middle_index=0
  123.     big_index=0
  124.     me_index=0

  125.     #创建分数
  126.     score=0
  127.     score_font=pygame.font.Font('./font/font.ttf',36)
  128.     #创建补给
  129.     bomb_supply=supply.Bomb(bg_size)
  130.     bullet_supply=supply.Bullet(bg_size)
  131.     supply_list=pygame.sprite.Group()
  132.     supply_list.add(bomb_supply)
  133.     supply_list.add(bullet_supply)
  134.     SUPPLY_TIME=USEREVENT
  135.     #创建无敌计数器
  136.     INVINCIBLE_TIME=USEREVENT+2
  137.     #超级子弹定时器
  138.     SUPER_BULLET=USEREVENT+1
  139.     is_super_bullet=False#是否使用超级子弹
  140.     pygame.time.set_timer(SUPPLY_TIME,30*1000)
  141.     while running:
  142.         for event in pygame.event.get():
  143.             if event.type==pygame.QUIT:
  144.                 pygame.quit()
  145.                 sys.exit()
  146.             elif event.type==pygame.KEYDOWN:
  147.                 if event.key==K_SPACE:#使用炸弹
  148.                     if bomb_num:
  149.                         for i in enemies:
  150.                             if i.rect.top>0:
  151.                                 i.active=False
  152.                         use_bomb.play()
  153.                         bomb_num-=1
  154.             elif event.type==pygame.MOUSEBUTTONDOWN:
  155.                 if event.button==1 :
  156.                     if pause_rect.collidepoint(event.pos):#暂停游戏
  157.                         pause=not pause
  158.                         if pause:
  159.                             pygame.time.set_timer(SUPPLY_TIME,0)
  160.                             pygame.mixer.music.pause()
  161.                             pygame.mixer.pause()
  162.                         else:
  163.                             pygame.time.set_timer(SUPPLY_TIME,30*1000)
  164.                             pygame.mixer.unpause()
  165.                             pygame.mixer.music.unpause()
  166.             elif event.type==SUPPLY_TIME:
  167.                 bomb_supply.active=True#补给开始
  168.                 bullet_supply.active=True
  169.                 supply_sound.play()
  170.             elif event.type==SUPER_BULLET:
  171.                 is_super_bullet=False
  172.                 pygame.time.set_timer(SUPER_BULLET,0)
  173.             elif event.type==INVINCIBLE_TIME:
  174.                 me.invincible=False
  175.                 pygame.time.set_timer(INVINCIBLE_TIME,0)
  176.         key_pressed=pygame.key.get_pressed()#获取键盘输入情况   
  177.         
  178.         
  179.         mouse_pos=pygame.mouse.get_pos()#获取鼠标位置情况
  180.         if not pause:
  181.             if pause_rect.collidepoint(mouse_pos):
  182.                 pause_image=pause_pressed
  183.             else:
  184.                 pause_image=pause_nor
  185.         else:
  186.             if pause_rect.collidepoint(mouse_pos):
  187.                 pause_image=resume_pressed
  188.             else:
  189.                 pause_image=resume_nor
  190.         screen.blit(bg_image,(0,0))#绘制背景
  191.             
  192.         if not pause:
  193.             
  194.             bomb_text=bomb_font.render('× %s'%str(bomb_num),True,(255,0,0))
  195.             #绘制炸弹图标
  196.             screen.blit(bomb_image,bomb_rect)
  197.             screen.blit(bomb_text,(bomb_rect[0]+bomb_rect.width+5,bomb_rect.top+8))
  198.             #我方飞机移动
  199.             if key_pressed[K_a]:
  200.                 if key_pressed[K_w]:
  201.                     me.move_top()
  202.                 if key_pressed[K_s]:
  203.                     me.move_bottom()
  204.                 me.move_left()
  205.             if key_pressed[K_d]:
  206.                 if key_pressed[K_w]:
  207.                     me.move_top()
  208.                 if key_pressed[K_s]:
  209.                     me.move_bottom()
  210.                 me.move_right()
  211.             if key_pressed[K_w]:
  212.                 if key_pressed[K_a]:
  213.                     me.move_left()
  214.                 if key_pressed[K_d]:
  215.                     me.move_right()
  216.                 me.move_top()
  217.             if key_pressed[K_s]:
  218.                 if key_pressed[K_a]:
  219.                     me.move_left()
  220.                 if key_pressed[K_d]:
  221.                     me.move_right()
  222.                 me.move_bottom()
  223.             
  224.             #检测是否吃到炸弹补给并绘制
  225.             if bomb_supply.active:
  226.                 bomb_supply.move()
  227.                 screen.blit(bomb_supply.image,bomb_supply.rect)
  228.                 if pygame.sprite.collide_mask(me,bomb_supply):
  229.                     bomb_supply.active=False
  230.                     get_bomb.play()
  231.                     bomb_supply.reset()
  232.                     if bomb_num<3:
  233.                         bomb_num+=1
  234.             #检测是否吃到超级子弹补给并绘制
  235.             if bullet_supply.active:
  236.                 bullet_supply.move()
  237.                 screen.blit(bullet_supply.image,bullet_supply.rect)
  238.                 if pygame.sprite.collide_mask(me,bullet_supply):
  239.                     is_super_bullet=True
  240.                     bullet_supply.active=False
  241.                     pygame.time.set_timer(SUPER_BULLET,18*1000)
  242.                     get_bullet.play()
  243.                     bullet_supply.reset()
  244.             
  245.             if delay%10==0:#发射子弹
  246.                 bullet_sound.play()
  247.                 if is_super_bullet:
  248.                     bullets=bullet2
  249.                     bullet2[bullet2_index].reset((me.rect.centerx-33,me.rect.centery))
  250.                     bullet2_index=(bullet2_index+1)%8
  251.                     bullet2[bullet2_index].reset((me.rect.centerx+30,me.rect.centery))
  252.                     bullet2_index=(bullet2_index+1)%8
  253.                 else:
  254.                     bullets=bullet1
  255.                     bullet1[bullet1_index].reset(me.rect.midtop)
  256.                     bullet1_index=(bullet1_index+1)%4
  257.             #检测子弹是否击中敌机
  258.             for b in bullets:
  259.                 b.move()
  260.                 if b.active:
  261.                     screen.blit(b.image,b.rect)
  262.                     bullet_down=pygame.sprite.spritecollide(b,enemies,False,pygame.sprite.collide_mask)
  263.                     if bullet_down:
  264.                         b.active=False
  265.                         for i in bullet_down:
  266.                             if i in smalls:
  267.                                 i.active=False
  268.                             elif i in middles:
  269.                                 i.hit=True
  270.                                 if i.hp==0:
  271.                                     i.active=False
  272.                                 else:
  273.                                     i.hp-=1
  274.                             elif i in bigs:
  275.                                 i.hit=True
  276.                                 if i.hp==0:
  277.                                     i.active=False
  278.                                 else:
  279.                                     i.hp-=1
  280.             #等级提升难度
  281.             if level==1 and score>500:
  282.                 upgrade.play()
  283.                 level=2
  284.                 add_small(2,enemies,smalls)
  285.                 add_middle(1,enemies,middles)
  286.             elif level==2 and score>1500:
  287.                 upgrade.play()
  288.                 level=3
  289.                 add_small(3,enemies,smalls)
  290.                 add_middle(1,enemies,middles)
  291.                 add_big(1,enemies,bigs)
  292.                 speed_inc(smalls,1)

  293.             elif level==3 and score>3000:
  294.                 upgrade.play()
  295.                 level=4
  296.                 add_small(3,enemies,smalls)
  297.                 add_middle(1,enemies,middles)
  298.                 add_big(1,enemies,bigs)
  299.                 speed_inc(smalls,1)
  300.                 speed_inc(middles,1)
  301.                 speed_inc(bigs,1)
  302.             elif level==4 and score>5000:
  303.                 upgrade.play()
  304.                 level=5
  305.                 add_small(3,enemies,smalls)
  306.                 add_middle(2,enemies,middles)
  307.                 add_big(1,enemies,bigs)
  308.                 speed_inc(smalls,1)
  309.                 speed_inc(middles,1)
  310.                 speed_inc(bigs,1)
  311.                
  312.             #检测碰撞
  313.             enemies_down=pygame.sprite.spritecollide(me,enemies,False,pygame.sprite.collide_mask)
  314.             if enemies_down:
  315.                 if not me.invincible:
  316.                     me.active=False
  317.                 for i in enemies_down:
  318.                     i.active=False
  319.                     
  320.                
  321.                 screen.blit(pause_nor,(bg_size[0]-60,0))
  322.             #绘制我方飞机
  323.             if me.active:
  324.                 if switch:
  325.                     screen.blit(me.image1,me.rect)
  326.                 else:
  327.                     screen.blit(me.image2,me.rect)
  328.             else:
  329.                 if (delay%10)==0:
  330.                     if me_index==0:
  331.                         me_down.play()
  332.                     screen.blit(me.down_images[me_index],me.rect)
  333.                     me_index=(me_index+1)%4
  334.                     if me_index==0:
  335.                         life_num-=1
  336.                         
  337.                         pygame.time.set_timer(INVINCIBLE_TIME,3*1000)
  338.                         life_text=life_font.render('× %s'%life_num,True,(255,255,0))
  339.                         me.reset()
  340.             
  341.             #绘制剩余生命数量
  342.             screen.blit(life,life_rect)
  343.             screen.blit(life_text,(life_rect[0]-50,life_rect[1]))
  344.             delay-=1
  345.             if not delay:
  346.                 delay=60
  347.             if not (delay%5):
  348.                 switch=not switch#切换图片

  349.             if bomb_supply.active:#炸弹移动
  350.                 bomb_supply.move()
  351.                 screen.blit(bomb_supply.image,bomb_supply.rect)
  352.                
  353.             #绘制敌方飞机
  354.             for i in bigs:#绘制大飞机
  355.                 if i.active:
  356.                     i.move()
  357.                     if i.hit:
  358.                         screen.blit(i.hit_image,i.rect)
  359.                         i.hit=False
  360.                     else:
  361.                         if switch:
  362.                             screen.blit(i.image,i.rect)
  363.                         else:
  364.                             screen.blit(i.image_n2,i.rect)
  365.                     if e.Da.hp>i.hp:
  366.                         pygame.draw.rect(screen,(0,0,0),(i.rect.left,i.rect.top,i.rect.width,7))#绘制血条
  367.                         if i.hp<e.Da.hp*0.3:
  368.                             pygame.draw.rect(screen,(255,0,0),(i.rect.left,i.rect.top,i.rect.width//e.Da.hp*i.hp,7))#绘制血条
  369.                         else:
  370.                             pygame.draw.rect(screen,(0,255,0),(i.rect.left,i.rect.top,i.rect.width//e.Da.hp*i.hp,7))#绘制血条

  371.                     if i.rect.bottom==-50:#大飞机进场音乐
  372.                         enemy3_flying.play(-1)
  373.                 else:
  374.                     if not (delay%6):
  375.                         if big_index==0:
  376.                             enemy3_down.play()
  377.                             enemy3_flying.stop()
  378.                         screen.blit(i.down_images[big_index],i.rect)
  379.                         big_index=(big_index+1)%6
  380.                         if big_index==0:
  381.                             score+=200
  382.                             i.reset()

  383.             for i in middles:#绘制中飞机
  384.                 if i.active:
  385.                     i.move()
  386.                     if i.hit:
  387.                         screen.blit(i.hit_image,i.rect)
  388.                         i.hit=False
  389.                     else:
  390.                         screen.blit(i.image,i.rect)
  391.                     
  392.                     if e.Zhong.hp>i.hp:
  393.                         pygame.draw.rect(screen,(0,0,0),(i.rect.left,i.rect.top,i.rect.width,7))#绘制血条
  394.                         if i.hp<e.Zhong.hp*0.3:
  395.                             pygame.draw.rect(screen,(255,0,0),(i.rect.left,i.rect.top,i.rect.width//e.Zhong.hp*i.hp,7))#绘制血条
  396.                         else:
  397.                             pygame.draw.rect(screen,(0,255,0),(i.rect.left,i.rect.top,i.rect.width//e.Zhong.hp*i.hp,7))#绘制血条
  398.                 else:
  399.                   
  400.                     if (delay%6)==0:
  401.                         if middle_index==0:
  402.                             enemy2_down.play()
  403.                         screen.blit(i.down_images[middle_index],i.rect)
  404.                         middle_index=(middle_index+1)%4
  405.                         if middle_index==0:
  406.                             score+=50
  407.                             i.reset()

  408.             for i in smalls:#绘制小飞机
  409.                 if i.active:
  410.                     i.move()
  411.                     screen.blit(i.image,i.rect)
  412.                 else:
  413.                     
  414.                     if (delay%6)==0:
  415.                         if small_index==0:
  416.                             enemy1_down.play()
  417.                         screen.blit(i.down_images[small_index],i.rect)
  418.                         small_index=(small_index+1)%4
  419.                         if small_index==0:
  420.                             score+=10
  421.                             i.reset()

  422.             score_text=score_font.render('Score : %s'% str(score),True,(255,255,255))
  423.             
  424.         screen.blit(score_text,(0,0))#绘制得分
  425.         #绘制暂停按钮
  426.         screen.blit(pause_image,pause_rect)
  427.         if life_num==0:#游戏结束
  428.                 #背景音乐停止
  429.                 pygame.mixer.music.stop()
  430.                 #其他音效停止
  431.                 pygame.mixer.stop()
  432.                 #停止发放补给
  433.                 pygame.time.set_timer(SUPPLY_TIME,0)
  434.                 if not recorded:
  435.                     recorded=True
  436.                     #读取最高分
  437.                     with open('./record.txt','r') as f:
  438.                         record_score=int(f.readline())
  439.                     #如果高于最高分则存档
  440.                     if score>record_score:
  441.                         record_score=score
  442.                         with open('./record.txt','w') as f:
  443.                             f.write(str(score))
  444.                 #绘制结束界面
  445.                 pause=True
  446.                 screen.blit(bg_image,(0,0))
  447.                 screen.blit(score_text,(0,0))
  448.                 max_score=score_font.render('Max Score = %s'% str(record_score),True,(255,255,255))#绘制最高分数
  449.                 screen.blit(max_score,(120,200))
  450.                 screen.blit(again_image,again_rect)#绘制重新开始
  451.                 screen.blit(gameover_image,gameover_rect)#绘制结束游戏
  452.                 mouse_pressed=pygame.mouse.get_pressed()
  453.                 if again_rect.collidepoint(mouse_pos):
  454.                     if mouse_pressed[0]:
  455.                         main()
  456.                 elif gameover_rect.collidepoint(mouse_pos):
  457.                     if mouse_pressed[0]:
  458.                         pygame.quit()
  459.                         sys.exit()
  460.                
  461.         pygame.display.flip()
  462.         clock.tick(60)

  463.    
  464.         
  465. if __name__=='__main__':
  466.     try:
  467.         main()
  468.     except SystemExit:
  469.         pass
  470.     except:
  471.         traceback.print_exc()
  472.         pygame.quit()
  473.         input()






复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-8-4 16:06:21 | 显示全部楼层    本楼为最佳答案   
去这个网页参考一下啊~

https://www.bilibili.com/video/BV1y7411H7dB/?spm_id_from=333.788.videocard.1
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-24 20:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表