类型错误:'int'对象不可调用(Pygame)



我正在尝试为小型平台游戏制作一个在屏幕底部加载的地板。我也是这样做的,所以以后(我认为)只在相机中加载地板比无限加载更容易。我确实试图找到一个解决方案,但我没有提到"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()

这就是问题所在:

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

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

你指的是20*N吗?

顺便说一句,更python的是将while (N < tilesNeeded):写成for N in range(tilesNeeded):,然后你不需要显式地增加它

相关内容

  • 没有找到相关文章

最新更新