Snake problems - Movement
Question: I am having some issues with my code in python, I am making a version of
snake, my issue concerns the movement of the snake itself. I have gotten the
directions working fine, I just need to make it so that the snake continues
moving in the direction it has been told to do so via the key press, I also
need to make it so that it is the one block, currently it shows all previous
blocks once it has been moved.

    
    
    import pygame, sys, time, random
    from pygame.locals import *
    
    pygame.init()
    
    size = width,height = 480, 480 #16x30,16x30
    grey = (128,128,128)
    screen = pygame.display.set_mode(size)
    icon = pygame.image.load('snakeIcon.png')
    newDir = 0
    prevDir = 0
    FPS = 8
    
    xCoord = 10.0
    yCoord = 10.0
    
    #Main Program:
    pygame.display.set_caption('Anthony\'s Snake')
    pygame.display.set_icon(icon)
    screen.fill(grey)
    
    fpsTime = pygame.time.Clock()
    
    gameB = pygame.image.load('gameB.png')
    border = {}
    createLvl()
    
    snakeH = pygame.image.load('snakeH.png')
    snake = {}
    
    refreshScreen()
    
    keyCheck = {'LEFT':bool(0), 'RIGHT':bool(0), 'UP':bool(0), 'DOWN':bool(0),    'ESC':bool(0)}
    
    pygame.mixer.music.load('retroMusik.mp3')
    pygame.mixer.music.set_volume(0.5)
    pygame.mixer.music.play(-1)
    
    while bool(1):
    for i in range(1):
        snake[str(len(snake))]=snakeH.get_rect()
    x = xCoord
    y = yCoord
    for i in range(len(snake)):
        snake[str(i)].x = x*16
        snake[str(i)].y = y*16
    
    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit()
        if event.type == KEYDOWN:
            if event.key == K_UP :
                keyCheck['UP'] = bool(1)
            if event.key == K_DOWN :
                keyCheck['DOWN'] = bool(1)
            if event.key == K_LEFT :
                keyCheck['LEFT'] = bool(1)
            if event.key == K_RIGHT :
                keyCheck['RIGHT'] = bool(1)
            if event.key == K_ESCAPE :
                keyCheck['ESC'] = bool(1)
    
        if event.type == KEYUP:
            if event.key == K_UP :
                keyCheck['UP'] = bool(0)
            elif event.key == K_DOWN :
                keyCheck['DOWN'] = bool(0)
            elif event.key == K_LEFT :
                keyCheck['LEFT'] = bool(0)
            elif event.key == K_RIGHT :
                keyCheck['RIGHT'] = bool(0)
            elif event.key == K_ESCAPE :
                keyCheck['ESC'] = bool(0)
    
    if keyCheck['UP']:
        if prevDir != 'DOWN':
            newDir = 'UP'
            print('Direction changed to UP')
    if keyCheck['DOWN']:
        if prevDir != 'UP':
            newDir = 'DOWN'
            print('Direction changed to DOWN')
    if keyCheck['LEFT']:
        if prevDir != 'RIGHT':
            newDir = 'LEFT'
            print('Direction changed to LEFT')
    if keyCheck['RIGHT']:
        if prevDir != 'LEFT':
            newDir = 'RIGHT'
            print('Direction changed to RIGHT')
    prevDir = newDir
    
    
    if keyCheck['UP'] == bool(1):
        yCoord -= 1
    if keyCheck['DOWN'] == bool(1):
        yCoord += 1
    if keyCheck['LEFT'] == bool(1):
        xCoord -= 1
    if keyCheck['RIGHT'] == bool(1):
        xCoord += 1
    
    refreshScreen()
    fpsTime.tick(FPS)
    

Please be soft on me, I am still new to this. Thank you in advance.


Answer: I think your animation doesn't work right because you don't erase (cover with
background) the screen before drawing. See
[this](http://www.pygame.org/docs/tut/MoveIt.html) Pygame tutorial for slow
and detailed explanation.

Don't use `bool(1)`. Use `True` and `False`.

I'm not sure but I think the problem with the snake not moving is either A)
you reset your control/movement variable or B) you don't check it every
"round"/frame.

I'd really recommend finding some tutorial (or something) and read some Python
code by other people, your code could use a lot of improvement (this isn't
_bad_ , the important thing is trying to improve).

