我有一个python程序,使用turtle来制作游戏“Snake”。它功能齐全。现在我要加入。gif图像来美化它。
当我试图使用自定义形状作为蛇头时,问题就出现了。如果我使用海龟的基本形状,比如“三角形”或“箭头”,效果很好。它可以正确转动,并按预期打印在第一个车身段上。当我将其更改为自定义图像时,问题是它打印在第一个身体部分下,无法旋转。
对照样本
if direction == "up":
if snake_direction != "down":
snake_direction = "up"
head_stamper.setheading(90)
母版用于制作许多节,第一节上有一个头。
for segment in snake:
stamper.goto(segment[0], segment[1]) #These are the body segments, they work fine.
stamper.stamp()
head_stamper.goto(new_head)
在这里显示两个母版。
# Stamper for each body section
stamper = turtle.Turtle()
stamper.shape(bod_segment)
stamper.shapesize(25 / 20)
stamper.penup()
# Special stamper just for the snake's head.
head_stamper = turtle.Turtle()
# head_stamper has no issues when I make the shape "arrow" or "triangle", etc.
head_stamper.shape(head_segment)
stamper.shapesize(25 / 20)
head_stamper.penup()
我认为这就是所有与问题相关的代码。