import pygame, sys
from pygame.locals import *
bifl = 'screeing.jpg'
milf = 'char_fowed_walk1.png'
pygame.init()
screen = pygame.display.set_mode((640, 360),0, 32)
background = pygame.image.load(bifl).convert()
mouse_c = pygame.image.load(milf).convert_alpha()
x, y = 0, 0
movex, movey = 0, 0
class move:
def moveUp():
movey =- 0.3
def moveDown():
movey =+ 0.3
def moveLeft():
movex =- 0.3
def moveRight():
movex =+ 0.3
def stopUp():
movey = 0
def stopDown():
movey = 0
def stopLeft():
movex = 0
def stopRight():
movex = 0
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_LEFT:
move.moveLeft()
elif event.key == K_RIGHT:
move.moveRight()
elif event.key == K_UP:
move.moveUp()
elif event.key == K_DOWN:
move.moveDown()
if event.type == KEYUP:
if event.key == K_LEFT:
move.stopLeft()
elif event.key == K_RIGHT:
move.stopRight()
elif event.key == K_UP:
move.stopUp()
elif event.key == K_DOWN:
move.stopDown()
x += movex
y += movey
screen.blit(background, (0, 0))
screen.blit(mouse_c, (x, y))
pygame.display.update()
当我运行它时,一切都只在玩家不动的情况下起作用,我在没有类和函数的情况下测试它并且它工作,所以它绝对与我添加的类有关。pygame 安装正确,我使用的是 python 2.7,我在其他脚本中使用了 pygame,它工作正常。