Question

I am attempting to make a floor that loads at the bottom of the screen for little platformer. I am doing it the this way also so later on it will be easier(I think) to have the floor load only in the camera versus loading infinitely. I did try to find a solution but I am not mentioning "N" as a function so I have no idea. Any help or general suggestions are appreciated. And yes I know that there are some useless things in there right now but I just have yet to get around to them yet( 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

Here is the whole program to look at

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()
Was it helpful?

Solution

This is the problem:

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

In particular 20(N) to Python looks like you're calling the object 20 with an argument of N. but 20 is an integer which is not callable, so it throws the exception.

Do you mean 20*N?

Btw, more pythonic is to write while (N < tilesNeeded): as for N in range(tilesNeeded): and then you don't need to explicitly increment it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top