Upload files to "/"
This commit is contained in:
commit
737d323257
BIN
kelner.png
Normal file
BIN
kelner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 214 KiB |
73
main.py
Normal file
73
main.py
Normal file
@ -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()
|
BIN
stolik.png
Normal file
BIN
stolik.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 39 KiB |
Loading…
Reference in New Issue
Block a user