naprawienie kolizji ze stołami i krzesłami

This commit is contained in:
Michał Szuszert 2022-04-28 19:27:49 +02:00
parent 6244a2832f
commit 421b42d578

View File

@ -362,6 +362,25 @@ for i in range(16):
for table in tables: for table in tables:
map.add_table(table.loc) map.add_table(table.loc)
def check_collision_with_table(x,y):
answer = False
for i in tables_coordinates:
if i[0] <= x <= i[0] + 32 and i[1] <= y <= i[1] + 32:
answer = True
else:
continue
return answer
def check_collision_with_chair(x,y):
answer = False
for i in chairs:
for j in i:
if j.loc[0] <= x <= j.loc[0] + 32 and j.loc[1] <= y <= j.loc[1] + 32:
answer = True
else:
continue
return answer
def main(): def main():
direction = [] direction = []
while True: while True:
@ -392,10 +411,20 @@ def main():
if left: if left:
waiterGo(mouseToNum()) waiterGo(mouseToNum())
elif right: elif right:
while True:
x = pygame.mouse.get_pos()[1] x = pygame.mouse.get_pos()[1]
y = pygame.mouse.get_pos()[0] y = pygame.mouse.get_pos()[0]
goal = (x//32, y//32) if y > 608 or y < 32 or x > 608 or x < 32 or check_collision_with_table(y,x) or check_collision_with_chair(y, x):
#goal = (18,18) print("I can't go there")
break
goal = (x // 32, y // 32)
route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal)
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
break
elif middle:
x = pygame.mouse.get_pos()[1]
y = pygame.mouse.get_pos()[0]
goal = (18,18)
route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal) route = astar(map.get_arr(), (waiter.loc[1] // 32, waiter.loc[0] // 32), goal)
direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)] direction = [(x[1] - y[1], x[0] - y[0]) for x, y in zip(route[1:], route)]
if len(direction) > 0: if len(direction) > 0: