[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Odd behaviour of sprites in a list - newbie help please?




hello,

as pointed out, it seems you have an issue with the python objects.

I agree also with general comment to improve code structure ; and maybe
have a quick look at Python coding convention PEP8 too ;-)

so it seems you have still a lot to discover from python's
magic :) for example this code snippet:

On 24/06/2019 17:19, Adam Coombes wrote:
     for tail in range (len(Snake)-1,0,-1):
         print(Snake,tail)
         Snake[tail] = Snake[tail-1]
         Window.blit(playerImage,Snake[tail])
         print(Snake,tail)

I'm not sure what you want, but I guess you could find
advantage in some of the following patterns:

a)

for rect in Snake:
  # maybe you find out that don't need the index, just the object
  use(rect)

b) or
for number, rect in enumerate(Snake):
   do_somthing_with(number, rect)

c) consider also stuff like
Snake[:-1] = Snake[1:]
# takes a slice of the list and assign it to another slice


then, unfortunately I don't the exact logic of your code or game:
where is the position of the head of the snake ever defined ?


hope, that helps !