From 421b42d57825688ba8e023a56499b6a6e630e58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Szuszert?= Date: Thu, 28 Apr 2022 19:27:49 +0200 Subject: [PATCH] =?UTF-8?q?naprawienie=20kolizji=20ze=20sto=C5=82ami=20i?= =?UTF-8?q?=20krzes=C5=82ami?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiles.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tiles.py b/tiles.py index b6d6098..43ac16f 100644 --- a/tiles.py +++ b/tiles.py @@ -362,6 +362,25 @@ for i in range(16): for table in tables: 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(): direction = [] while True: @@ -392,10 +411,20 @@ def main(): if left: waiterGo(mouseToNum()) elif right: + while True: + x = pygame.mouse.get_pos()[1] + y = pygame.mouse.get_pos()[0] + 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): + 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 = (x//32, y//32) - #goal = (18,18) + goal = (18,18) 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)] if len(direction) > 0: