小编Poi*_*ter的帖子

如何在贪吃蛇游戏中为蛇的身体部位使用不同的图像?(Python、Pygame、蛇)

解释

我目前正在使用 Pygame 开发蛇游戏,但我有一个问题,因为我的蛇目前仅由方块组成,但如果蛇包含绘制的 25x25 图片,用于蛇头、身体、尾巴和蛇尾,我会发现它会更好。弯曲身体的一部分,这样当蛇改变高度和方向时,这部分看起来仍然与蛇相连。

我还添加了一个示例图像,以便您可以更好地理解我所说的不同身体部位的含义。

在此输入图像描述


这是我的代码的相关部分,因此您可以看到正在生长的蛇体当前如何工作。

block_size = 25
black = (0, 0, 0)

# This function contains a list with the current coordinates of the snake head (coordinates) 
# and then draws rectangles of size 25x25 (block_size).

def body_segments(block_size, coordinates):
    for XnY in coordinates:
        pygame.draw.rect(screen, black, [XnY[0], XnY[1], block_size, block_size])


coordinates = []
snake_lenght = 0

# Game Loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Background …
Run Code Online (Sandbox Code Playgroud)

python pygame game-development game-engine python-3.x

4
推荐指数
1
解决办法
2056
查看次数