From 919c4ca04c073c9f7f266ce90b7b3136b6a97d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kinder?= Date: Mon, 21 Mar 2022 15:04:00 +0100 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 --- cafe.tmx | 24 ++++++------- chair.png | Bin 0 -> 2129 bytes table.png | Bin 0 -> 2447 bytes tiles.py | 104 +++++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 chair.png create mode 100644 table.png diff --git a/cafe.tmx b/cafe.tmx index a62be9e..520c7a2 100644 --- a/cafe.tmx +++ b/cafe.tmx @@ -7,24 +7,24 @@ 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6, -7,8,10,10,8,8,8,10,10,8,8,8,10,10,8,8,8,10,8,12, -13,10,16,17,10,8,10,16,17,10,8,10,16,17,10,8,10,9,10,18, -13,8,10,10,8,8,8,10,10,8,8,8,10,10,8,8,8,10,8,18, 7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, -7,8,10,8,8,10,8,8,10,8,8,10,8,8,10,8,8,10,8,12, -7,8,9,8,8,9,8,8,9,8,8,9,8,8,9,8,8,9,8,12, -7,8,10,8,8,10,8,8,10,8,8,10,8,8,10,8,8,10,8,12, 13,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,18, 13,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,18, 7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, 7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, -7,8,10,8,8,8,10,8,8,8,8,8,8,10,8,8,8,10,8,12, -7,10,9,10,8,10,9,10,8,8,8,8,10,9,10,8,10,9,10,12, -7,8,10,8,8,8,10,8,8,8,8,8,8,10,8,8,8,10,8,12, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, 13,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,18, -13,8,10,8,8,8,10,8,8,8,8,8,8,10,8,8,8,10,8,18, -7,10,9,10,8,10,9,10,8,8,8,8,10,9,10,8,10,9,10,12, -7,8,10,8,8,8,10,8,8,8,8,8,8,10,8,8,8,10,8,12, +13,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,18, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, +13,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,18, +13,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,18, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, +7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,12, 25,27,27,27,27,27,27,27,27,28,29,27,27,27,27,27,27,27,27,30 diff --git a/chair.png b/chair.png new file mode 100644 index 0000000000000000000000000000000000000000..3839841f9f2a0a966731b67aad6be5daf2ea40e8 GIT binary patch literal 2129 zcmbVN2~ZPP7+wM>mjYG19oMB)6q4O+LPAzjt{}${L_Q^g5wwVC z@u*V4s>OPYPA%4Jv<0guYMDWtdMgSFGI&6xqoQ_Hy5WdU$5y91^Y*=c?|a{W|681# z6g$LYj0XS!L*nB!DZ&iehua|G&E@7k5hizY+#C)7B>wi{WZM~@0|2f8bZR=Eu1&-U z)+E76R!2!}CbNJBfUt0z87B-B59+84no&cKs*Xb-O{$^UAzDOhj;1o{xLgZ0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m&fo-@o7T!qLWzV_yz+ zeDUF)rcVa?$}hGj^!{`q662OC=kBlD{c?7D+&h`Tr7Je_{9oQZpRskxoxzz=6A$bd zzOiP_zOVMY5?9-sd%Jl6-a2o~zGJsu=8cVmtNVsGFTGH||4fY97}c@!NW-i5M%FcC z-gWaShgKmoPTUF<&&c)n|j2YVa`;Mo5vBx)*Uw^4# z$GYCzbWQ87#J^puK4Exy=%csh3kQo z88`b5sk}AIcA?ilFLoHVoEBzuFV6Y;RNfmymM=WN0u_53Qq@bo-9b;E^&9QiMJu;0 z{MTv& AasU7T literal 0 HcmV?d00001 diff --git a/tiles.py b/tiles.py index 0eb1dfc..e370e7b 100644 --- a/tiles.py +++ b/tiles.py @@ -1,37 +1,107 @@ +import numpy as np import pygame import pytmx pygame.init() -display = pygame.display.set_mode((640,640)) +display = pygame.display.set_mode((640, 640)) clock = pygame.time.Clock() - gameMap = pytmx.load_pygame("cafe.tmx") - waiterImg = pygame.image.load("waiter.png") -waiterX = 50 -waiterY = 300 +tableImg = pygame.image.load('table.png') +chairImg = pygame.image.load('chair.png') -def waiter(): - display.blit(waiterImg, (waiterX, waiterY)) -while(True): +def pos_of_chair(table_cor, k): + pos = ((table_cor[0], table_cor[1] - 32), + (table_cor[0], table_cor[1] + 32), + (table_cor[0] - 32, table_cor[1]), + (table_cor[0] + 32, table_cor[1])) + return pos[k] - clock.tick(60) + +class Waiter: + def __init__(self, loc): + self.loc = loc + + def render(self, surface): + surface.blit(waiterImg, (self.loc[0], self.loc[1])) + + def handle_events(self): + key = pygame.key.get_pressed() + if key[pygame.K_w] or key[pygame.K_UP]: + self.loc[1] -= 32 + elif key[pygame.K_s] or key[pygame.K_DOWN]: + self.loc[1] += 32 + elif key[pygame.K_a] or key[pygame.K_LEFT]: + self.loc[0] -= 32 + elif key[pygame.K_d] or key[pygame.K_RIGHT]: + self.loc[0] += 32 + + +class Table: + def __init__(self, loc, num): + self.loc = loc + self.number = num + self.num_of_chairs = np.random.randint(1, 5) + + def render(self, surface): + surface.blit(tableImg, (self.loc[0], self.loc[1])) + + def get_number(self): + return self.number + + def get_number_of_chairs(self): + return self.num_of_chairs + + +class Chair: + def __init__(self, loc): + self.loc = loc + + def render(self, surface): + surface.blit(chairImg, (self.loc[0], self.loc[1])) + + +waiter = Waiter([64, 320]) +tables = [] +chairs = [] +tables_coordinates = ((32 * 3, 32 * 2), (32 * 7, 32 * 2), (32 * 12, 32 * 2), (32 * 16, 32 * 2), + (32 * 3, 32 * 6), (32 * 7, 32 * 6), (32 * 12, 32 * 6), (32 * 16, 32 * 6), + (32 * 3, 32 * 13), (32 * 7, 32 * 13), (32 * 12, 32 * 13), (32 * 16, 32 * 13), + (32 * 3, 32 * 17), (32 * 7, 32 * 17), (32 * 12, 32 * 17), (32 * 16, 32 * 17)) +for i in range(16): + tables.append(Table(tables_coordinates[i], i)) + arr = [] + for j in range(0, tables[i].get_number_of_chairs()): + 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): + if event.type == pygame.QUIT: quit() - if(keys[pygame.K_ESCAPE]): + 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 != None): - display.blit(tile, (x * gameMap.tilewidth, y * gameMap.tileheight)) + 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() - pygame.display.update() \ No newline at end of file + waiter.handle_events() + + for table in tables: + table.render(display) + for chair_list in chairs: + for chair in chair_list: + chair.render(display) + + waiter.render(display) + pygame.display.update()