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: # go left if event.key == pygame.K_LEFT and x > (tile_width / 2): x -= tile_width # go right if event.key == pygame.K_RIGHT and x < (grid_width - (tile_width / 2)): x += tile_width # go up if event.key == pygame.K_UP and y > (tile_height / 2): y -= tile_height # go down if event.key == pygame.K_DOWN and y < (grid_height - (tile_height / 2)): y += tile_height return (x, y)