Prześlij pliki do ''
This commit is contained in:
parent
c59836e549
commit
919c4ca04c
24
cafe.tmx
24
cafe.tmx
@ -7,24 +7,24 @@
|
||||
<layer id="1" name="Warstwa Kafelków 1" width="20" height="20">
|
||||
<data encoding="csv">
|
||||
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
|
||||
</data>
|
||||
</layer>
|
||||
|
104
tiles.py
104
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()
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user