commit 737d323257300be09d8c742c0c49fe91c07fcb11 Author: s481847 Date: Wed Mar 13 18:05:38 2024 +0100 Upload files to "/" diff --git a/kelner.png b/kelner.png new file mode 100644 index 0000000..8e3d7a5 Binary files /dev/null and b/kelner.png differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..7fb7e34 --- /dev/null +++ b/main.py @@ -0,0 +1,73 @@ +import pygame +import random +import time + +pygame.init() + +pygame.display.set_caption("Automatyczny kelner") +#----------------wymiary okna +width = 1000 +height = 800 + +x_k = 1 #----------wspolrzedna x kelnera +y_k = 1 #----------wspolrzedna y kelnera + +screen = pygame.display.set_mode((width, height)) + +#-----------wspolrzedna stolikow +coords = ["100 250", "800 250", "100 600", "800 600"] + +kelnerImg = pygame.image.load("kelner.png") +kelnerImg = pygame.transform.scale(kelnerImg, (100, 100)) +stolikImg = pygame.image.load("stolik.png") +stolikImg = pygame.transform.scale(stolikImg, (140, 140)) + +def kelner(x, y): + screen.blit(kelnerImg, (x, y)) + +def stolik(x, y): + screen.blit(stolikImg, (x, y)) + +#-------------Stolik do ktorego idzie kelner +cel = coords[random.randrange(0, 4)] +run = True + +while run: + + screen.fill((0, 0, 0)) + kelner(x_k, y_k) + + for i in range(4): + test = coords[i] + x_y = test.split(" ") + x = int(x_y[0]) + y = int(x_y[1]) + stolik(x, y) + + split = str(cel).split(" ") + x_s = int(split[0]) + y_s = int(split[1]) + + #print("X_k: " + str(x_k) + " Y_k: " + str(y_k))-------------Wypisuje wspolrzedne kelnera + + #----------------Sprawdzenie w ktora strone ma isc kelner + if x_k != x_s: + x = (x_s - x_k) / abs(x_s - x_k) + else: + x = 0 + if y_k != y_s: + y = (y_s - y_k) / abs(y_s - y_k) + else: + y = 0 + x_k = x_k + x + y_k = y_k + y + if x_k == x_s and y_k == y_s: + cel = coords[random.randrange(0, 4)] + time.sleep(0.001) + + key = pygame.key.get_pressed() + pygame.display.update() + for event in pygame.event.get(): + if event.type == pygame.QUIT: + run = False +pygame.quit() \ No newline at end of file diff --git a/stolik.png b/stolik.png new file mode 100644 index 0000000..c71186e Binary files /dev/null and b/stolik.png differ