astar ruch smieciarki
This commit is contained in:
parent
a19449a1c4
commit
83c00349d5
9
game.py
9
game.py
@ -41,6 +41,7 @@ def game():
|
||||
# Petla az uzytkownik zamknie program
|
||||
done = False
|
||||
clock = pygame.time.Clock()
|
||||
temp = True
|
||||
|
||||
# -------- Glowna petla programu -----------
|
||||
while not done:
|
||||
@ -69,11 +70,15 @@ def game():
|
||||
obiekty["smieciarka"].w_dol()
|
||||
|
||||
|
||||
obiekty["smieciarka"].rand_move()
|
||||
#obiekty["smieciarka"].rand_move()
|
||||
while(temp):
|
||||
obiekty["smieciarka"].astar_move(obiekty)
|
||||
temp = False
|
||||
clock.tick(7)
|
||||
#start = obiekty["plansza"][0, 14]
|
||||
#koniec = obiekty["plansza"][14, 0]
|
||||
print(astar.astar(obiekty, (0, 14), (14, 0)))
|
||||
|
||||
#print(astar.astar(obiekty, (0, 14), (14, 0)))
|
||||
#print(len(astar.astar(start, koniec)))
|
||||
pygame.quit()
|
||||
|
||||
|
16
modele.py
16
modele.py
@ -3,6 +3,7 @@ import game
|
||||
import random
|
||||
import os
|
||||
import shutil
|
||||
import astar
|
||||
|
||||
# wysokosc i szerokosc kazdej kratki
|
||||
WIDTH = 60
|
||||
@ -24,6 +25,7 @@ class Smieciarka(pygame.sprite.Sprite):
|
||||
def __init__(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.pozycja = (self.x, self.y)
|
||||
self.image = pygame.image.load('resources/plansza/smieciarka.png')
|
||||
self.obraz = None
|
||||
self.ruch = 1
|
||||
@ -54,6 +56,20 @@ class Smieciarka(pygame.sprite.Sprite):
|
||||
elif rand_int == 3:
|
||||
self.w_dol()
|
||||
|
||||
def astar_move(self, obiekty):
|
||||
sciezka = astar.astar(obiekty, self.pozycja, (14, 0))
|
||||
print(sciezka)
|
||||
for koord in sciezka:
|
||||
if koord[0] == self.x - 1 and koord[1] == self.y:
|
||||
self.w_lewo()
|
||||
elif koord[0] == self.x + 1 and koord[1] == self.y:
|
||||
self.w_prawo()
|
||||
elif koord[0] == self.x and koord[1] + 1 == self.y:
|
||||
self.w_gore()
|
||||
elif koord[0] == self.x and koord[1] - 1 == self.y:
|
||||
self.w_dol()
|
||||
print("skonczylem")
|
||||
|
||||
def w_lewo(self):
|
||||
if self.x > 0:
|
||||
if self.plansza[self.x - 1, self.y].jestPrzeszkoda is not True:
|
||||
|
Loading…
Reference in New Issue
Block a user