Machine_learning_2023/Interface/movement.py

26 lines
681 B
Python
Raw Normal View History

2023-03-12 20:13:00 +01:00
import pygame
import sys
2023-03-16 20:33:22 +01:00
2023-03-28 19:36:57 +02:00
def movement_key_press(board_size, x, y, cat_x=None, cat_y=None):
2023-03-12 20:13:00 +01:00
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
2023-03-16 20:33:22 +01:00
# go left
2023-03-23 00:54:05 +01:00
if event.key == pygame.K_LEFT and x > 0:
x -= 1
2023-03-16 20:33:22 +01:00
2023-03-23 00:54:05 +01:00
# go right
if event.key == pygame.K_RIGHT and x < board_size - 1:
x += 1
2023-03-16 20:33:22 +01:00
2023-03-23 00:54:05 +01:00
# go up
if event.key == pygame.K_UP and y > 0:
y -= 1
2023-03-16 20:33:22 +01:00
2023-03-23 00:54:05 +01:00
# go down
if event.key == pygame.K_DOWN and y < board_size - 1:
y += 1
2023-03-16 20:33:22 +01:00
return (x, y)