80 lines
2.9 KiB
Python
80 lines
2.9 KiB
Python
import sys
|
|
import pygame
|
|
from wozek import Wozek
|
|
import wyszukiwanie
|
|
import ekran
|
|
from grid import SearchGrid
|
|
pygame.init()
|
|
|
|
|
|
def main():
|
|
wozek = Wozek()
|
|
|
|
while True:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
sys.exit(0)
|
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
|
sys.exit(0)
|
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
# lewy przycisk myszy
|
|
if event.button == 1:
|
|
grid_points = SearchGrid()
|
|
x = pygame.mouse.get_pos()[0]
|
|
y = pygame.mouse.get_pos()[1]
|
|
wiersz = ekran.sprawdz_ktory_wiersz(x)
|
|
kolumna = ekran.sprawdz_ktora_kolumna(y)
|
|
docelowy_stan = wyszukiwanie.Stan(wiersz * 70, kolumna * 70, 1)
|
|
# wezel = wyszukiwanie.wyszukiwanie_bfs(wozek.obecnyStan, docelowy_stan, grid_points)
|
|
wezel = wyszukiwanie.wyszukiwanie_a_star(wozek.obecnyStan, docelowy_stan, grid_points)
|
|
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
|
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_DOWN:
|
|
wozek.y_change = 1
|
|
if event.key == pygame.K_UP:
|
|
wozek.y_change = -1
|
|
if event.key == pygame.K_RIGHT:
|
|
wozek.x_change = 1
|
|
if event.key == pygame.K_LEFT:
|
|
wozek.x_change = -1
|
|
|
|
if event.type == pygame.KEYUP:
|
|
if event.key == pygame.K_DOWN or event.key == pygame.K_UP:
|
|
wozek.y_change = 0
|
|
if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
|
|
wozek.x_change = 0
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_SPACE:
|
|
if wozek.ln == 0:
|
|
wozek.load_package()
|
|
wozek.dynamic_wozek_picture()
|
|
else:
|
|
wozek.drop_package()
|
|
wozek.dynamic_wozek_picture()
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
if event.key == pygame.K_p:
|
|
wozek.place_on_shelf(ekran.regals_collision_group, "dolna")
|
|
|
|
|
|
wozek.obecnyStan.x += wozek.x_change
|
|
wozek.obecnyStan.y += wozek.y_change
|
|
|
|
if wozek.obecnyStan.x <= 0:
|
|
wozek.obecnyStan.x = 0
|
|
elif wozek.obecnyStan.x >= ekran.EKRAN_SZEROKOSC-70:
|
|
wozek.obecnyStan.x = ekran.EKRAN_SZEROKOSC-70
|
|
if wozek.obecnyStan.y <= 0:
|
|
wozek.obecnyStan.y = 0
|
|
elif wozek.obecnyStan.y >= ekran.EKRAN_WYSOKOSC-70:
|
|
wozek.obecnyStan.y = ekran.EKRAN_WYSOKOSC-70
|
|
|
|
ekran.odswiez_ekran(wozek)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|