I want it so that when i press my left arrow key (for example) the snake head will move towards the left. I have been using the pygame.display.flip command for that but that would mean if i keep clicking my left key it continually flips left and right.
if event.key == K_LEFT:
block = pygame.transform.flip(block, True, False)
block_x -= 20
(rest of my code if it helps)
import pygame
from pygame.locals import *
def draw_block():
surface.fill((44, 250, 150))
surface.blit(block, (block_x, block_y))
pygame.display.update
def change_direction():
block = pygame.display.flip
pygame.init()
WND_RES = (800, 600)
surface = pygame.display.set_mode(WND_RES)
surface.fill((44, 250, 150))
block_x = 100
block_y = 100
block = pygame.image.load("resources/pogchamp.jpg").convert()
surface.blit(block,(block_x,block_y))
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == KEYDOWN:
pass
if event.key == K_ESCAPE:
running = False
if event.key == K_UP:
block_y -= 20
draw_block()
if event.key == K_DOWN:
block_y += 20
draw_block()
if event.key == K_LEFT:
block = pygame.transform.flip(block, True, False)
block_x -= 20
draw_block()
if event.key == K_RIGHT:
block_x += 20
block = pygame.transform.flip(block, True, False)
draw_block()
elif event.type == QUIT:
running = False
pygame.display.update()