好的这是我在youtube上找到的代码,我没有完成,但我有一个错误,当我按左右箭头键向左和向右移动时,我的精灵不会响应有空间跳转可以有人请帮助我?
`import pygame
pygame.init()
#display
win = pygame.display.set_mode((500, 500))
pygame.display.set_caption("first game")
这是代码的一部分抱歉我是stackoverflow #vars的新手 walkRight = pygame.image.load(' sprites / R1.png'),pygame.image.load(' sprites /R2.png'),pygame.image.load( 39;子画面/ R3.png&#39),pygame.image.load('子画面/ R4.png&#39),pygame.image.load('子画面/ R5.png' ),pygame.image.load('子画面/ R6.png&#39),pygame.image.load('子画面/ R7.png&#39),pygame.image.load(&# 39;子画面/ R8.png&#39),pygame.image.load('子画面/ R9.png') walkLeft = pygame.image.load(' sprites / L1.png'),pygame.image.load(' sprites / L2.png'),pygame.image.load(&# 39;子画面/ L3.png&#39),pygame.image.load('子画面/ L4.png&#39),pygame.image.load('子画面/ L5.png' ),pygame.image.load('子画面/ L6.png&#39),pygame.image.load('子画面/ L7.png&#39),pygame.image.load(&# 39;子画面/ L8.png&#39),pygame.image.load('子画面/ L9.png') bg = pygame.image.load(' sprites / bg.jpg') char = pygame.image.load(' sprites / standing.png')
clock = pygame.time.Clock()
x = 50
y = 410
width = 64
height = 64
vel = 10
isJump = False
jumpcount = 10
left = False
right = False
walkcount = 0
#define draw
pygame.draw.rect
win.blit(bg, (0,0))
if walkcount + 1 >= 27:
walkcount = 0
if left:
win.blit(walkLeft[walkcount//3], (x,y))
walkcount += 1
elif right:
win.blit(walkRight[walkcount//3], (x,y))
walkcount += 1
else:
win.blit(char, (x,y))
pygame.display.update()
#main loop
running = True
while running:
clock.tick(27)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x > vel:
x -= vel
left = True
right = False
elif keys[pygame.K_RIGHT] and x < 800 - width - vel:
x += vel
right = True
left = False
else:
right = False
left = False
walkcount = 0
if not(isJump):
if keys[pygame.K_SPACE]:
isJump = True
right = False
left = False
walkcount = 0
else:
if jumpcount >= -10:
neg = 1
if jumpcount < 0:
neg = -1
y -= (jumpcount ** 2) * 0.5 * neg
jumpcount -= 1
else:
isJump = False
jumpcount = 10
#quit and draw command
pygame.quit()`