-1

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

1 回答 1

3

这就是问题:

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

特别是20(N)对于 Python,看起来您正在使用参数 N 调用对象 20。但 20 是一个不可调用的整数,因此它会引发异常。

你的意思是20*N

顺便说一句,更多的 pythonic 是写while (N < tilesNeeded):asfor N in range(tilesNeeded):然后你不需要显式地增加它。

于 2013-04-11T04:12:22.580 回答