我的代码问题是TypeError: rect argument is invalid
。
我是非常新的,我不知道如何解决这个问题。
我正在使用pygame
和pyhton 2.7
。
import pygame
import random
pygame.init()
black = ( 0, 0, 0)
white = ( 255, 255, 255)
blue = ( 20, 90, 150)
green = ( 0, 255, 0)
dkgreen = ( 0, 100, 0)
red = ( 200, 60, 60)
purple = (0xBF,0x0F,0xB5)
brown = (0x55,0x33,0x00)
def background(screen):
screen.fill(black)
size=[510,510]
screen=pygame.display.set_mode(size)
pygame.display.set_caption("Cheese")
tab=[[[30*i,30*j] for i in range(17)] for j in range(17)]
clock=pygame.time.Clock()
player=[]
for k in range(5):
playerIm=pygame.image.load("player"+str(k)+".gif").convert()
playerIm.set_colorkey(white)
player.append(playerIm)
PlaYerimg=player[0]
xj=0
yj=0
done=False
while done == False:
for event in pygame.event.get():
if event.type==pygame.QUIT:
done=True
#TECLAS
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_LEFT:
PlaYerimg=player[4]
if xj>0:
xj=xj-1
elif event.key==pygame.K_RIGHT:
PlaYerimg=player[2]
if xj<16:
xj=xj+1
elif event.key==pygame.K_UP:
PlaYerimg=player[1]
if yj>0:
yj=yj-1
elif event.key==pygame.K_DOWN:
PlaYerimg=player[3]
if yj<16:
yj=yj+1
background(screen) #define a cor do ecra
pos=pygame.mouse.get_pos()
mousestat=pygame.mouse.get_pressed()
print pos
count=0
for i in range(17):
for j in range(17):
x=tab[i][j][0]
y=tab[i][j][1]
if count%2==0:
pygame.draw.rect(screen, white,[x,y,30,30])
else:
pygame.draw.rect(screen, black,[x,y,30,30])
count=count+1
screen.blit(PlaYerimg, tab[yj][xj])
pygame.display.flip()
clock.tick(20)
pygame.quit()
问题在于rect
的论证,但是我通过了正确的论证。
答案 0 :(得分:0)
第三个参数必须是元组。将[]
替换为()
pygame.draw.rect(screen, white,(x,y,30,30))
...
pygame.draw.rect(screen, black,(x,y,30,30))
...