Machine_learning_2023/Interface/movement.py
countingthedots 50a0eda8ef obrazy kota
2023-03-28 19:44:39 +02: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)