Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按住键时Python精灵不移动_Python_Pygame - Fatal编程技术网

按住键时Python精灵不移动

按住键时Python精灵不移动,python,pygame,Python,Pygame,我现在正在做一个游戏的基础,但是由于某些原因我不能让我的精灵移动。我知道当我按下按键时,它正在注册,但由于某种原因,精灵只是静止不动 import pygame import sys from pygame.locals import * import time pygame.init() black = (0, 0, 0) white = (255, 255, 255) screen = pygame.display.set_mode((800, 600)) pygame.displa

我现在正在做一个游戏的基础,但是由于某些原因我不能让我的精灵移动。我知道当我按下按键时,它正在注册,但由于某种原因,精灵只是静止不动

import pygame
import sys
from pygame.locals import *
import time

pygame.init()

black = (0, 0, 0)
white = (255, 255, 255)

screen = pygame.display.set_mode((800, 600)) 
pygame.display.set_caption("RADICAL")
screen.fill(black)

imga = pygame.image.load('coina.png')
imgb = pygame.image.load('coinb.png')
sound = pygame.mixer.Sound('coin.mp3')

FPS = 80
imgx = 10
imgy = 10
pixMove = 10

steps = 0 
x1 = 0 
y1 = 0

keystate = pygame.key.get_pressed()

GameOver = False

while not GameOver:
    screen.fill(white)

    points = (steps)
    font = pygame.font.SysFont(None, 30)
    text = font.render('Score: '+str(points), True, black)
    screen.blit(text, (0,0))

    if steps % 2 == 0: 
        screen.blit(imga, (imgx, imgy))
    else:
        screen.blit(imgb, (imgx, imgy))

    for event in pygame.event.get():
        print event 
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

        elif event.type == pygame.KEYDOWN:
            if keystate[pygame.K_UP]:
                y1 -= pixMove
            elif keystate[pygame.K_DOWN]:
                y1 += pixMove
            elif keystate[pygame.K_LEFT]:
                x1 -= pixMove
            elif keystate[pygame.K_RIGHT]:
                x1 += pixMove
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                x1 = 0 
            if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
                y1 = 0   

            steps +=1 

        if event.type == K_SPACE:
            sound.play()
            time.sleep(1)
            sound.stop()

pygame.display.update()
fpsTime.tick(FPS)
通常,您会将()图像显示在屏幕上(
pygame.display.set_mode()
),以便在我们称之为
pygame.display.update()
)的屏幕上反映所做的更改,在您的情况下,游戏永远不会出现语句,这是while循环之外的