我目前正在使用 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)