This is my final project for my Python class. It's basically a snake game, only it's themed so instead of a snake, there is a leading image (the head) and a train behind it (the snake body).
Everything is perfect in the code, except one thing: the way the code is now, the head is at the end of the snake and I can't figure out for the life of me how to move it to the front where it leads the train.
Here is my code:
I have tried your code, and I change a little in the drawCock
function:
def drawCock(Cock):
for place in Cock:
x = place['x'] * size
y = place['y'] * size
CART = pygame.transform.scale(image2,(size,size))
SHOW.blit(CART,(x,y))
if Cock[2:]:
HEAD = pygame.transform.scale(image1,(size,size))
SHOW.blit(HEAD,(Cock[0]['x']*size,Cock[0]['y']*size))
I use the dictionary Cock
's first item's x
and y
as the coordinate values to draw the head. The head is in the first position of the snake now. Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.