Estou começando a aprender python, e estou utilizando a biblioteca pygame para desenvolver o jogo snake, estou com dificuldade de programar a movimentação da cobra, alguem que ja utilizou a biblioteca pode me ajudar?
CODIGO FONTE:
#JOGO SNAKE
import pygame
from pygame.locals import *
import random
#Definir posição aleatória da maçã
def random_pos():
x = random.randint(0,590)
y = random.randint(0,590)
return (x//10 *10, y//10 *10)
#todo game feito com pygame inicia com essa função
pygame.init()
#definindo o tamanho da janela
screen = pygame.display.set_mode([600,600])
pygame.display.set_caption('Snake')#Titulo da janela
#Variaveis para movimentação
UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3
my_direction = LEFT
#Variavel para cobra
snake = ((200,200),(210,200),(220,200))
snake_skin = pygame.Surface((10,10))
snake_skin.fill((255,255,255))
#Variável para maçã
apple = pygame.Surface((10,10))
apple.fill((255,0,0))
apple_pos = random_pos()
#Variavel para definir FPS
clock = pygame.time.Clock()
#Laço Principal
while True:
#Obtendo interação do usuário com a aplicação
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
if event.type == KEYDOWN:
if event.type == K_UP:
my_direction = UP
if event.type == K_RIGHT:
my_direction = RIGHT
if event.type == K_DOWN:
my_direction = DOWN
if event.type == K_LEFT:
my_direction = LEFT
screen.fill((0, 0, 0))#definindo cor da janela
screen.blit(apple, apple_pos)#exibindo maça na tela
clock.tick(20)#Definindo FPS máximo
#movimentação da cobra
if my_direction == UP:
snake[0] = snake[0][0], snake[0][1] + 10
pygame.display.update()