From a0bfe9fcf743673d9c901a46dc2c21667d47539a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Ciesi=C3=B3=C5=82ka?= Date: Tue, 5 Apr 2022 18:36:43 +0200 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiles.py | 233 +++++++++++++++++++++++++++++++++++++++++++++++----- waiterD.png | Bin 0 -> 1894 bytes waiterL.png | Bin 0 -> 1691 bytes waiterR.png | Bin 0 -> 1749 bytes 4 files changed, 212 insertions(+), 21 deletions(-) create mode 100644 waiterD.png create mode 100644 waiterL.png create mode 100644 waiterR.png diff --git a/tiles.py b/tiles.py index 521dd74..8b9f4f1 100644 --- a/tiles.py +++ b/tiles.py @@ -1,6 +1,9 @@ +import time import numpy as np import pygame import pytmx +from queue import Queue +import math pygame.init() @@ -8,6 +11,9 @@ display = pygame.display.set_mode((640, 640)) clock = pygame.time.Clock() gameMap = pytmx.load_pygame("cafe.tmx") waiterImg = pygame.image.load("waiter.png") +waiterImgD = pygame.image.load("waiterD.png") +waiterImgL = pygame.image.load("waiterL.png") +waiterImgR = pygame.image.load("waiterR.png") tableImg = pygame.image.load('table.png') chairImg = pygame.image.load('chair.png') @@ -38,6 +44,19 @@ class Waiter: elif key[pygame.K_d] or key[pygame.K_RIGHT]: self.loc[0] += 32 + def up(self): + self.loc[1] -= 32 + + def down(self): + self.loc[1] += 32 + + def left(self): + self.loc[0] -= 32 + + def right(self): + self.loc[0] += 32 + + class Table: def __init__(self, loc, num): @@ -97,7 +116,159 @@ class Order(Table): self.status = True -waiter = Waiter([64, 320]) +class Graph: + def __init__(self, num_of_nodes, directed=True): + self.m_num_of_nodes = num_of_nodes + self.m_nodes = range(self.m_num_of_nodes) + self.m_directed = directed + self.m_adj_list = {node: set() for node in self.m_nodes} + + def add_edge(self, node1, node2, weight=1): + self.m_adj_list[node1].add((node2, weight)) + if not self.m_directed: + self.m_adj_list[node2].add((node1, weight)) + + def print_adj_list(self): + for key in self.m_adj_list.keys(): + print("node", key, ": ", self.m_adj_list[key]) + + def bfs(self, start_node, target_node): + visited = set() + queue = Queue() + queue.put(start_node) + visited.add(start_node) + parent = dict() + parent[start_node] = None + path_found = False + while not queue.empty(): + current_node = queue.get() + if current_node == target_node: + path_found = True + break + for (next_node, weight) in self.m_adj_list[current_node]: + if next_node not in visited: + queue.put(next_node) + parent[next_node] = current_node + visited.add(next_node) + path = [] + if path_found: + path.append(target_node) + while parent[target_node] is not None: + path.append(parent[target_node]) + target_node = parent[target_node] + path.reverse() + return path + + +def pathFromTo(start, dest): + tab2 = [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57] + tab4 = [41, 58] + tab3 = [] + tab5 = [] + for x in range(16): + for num in tab4: + tab5.append(num + x * 20) + for x in range(16): + for num in tab2: + tab3.append(num + x * 20) + graph = Graph(400, directed=False) + for x in tab5: + b = x + 1 + c = x + 20 + d = x - 20 + graph.add_edge(x, b) + graph.add_edge(x, c) + graph.add_edge(x, d) + for x in tab3: + b = x + 1 + c = x + 20 + d = x - 1 + e = x - 20 + graph.add_edge(x, b) + graph.add_edge(x, c) + graph.add_edge(x, d) + graph.add_edge(x, e) + graph.add_edge(21, 22) + graph.add_edge(21, 41) + graph.add_edge(378, 358) + graph.add_edge(378, 377) + graph.add_edge(38, 37) + graph.add_edge(38, 58) + graph.add_edge(361, 362) + graph.add_edge(361, 341) + # graph.print_adj_list() + path = [] + path = graph.bfs(start, dest) + return path + + +def numToX(num): + digits = [int(a) for a in str(num)] + if num >= 100: + if digits[1] % 2 == 0: + x = digits[2] + else: + x = digits[2] + 10 + else: + if digits[0] % 2 == 0: + x = digits[1] + else: + x = digits[1] + 10 + x = x * 32 + return x + + +def numToY(num): + y = (math.floor(num/20)) * 32 + return y + + +def coordsToNum(coords): + num = ((coords[1]//32) * 20) + (coords[0]//32) + return int(num) + + +def waiterGo(dest): + print("Path: ", (pathFromTo(coordsToNum(waiter.loc), dest))) + go = [] + for numb in range(len(pathFromTo(coordsToNum(waiter.loc), dest)) - 1): + go.append(pathFromTo(coordsToNum(waiter.loc), dest)[numb] - pathFromTo(coordsToNum(waiter.loc), dest)[numb + 1]) + for x in range(len(go)): + if go[x] == -20: + waiter.down() + display.blit(waiterImgD, (waiter.loc[0], waiter.loc[1])) + #waiter.render(display) + pygame.display.update() + + time.sleep(0.2) + elif go[x] == 20: + waiter.up() + display.blit(waiterImg, (waiter.loc[0], waiter.loc[1])) + #waiter.render(display) + pygame.display.update() + time.sleep(0.2) + elif go[x] == 1: + waiter.left() + display.blit(waiterImgL, (waiter.loc[0], waiter.loc[1])) + #waiter.render(display) + pygame.display.update() + time.sleep(0.2) + elif go[x] == -1: + waiter.right() + display.blit(waiterImgR, (waiter.loc[0], waiter.loc[1])) + #waiter.render(display) + pygame.display.update() + time.sleep(0.2) + +def mouseToNum(): + x = pygame.mouse.get_pos()[0] + y = pygame.mouse.get_pos()[1] + cordTab = [x, y] + squareNum = coordsToNum(cordTab) + return squareNum + + +waiter = Waiter([32, 32]) tables = [] chairs = [] tables_coordinates = ((32 * 3, 32 * 2), (32 * 7, 32 * 2), (32 * 12, 32 * 2), (32 * 16, 32 * 2), @@ -111,31 +282,51 @@ for i in range(16): arr.append(Chair(pos_of_chair(tables_coordinates[i], j))) chairs.append(arr) -while True: - clock.tick(10) - keys = pygame.key.get_pressed() - for event in pygame.event.get(): - if event.type == pygame.QUIT: +def main(): + + while True: + + clock.tick(10) + keys = pygame.key.get_pressed() + + for event in pygame.event.get(): + if event.type == pygame.QUIT: + quit() + + if keys[pygame.K_ESCAPE]: quit() - if keys[pygame.K_ESCAPE]: - quit() + for layer in gameMap.visible_layers: + for x, y, gid, in layer: + tile = gameMap.get_tile_image_by_gid(gid) + if tile is not None: + display.blit(tile, (x * gameMap.tilewidth, y * gameMap.tileheight)) - for layer in gameMap.visible_layers: - for x, y, gid, in layer: - tile = gameMap.get_tile_image_by_gid(gid) - if tile is not None: - display.blit(tile, (x * gameMap.tilewidth, y * gameMap.tileheight)) + waiter.handle_events() - waiter.handle_events() + for table in tables: + table.render(display) + for chair_list in chairs: + for chair in chair_list: + chair.render(display) - for table in tables: - table.render(display) - for chair_list in chairs: - for chair in chair_list: - chair.render(display) + key = pygame.key.get_pressed() + left, middle, right = pygame.mouse.get_pressed() + + if left: + waiterGo(mouseToNum()) + + key = pygame.key.get_pressed() + if key[pygame.K_p]: + pass + + waiter.render(display) + pygame.display.update() + + + +if __name__ == '__main__': + main() - waiter.render(display) - pygame.display.update() diff --git a/waiterD.png b/waiterD.png new file mode 100644 index 0000000000000000000000000000000000000000..390ae1364a815891e0dd522f31e8834b13f6fd09 GIT binary patch literal 1894 zcmV-s2buVZP)Px+AW1|)R9Hu~mwQlD_Z7##_wL>I!an4opfPIPhz4;4i6bvbqTmBC+G&iH5tCpb z1}BEjbP~`aitS9pXc29qZ76AdBsC-i(P$H?VsI!yq=51eNd}7Y+6Vi-d+*-PUBnS& zT^h~#XMcCk{hjl<=bYd9{eA>SLv^N+wB2M_4?Gw5`^3DElp+=(y#``Ss4>zn7Mz0r=vP0IqA7Kp1rQZE^}5Xk|~g{uc+K&?v$ zXVOD?^-JrwmfND~8-GoKRG=FCU z2TC^BO&9LlBU_QUnkYJS(CutT);qXxu9C~n&9mD4XNUkWRA`j+L6XrLxYOH<6){Wu zOvA%L09>O0kjmwoLPHlGNqy}N<*p+o53K^G;+Q#h)fXF&@p%Q2u^zp0Tm<`nz_k^<#eSeSmw0 zia`j{+38y6_+`ig?r(MXpnBxYW?zPeAi~->PluD%=?Ho}^_^8E%I*=k&ehNY&6R_7V*>{(=OLzcY z{+joTVQ%_MzV5H+`DQpR@3ec&1LSYf+6Ce963%LdYk1Jg>H2Kku#OQE-1~OB-Tmbr z0q!Yyun+)RkmM`~#WN|6dp$X$P|@3b$<)<+g$h)wm>~a=g6ka^K%d?~%?gcXf)>R2 zeDz_rnIXthu=H&(Ogn&10BwBE$5-e>5%9E-6)OK?7t4yJ0@tgZXU@wNvax-~Y_(#} z+61eOC6AK=0c|!6yzQ|mOd_kOWZ`>b?rY#ipLtQ|0z zh65(!*joxb+R!MKd?=qz-LQduK0I8?cedJV*KB_~eOdsH`(emveD-Gp(5O`T3$)s- z^3qb3(#L0vAEU{Hb!lmamX40%A)Rj5WFaP90{|906&zgMT3xLci}+siusCQMA+fRg zAA5RY0JKa7V$uMCetsto6%=gTux5>WPG)`qPL_QR&cz{l^=g#v-wTo?@p)w>mz9%q zs&8;`(-Q^o(`fGAs;LR|Q7B+{I1rb*6^C}^Kq8eOb9WxTC@w;PMh!j{bEBgAhjhBY zCjuZ62vU?vWvW`KjK5i3t$EPs{y&#s*`hEkk61j$S4d2ZPOmpsnXTqB8%>{h6o|JJ zte8LNnSZQ~j#29ER@2eK!ZDQ>yLk(4w6;w<(YJc!P3FW^>p4`xmc zgit8N@v<^pudBB$kBF3}@7eWPpHBD6PXYkoj(|)e5&rRa`(;ZPFNSvIDs&QpJ}Qw{;U8a5#hk~+_F74 zb&B9dPp^ZU_1yiX`a}T8;AcK2{e!l8>uOwAiq0}u*Q;h*Eqkf!51S%{p z9t3yM8vq{(w-6((g|nK#cD2;ONk={w0B@3fdVT|`)P#X>-$T3$$ARr=FmhHi-+<0P zE&xD@_7Wmd7CA$!^mYk#Us}66j2!Lw2n_ujZ?xX_f(Pd(f)W*gbIsu+?7=Vrg1ile g&H-@Fn{!_OKV-iUPDW5bz5oCK07*qoM6N<$f;Fh4=l}o! literal 0 HcmV?d00001 diff --git a/waiterL.png b/waiterL.png new file mode 100644 index 0000000000000000000000000000000000000000..74d06710a44d88a18c38438fffb9cd504153f4bf GIT binary patch literal 1691 zcmV;M24wk(P)Px*RY^oaR9HvFmw8YVR~W#*J+hnK1j4Bm5o;hKmq)ZBqT+}G9u;*M3ycg^Tb)sR zc#YFqsfE^~9c^{6NXKgS;gDHa$TAAO`@-L1(+m0Vs(iRZNl_2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)kkF|h2BZg3TZz36nB4nckUm;Bc)*^2<62uU@_LPknO-hC|YL!NaKtC>U4*p%9e lLI3~|4&$!Boc0#Ee*se>*JN?NiS_^h002ovPDHLkV1l&FDYpOs literal 0 HcmV?d00001 diff --git a/waiterR.png b/waiterR.png new file mode 100644 index 0000000000000000000000000000000000000000..a3b4040897a6895f7526201f46527227b3559743 GIT binary patch literal 1749 zcmV;`1}gc9P)Px*k4Z#9R9HvFmw9j$RUXH`ujjt#$&ds?$R-Ggf+uPg2uY|YmZC|x2T=qC1(foD z+C^}aWrIgq;(b)%or*=!qBs;ZL}C%c5P~p(IUo!PYlvYLlFVdgx@UU&*y>IKGsz6Z zBjx+A`~8m3d%xfNz277Fiw6O42Y?}A92|fa0QCUG!R8}6osOA1e?h3%5yLWKlj{`U z+|(q5cz#`gVLl#A2oh(rbslSMw)S;$uB{DEEnn(sY&^Nm-O=&LU_lU*$>MvzxWqIi zdnzPJLPhx=Oq!AjlgR|<4~MYyp$9p?uWLmh5Ezu5AVj4O#HHtOaTBNcB!MR#jxw`# z!W2ejwhCQ8RvSa@zp6baj`*Y?JA5#5f)JgtQ-A;Jejy0o^5E`|+r{%gX976!XNO`y z09^HMMrd@}0qnXQfJ&vZ$J6wzPLF2?CkUkjfgKP4UtfdJ(eGA+=Uh2`vZ}>?1FMqFe}Z1pxNQa{~ep&eVfDSoSW0%*t2*30B+I#rZR4 z3!=d8Kk5{nE|-cjnuEfS1U-pM(Dmv`j2B|7%Oi2zCh**vm;ijOgT;Rv1X)oG2GxXP zdA-q6>~o(FhZsLBKK?mg6z>>H)9TFhbZvG73CjoLVIT?rp~kbU2Xpp1rx2K5=Ll2 zVF&0k{!URAoDN^1wQfifQd+locfIwFW!1))*-29-8|LNZDR$@^Z$Z_zt>|!j zFlYG+&@_#`CB+yyJV}{9aQHBC9(c$vjlRj$yYiR-d2{VVtx&+8TUQ&X+HHT2PZy%Q0?U;Y}G-x&53z=}wbYC4y%*0Gb4OKAB$P)W7=&KeU2B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