|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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的第一个小程序
- import pygame
- import sys
- pygame.init()
- bg = (255,255,55)
- size= oh,ho = 960,510
- oho=[1,1]
- bull=1
- #创建窗口
- s = pygame.display.set_mode(size)
- full=False
- ratio = 1
- space = pygame.image.load("space.png")
- onn = pygame.image.load("spaceship_red.png" )
- nn = onn
- onn_rect=onn.get_rect()
- d = nn_rect = onn.get_rect()
- c = space.get_rect()
- while True:
- for oo in pygame.event.get():
- if oo.type == pygame.QUIT:
- sys.exit()
- if oo.type == pygame.KEYDOWN:
- if oo.key == pygame.K_LEFT:
- oho=[-10,0]
- d=d.move(oho)
- bull=bull+1
- if oo.key == pygame.K_RIGHT:
- oho=[10,0]
- d=d.move(oho)
- bull=bull+1
- if oo.key == pygame.K_UP:
- oho=[0,-10]
- d=d.move(oho)
- bull=bull+1
- if oo.key == pygame.K_DOWN:
- oho=[0,10]
- d=d.move(oho)
- bull=bull+1
- if oo.key ==pygame.K_F11:
- full = not full
- if full:
- size= oh,ho = 1920,1080
- s = pygame.display.set_mode(size,pygame.FULLSCREEN | pygame.HWSURFACE)
- else:
- size= oh,ho = 960,510
- s = pygame.display.set_mode(size)
- if oo.key == pygame.K_EQUALS or oo.key == pygame.K_MINUS or oo.key == pygame.K_SPACE:
- if oo.key ==pygame.K_EQUALS and ratio <2:
- ratio =ratio+0.1
- if oo.key ==pygame.K_MINUS and ratio >0.5:
- ratio =ratio-0.1
- if oo.key ==pygame.K_SPACE:
- ratio=1.0
- nn=pygame.transform.smoothscale(onn, \
- (int(onn_rect.width * ratio), \
- int(onn_rect.height * ratio)))
- if d.left < 0 or d.right > oh:
- oho[0] = -oho[0]
- if d.top < 0 or d.bottom > ho:
- oho[1] = -oho[1]
-
- s.blit(nn,d)
- pygame.display.flip()
- s.fill(bg)
- print(bull)
复制代码
|
|