马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 XX牛牛 于 2023-1-29 21:55 编辑
ffrom pygame.locals import *
import pygame
pygame.init()
run = True
screen = pygame.display.set_mode((600, 1000))
py = 100
pspeed = 0.05
life = pygame.image.load("life.png")
empty1 = pygame.image.load("empty1.gif")
empty2 = pygame.image.load("empty2.gif")
empty3 = pygame.image.load("empty3.gif")
plane = pygame.image.load("飞机.png")
rplane = plane.get_rect()
while run:
for event in pygame.event.get():
if event.type == QUIT:
run = False
if event.type == K_SPACE:
py -= 500
pspeed = 0.05
py += pspeed
pspeed += 0.0001
screen.fill("green")
screen.blit(plane, (0, py))
rplane = plane.get_rect()
if rplane.bottom == 1000:
run = False
pygame.display.update()
请大佬多多支援!~
试一试.zip
(593.21 KB, 下载次数: 3)
本帖最后由 isdkz 于 2023-1-29 23:09 编辑
检测哪个按键被摁下用的是 event.key,even.type 是事件的类型,
所以用 if event.type == KEYDOWN 判断是否有按键摁下,再用 if event.key == K_SPACE 判断摁下的是否空格from pygame.locals import *
import pygame
pygame.init()
run = True
screen = pygame.display.set_mode((600, 1000))
py = 100
pspeed = 0.05
plane = pygame.image.load("飞机.png")
rplane = plane.get_rect()
while run:
for event in pygame.event.get():
if event.type == QUIT:
run = False
if event.type == KEYDOWN: # 改了这里
if event.key == K_SPACE: # 加了这里
py -= 50
pspeed = 0.05
py += pspeed
pspeed += 0.0001
screen.fill("green")
screen.blit(plane, (0, py))
rplane = plane.get_rect()
if rplane.bottom == 1000:
run = False
pygame.display.update()
|