142 lines
3.7 KiB
Python
142 lines
3.7 KiB
Python
import pygame
|
|
import random
|
|
import time
|
|
import threading
|
|
|
|
pygame.init()
|
|
|
|
pygame.display.set_caption("Automatyczny kelner")
|
|
#----------------wymiary okna
|
|
width = 1200
|
|
height = 800
|
|
|
|
x_k = 1 #----------wspolrzedna x kelnera
|
|
y_k = 1 #----------wspolrzedna y kelnera
|
|
|
|
screen = pygame.display.set_mode((width, height))
|
|
|
|
#-----------wspolrzedna stolikow
|
|
coords = ["325 320", "325 640", "885 320", "885 640"]
|
|
zamowienia = [0, 0, 1, 1]
|
|
|
|
kelnerStan = 0 #--- 0 - brak zamowienia, 1 - zamownienie, 2 - danie
|
|
|
|
kelnerImg = pygame.image.load("kelner.png")
|
|
kelnerImg = pygame.transform.scale(kelnerImg, (70, 70))
|
|
stolikImg = pygame.image.load("stolik.png")
|
|
stolikImg = pygame.transform.scale(stolikImg, (70, 70))
|
|
menuImg = pygame.image.load("menu.png")
|
|
menuImg = pygame.transform.scale(menuImg, (40, 40))
|
|
kitchenImg = pygame.image.load("kitchen.png")
|
|
kitchenImg = pygame.transform.scale(kitchenImg, (100, 100))
|
|
|
|
def kuchnia(x, y):
|
|
screen.blit(kitchenImg, (x, y))
|
|
|
|
def kelner(x, y):
|
|
screen.blit(kelnerImg, (x, y))
|
|
|
|
def stolik(x, y):
|
|
screen.blit(stolikImg, (x, y))
|
|
|
|
def changeTable(x, y):
|
|
screen.blit(menuImg, (x, y))
|
|
|
|
|
|
#def randomoweZamowienia():
|
|
#threading.Timer(5.0).start()
|
|
#x = random.randrange(0, 4)
|
|
#if zamownienia[x] == 0:
|
|
#zamownienia[x] = 1
|
|
#stolikImg = pygame.image.load("menu.png") #----zmien
|
|
#stolikImg = pygame.transform.scale(stolikImg, (70, 70))
|
|
#screen.blit(stolikImg, (1, 1))
|
|
|
|
|
|
|
|
def wypiszOkno():
|
|
screen.fill((0, 0, 0))
|
|
blockSize = 80
|
|
for x in range(0, width, blockSize):
|
|
for y in range(0, height, blockSize):
|
|
rect = pygame.Rect(x, y, blockSize, blockSize)
|
|
pygame.draw.rect(screen, (200, 200, 200), rect, 1) #-------------Wypisz kratę -TA
|
|
|
|
#-------------Stolik do ktorego idzie kelner
|
|
cel = coords[random.randrange(0, 4)]
|
|
run = True
|
|
|
|
#def randomTime():
|
|
# x = random.randrange(2, 20)
|
|
# threading.Timer(x, randomTime).start()
|
|
# y=random.randrange(0, 2)
|
|
# return y
|
|
|
|
#whichPic = randomTime()
|
|
|
|
while run:
|
|
|
|
wypiszOkno()
|
|
kuchnia(40, 40)
|
|
kelner(x_k, y_k)
|
|
if kelnerStan == 1:
|
|
changeTable(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])
|
|
|
|
for j in range(len(zamowienia)): #------------weź zamowienie
|
|
if zamowienia[j] == 1:
|
|
test = coords[j]
|
|
x_y = test.split(" ")
|
|
x = int(x_y[0])
|
|
y = int(x_y[1])
|
|
changeTable(x, y)
|
|
split2 = str(coords[j]).split(" ")
|
|
x_s2 = int(split2[0])
|
|
y_s2 = int(split2[1])
|
|
if (x_k == x_s2) and (y_k == y_s2) and kelnerStan == 0:
|
|
zamowienia[j] = 0
|
|
kelnerStan = 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
|
|
|
|
if x != 0:
|
|
x_k = x_k + x
|
|
else:
|
|
y_k = y_k + y
|
|
if x_k == x_s and y_k == y_s:
|
|
if kelnerStan == 1:
|
|
cel = "20 20"
|
|
else:
|
|
cel = coords[random.randrange(0, 4)]
|
|
|
|
if x_k == 20 and y_k == 20:
|
|
kelnerStan = 0
|
|
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() |