From 9db0cc3cfdb3b584c4f2b0ff9d7dd682dc8fad44 Mon Sep 17 00:00:00 2001 From: countingthedots Date: Sun, 12 Mar 2023 20:13:00 +0100 Subject: [PATCH] movement as a seperate function --- Interface/movement.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Interface/movement.py diff --git a/Interface/movement.py b/Interface/movement.py new file mode 100644 index 0000000..cbcd2c0 --- /dev/null +++ b/Interface/movement.py @@ -0,0 +1,17 @@ +import pygame +import sys + +def moving_cleaner(grid_width, grid_height,tile_width,tile_height, x, y): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit() + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT and x>(tile_width / 2): + x -= tile_width + if event.key == pygame.K_RIGHT and x<(grid_width-(tile_width / 2)): + x += tile_width + if event.key == pygame.K_UP and y>(tile_height / 2): + y -= tile_height + if event.key == pygame.K_DOWN and y<(grid_height-(tile_height / 2)): + y += tile_height + return(x,y)