I'm making a game with pygame
, and I ran into a problem. The function below is supposed to make a list of lists, containing 1s and 0s according to wall/floor. However, when I try to edit a single tile, an entire column is changed.
def createDefault(width,height,tileW,tileH):
level = []
mid = []
level.append([1]*(width/tileW))
mid.append(1)
for i in range((width - (tileW * 2)) / tileW):
mid.append(0)
mid.append(1)
for i in range((height - (tileH * 2)) / tileH):
level.append((mid))
level.append([1]*(width/tileW))
return level
level = createDefault(640,640,64,64)
level[2][4] = 1
print level
prints (prettified):
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
As you can see, in every list in the array, value 4 has been changed to 1. How can I make only the value in list 2, character 4 be edited?