Here I found a bug:
I created a player, then created another in the same place (replace it), something weird happened. When I ran the level, an error was raised.
Here is the traceback info:
Traceback (most recent call last):
File "main.py", line 1325, in <module>
File "main.py", line 185, in setup_level
File "main.py", line 378, in setup_leveldata
IndexError: list index out of range
So i looked through your code, and i found the problem. In the beginning of the level file, you save all the players right? And you save the spawnpoint in the matrix of map, but when user add a player at the position of another player, the original player is replaced, which means 'x' is replaced by another 'x'. But the player info was not changed. And you put the spawnpoint amount matching jugdement (Ln 379 - 380) after "entity_list.append(Player(spawnpoints[itemindex], [0, 0], playertypes[item[0]], item[1], item[2]))"
Here is the version that I improved (function "setup_leveldata"):
def setup_leveldata(txt, num_3d_slices): leveldata, entitydata, blocksize = convert_txt_to_leveldata(txt) resize_textures(blocksize, num_3d_slices) spawnpoints, entity_list, camera_boundaries = [], [], None converted_leveldata = deepcopy(leveldata) for rowindex, row in enumerate(leveldata): # convert strings to block class for itemindex, item in enumerate(row): converted_leveldata[rowindex][itemindex] = Block([itemindex * blocksize, rowindex * blocksize], item, blocksize) if item == "x": spawnpoints.append([itemindex * blocksize + blocksize / 2, rowindex * blocksize + blocksize / 2]) elif item == "X": spawnpoints.insert(0, [itemindex * blocksize + blocksize / 2, rowindex * blocksize + blocksize / 2]) converted_leveldata, endposavg, end_direction, end_hitboxes, lava_layer, bugfix_end_gradients = set_block_orientation(converted_leveldata, blocksize) if not len(entitydata) == len(spawnpoints): raise Exception("level spawnpoint amount does not match number of players") # if this is not changed, the whole program will stop. for itemindex, item in enumerate(entitydata): entity_list.append(Player(spawnpoints[itemindex], [0, 0], playertypes[item[0]], item[1], item[2])) if spawnpoints is not None and len(endposavg[0]) > 0: camera_boundaries = ((0, len(leveldata[0]) * blocksize - width), (0, len(leveldata) * blocksize - height)) return converted_leveldata, spawnpoints, blocksize, entity_list, camera_boundaries, end_hitboxes, lava_layer, bugfix_end_gradients, end_direction elif spawnpoints is None: raise Exception("level has no spawnpoint") else: raise Exception("level has no end")
P.S. Do you know how many errors PyCharm shows in main.py? 135! Red!