I am basically trying to generate a grid of pixels on a tkinter canvas. I have the following information passed into the function, the starting cordinates which are 0, 0 (posX, posY), I also have the an array of tiles (2500 for this example), than I have the level size in the x direction which is how many tiles will go from left to right before a new line of them is created.
What I want to accomplish is to loop through the array of tiles I have, placing them down every 16 pixels, until it hits the end of the levels x direction, where it will reset the x position to one and add 16 to the y position. I managed to somewhat accomplish this, however this is the out I am receiving from it:
My code is the following:
for i in range(0, len(level.levelTiles)):
if (i == level.levelSizeX - 1):
scene.create_rectangle(posX, posY, posX+16, posY+16, fill="red")
posY+=16
elif (i % level.levelSizeX == 1 and i > level.levelSizeX):
scene.create_rectangle(posX, posY, posX+16, posY+16, fill="red")
posX = 0
posY += 16
else:
if (48 < i < 52):
print (i)
print (i > 3)
print (i%50)
print ("___________________")
scene.create_rectangle(posX, posY, posX+16, posY+16, fill="red")
posX += 16
I'm stumped on a way to go about this without adding a bunch of more if statements for various problems to get those two rectangles in the right position, since what I have written so far doesn't appear to work until after the tile i > max tiles in x direction + 1.
Aucun commentaire:
Enregistrer un commentaire