Machine_learning_2023/Interface/vacuum_render.py

51 lines
1.3 KiB
Python

from Interface.grid_draw import GridDraw, Colors
import sys
import pygame
from random import randint
GRID_SIZE_X = 10
GRID_SIZE_Y = 10
# dummy function
def initial_draw():
# window name
pygame.display.set_caption("AI Vacuum Cleaner")
grid = GridDraw(800, 800, GRID_SIZE_X, GRID_SIZE_Y)
x = 2
y = 2
peels = []
for _ in range(10):
temp_x = randint(0, GRID_SIZE_X)
temp_y = randint(0, GRID_SIZE_Y)
peels.append((temp_x, temp_y))
while True:
grid.start_draw()
grid.fill_grid_with_sprite('TILE')
grid.board()
for peel in peels:
grid.draw_sprite(peel[0], peel[1], "PEEL")
grid.draw_sprite(x, y, "VACUUM")
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
match event.key:
case pygame.K_LEFT:
x = (x - 1 + GRID_SIZE_X) % GRID_SIZE_X
case pygame.K_RIGHT:
x = (x + 1 + GRID_SIZE_X) % GRID_SIZE_X
case pygame.K_UP:
y = (y - 1 + GRID_SIZE_Y) % GRID_SIZE_Y
case pygame.K_DOWN:
y = (y + 1 + GRID_SIZE_Y) % GRID_SIZE_Y
grid.end_draw(delay=10)