2023-03-12 20:13:00 +01:00
|
|
|
import pygame
|
|
|
|
import sys
|
|
|
|
|
2023-03-16 20:33:22 +01:00
|
|
|
|
2023-03-16 21:55:05 +01:00
|
|
|
def robot_movement(grid_width, grid_height, tile_width, tile_height, x, y):
|
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
|
|
|
|
if event.key == pygame.K_LEFT and x > (tile_width / 2):
|
2023-03-12 20:13:00 +01:00
|
|
|
x -= tile_width
|
2023-03-16 20:33:22 +01:00
|
|
|
|
|
|
|
# go right
|
|
|
|
if event.key == pygame.K_RIGHT and x < (grid_width - (tile_width / 2)):
|
2023-03-12 20:13:00 +01:00
|
|
|
x += tile_width
|
2023-03-16 20:33:22 +01:00
|
|
|
|
|
|
|
# go up
|
|
|
|
if event.key == pygame.K_UP and y > (tile_height / 2):
|
2023-03-12 20:13:00 +01:00
|
|
|
y -= tile_height
|
2023-03-16 20:33:22 +01:00
|
|
|
|
|
|
|
# go down
|
|
|
|
if event.key == pygame.K_DOWN and y < (grid_height - (tile_height / 2)):
|
2023-03-12 20:13:00 +01:00
|
|
|
y += tile_height
|
2023-03-16 20:33:22 +01:00
|
|
|
return (x, y)
|