I am making a snake game in python (using pygame) but when drawing the tail, the error comes up. The map is bigger than the screen so I created a coordinate conversion function (put in game coordinates and get out screen coordinates) but that breaks as soon as I move the snake/update the tail location list.
I have absolutely no idea what is going on so I have no idea what to try.
# Define convCoords. Converts game coordinates to screen coordinates for 20x20px squares.
def convCoords(mapX, mapY, mode):
screenX = ((camX - 15) - mapX) * -20
screenY = ((camY - 11) - mapY) * -20
if mode == 1: # If mode = 1, return both X and Y
return screenX, screenY
elif mode == 2: # If mode = 2, return only X
return screenX
elif mode == 3: # If mode = 3, return only Y
return screenY
else:
raise IndexError("Use numbers 1-3 for mode") # Raise an error if a number other than 1-3 is given as mode
def main():
stuff()
if snakeMoveTimer >= speed:
# Move the tail forward
convCoordsInserterX = lambda: convCoords(camX, 0, 2)
convCoordsInserterY = lambda: convCoords(0, camY, 3)
list.append(tailLocations, (convCoordsInserterX,
convCoordsInserterY, 20, 20))
if not appleEaten:
list.pop(tailLocations, 0)
else:
appleEaten = False
furtherStuff()
# Draw the tail
for object in tailLocations:
print(object)
pygame.draw.rect(gameDisplay, GREEN, object)
# Increase the timer
snakeMoveTimer += 1
The print prints out (240, 220, 20, 20) (260, 220, 20, 20) (280, 220, 20, 20) until it updates when it outputs:
(<function main.<locals>.<lambda> at 0x00000234D43C68B8>, <function main.<locals>.<lambda> at 0x00000234D43CB048>, 20, 20)
Traceback (most recent call last):
File "C:/Users/Me/Python/Snake/snake.py", line 285, in <module>
main()
File "C:/Users/Me/Python/Snake/snake.py", line 255, in main
pygame.draw.rect(gameDisplay, GREEN, object)
TypeError: Rect argument is invalid