鱼C论坛

 找回密码
 立即注册
查看: 3212|回复: 1

[学习笔记] 关于pygame的飞机大战源码快捷引用

[复制链接]
发表于 2022-8-11 22:11:52 | 显示全部楼层 |阅读模式

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

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

x
勿喷勿喷
小甲鱼的“带你学pygame带你飞”
https://www.bilibili.com/video/BV1XN4y1L7HG?spm_id_from=333.999.0.0&vd_source=d598216e52ea153ab83bc8fcee3beebf
给新人的资料


                               
登录/注册后可看大图


原网站
https://github.com/techwithtim/PygameForBeginners
用里面的素材做了一个旧版的python教程的pygame的第一个小程序
  1. import pygame
  2. import sys

  3. pygame.init()
  4. bg = (255,255,55)
  5. size= oh,ho = 960,510
  6. oho=[1,1]
  7. bull=1
  8. #创建窗口
  9. s = pygame.display.set_mode(size)

  10. full=False

  11. ratio = 1
  12. space = pygame.image.load("space.png")
  13. onn = pygame.image.load("spaceship_red.png" )
  14. nn = onn
  15. onn_rect=onn.get_rect()
  16. d = nn_rect = onn.get_rect()
  17. c = space.get_rect()
  18. while True:
  19.     for oo in pygame.event.get():
  20.         if oo.type == pygame.QUIT:
  21.              sys.exit()
  22.         if oo.type == pygame.KEYDOWN:
  23.             if oo.key == pygame.K_LEFT:
  24.                 oho=[-10,0]
  25.                 d=d.move(oho)
  26.                 bull=bull+1
  27.             if oo.key == pygame.K_RIGHT:
  28.                 oho=[10,0]
  29.                 d=d.move(oho)
  30.                 bull=bull+1
  31.             if oo.key == pygame.K_UP:
  32.                 oho=[0,-10]
  33.                 d=d.move(oho)
  34.                 bull=bull+1
  35.             if oo.key == pygame.K_DOWN:
  36.                 oho=[0,10]
  37.                 d=d.move(oho)
  38.                 bull=bull+1
  39.             if oo.key ==pygame.K_F11:
  40.                 full = not full
  41.                 if full:
  42.                     size= oh,ho = 1920,1080
  43.                     s = pygame.display.set_mode(size,pygame.FULLSCREEN | pygame.HWSURFACE)
  44.                 else:
  45.                     size= oh,ho = 960,510
  46.                     s = pygame.display.set_mode(size)

  47.             if oo.key == pygame.K_EQUALS or oo.key == pygame.K_MINUS or oo.key == pygame.K_SPACE:
  48.                 if oo.key ==pygame.K_EQUALS and ratio <2:
  49.                     ratio =ratio+0.1
  50.                 if oo.key ==pygame.K_MINUS and ratio >0.5:
  51.                     ratio =ratio-0.1
  52.                 if oo.key ==pygame.K_SPACE:
  53.                      ratio=1.0

  54.                 nn=pygame.transform.smoothscale(onn, \
  55.                                                 (int(onn_rect.width * ratio), \
  56.                                                 int(onn_rect.height * ratio)))





  57.     if d.left < 0 or d.right > oh:
  58.         oho[0] = -oho[0]
  59.     if d.top < 0 or d.bottom > ho:
  60.         oho[1] = -oho[1]
  61.         
  62.     s.blit(nn,d)
  63.     pygame.display.flip()
  64.     s.fill(bg)
  65.     print(bull)



复制代码

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

使用道具 举报

 楼主| 发表于 2022-8-12 15:16:31 | 显示全部楼层

怎么没有人回复哪
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-25 17:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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