下面的代码给了我这个错误,我很困惑。抱歉,如果我问错了问题,我是新来的,但我认为这符合准则。一旦我释放它给我这个错误和崩溃的键,图像就会在背景中移动。
Traceback (most recent call last):
File "C:\Users\Samga_000\Desktop\game\game.py", line 89, in <module>
rungame()
File "C:\Users\Samga_000\Desktop\game\game.py", line 79, in rungame
p.still()
TypeError: 'int' object is not callable
import pygame, sys
from pygame.locals import *
pygame.init()
WIDTH = 400
HEIGHT = 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
bif = "grass.png"
background = pygame.image.load(bif)
pygame.display.set_caption('RPG')
def drawEntitys():
frispri.update()
frispri.draw(screen)
def drawScreen():
screen.blit(background, (0,0))
class Player(pygame.sprite.Sprite):
image = pygame.image.load("misha.png")
image = image.convert_alpha()
def __init__(self):
pygame.sprite.Sprite.__init__(self, self.groups)
self.pos = (20, 20)
self.image = Player.image
self.rect = self.image.get_rect()
self.movepos = [0,0]
self.area = screen.get_rect()
self.still = True
def update(self):
newpos = self.rect.move(self.movepos)
if self.area.contains(newpos):
self.rect = newpos
pygame.event.pump()
def move(self, x, y):
self.still = 0
if self.still == 0:
self.movepos[0] = self.movepos[0] - x
self.movepos[1] = self.movepos[1] - y
else:
pass
def still(self):
self.still = 1
frispri = pygame.sprite.Group()
Player.groups = frispri
p = Player()
def rungame():
while True:
drawScreen()
drawEntitys()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
elif event.type == KEYDOWN:
if event.key == K_UP:
p.move(0,1)
elif event.key == K_DOWN:
p.move(0,-1)
elif event.key == K_LEFT:
p.move(1,0)
elif event.key == K_RIGHT:
p.move(-1,0)
elif event.type == KEYUP:
if event.key == K_UP:
p.still()
elif event.key == K_DOWN:
p.still()
elif event.key == K_LEFT:
p.still()
elif event.key == K_RIGHT:
p.still()
flipgame()
def flipgame():
pygame.display.flip()
rungame()