Machine_learning_2023/Interface/movement.py
2023-03-23 00:54:05 +01:00

26 lines
657 B
Python

import pygame
import sys
def movement_key_press(board_size, x, y):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
# go left
if event.key == pygame.K_LEFT and x > 0:
x -= 1
# go right
if event.key == pygame.K_RIGHT and x < board_size - 1:
x += 1
# go up
if event.key == pygame.K_UP and y > 0:
y -= 1
# go down
if event.key == pygame.K_DOWN and y < board_size - 1:
y += 1
return (x, y)