TypeError:'int'对象不可调用(Pygame)

时间:2013-04-11 04:10:04

标签: python int pygame python-3.2 callable

我试图在屏幕底部加载一个可以放置小平台的地板。我也是这样做的,所以稍后我会更容易(我认为)只在相机中加载地板而不是无限加载。我确实试图找到一个解决方案,但我没有提到“N”作为一个功能,所以我不知道。任何帮助或一般建议表示赞赏。是的,我知道现在有一些无用的东西,但我还没有找到他们(FPS,BASICFONT)

def drawTiles():
    N = 0
    while (N < tilesNeeded):
        pygame.draw.rect(DISPLAYSURF, GREEN, (20(N), floorx, TILESIZE, TILESIZE))
        pygame.draw.rect(DISPLAYSURF, LIGHTGREEN, ((TILESIZE/4) + (20(N)), (floorx + (TILESIZE/4)), TILESIZE / 2, TILESIZE / 2))
        N = N + 1

以下是整个程序

import pygame, sys, random
from pygame.locals import *

TILESIZE = 20
WINDOWWIDTH = 640
WINDOWHEIGHT = 480
FPS = 30
floorx = (WINDOWHEIGHT - (TILESIZE))
floory = (WINDOWWIDTH / TILESIZE)
TileOffset = 20
tilesNeeded = (WINDOWWIDTH / TILESIZE)



BLACK =         (  0,   0,   0)
WHITE =         (255, 255, 255)
SKYBLUE =       (200, 210, 255)
DARKTURQUOISE = (  3,  54,  73)
GREEN =         (  0,  92,   7)
LIGHTGREEN =    (  0, 135,  15)


def main():
    global FPSCLOCK, DISPLAYSURF, BASICFONT, TILESIZE, floorx, floory, floorCovered, tilesNeeded

    pygame.init()
    FPSCLOCK = pygame.time.Clock()
    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
    pygame.display.set_caption('Alpha One')

    DISPLAYSURF.fill(SKYBLUE)

    drawTiles()



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

        pygame.display.update()

def drawTiles():
    N = 0
    while (N < tilesNeeded):
        pygame.draw.rect(DISPLAYSURF, GREEN, (20(N), floorx, TILESIZE, TILESIZE))
        pygame.draw.rect(DISPLAYSURF, LIGHTGREEN, ((TILESIZE/4) + (20(N)), (floorx + (TILESIZE/4)), TILESIZE / 2, TILESIZE / 2))
        N = N + 1





if __name__ == '__main__':
    main()

1 个答案:

答案 0 :(得分:3)

这是问题所在:

    pygame.draw.rect(DISPLAYSURF, GREEN, (20(N), floorx, TILESIZE, TILESIZE))

特别是Python的20(N)看起来像是用参数N调用对象20但是20是一个不可调用的整数,所以它抛出异常。

您的意思是20*N吗?

顺便说一下,pythonic就是将while (N < tilesNeeded):写为for N in range(tilesNeeded):,然后你就不需要显式增加它了。