Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f60679cd08 | ||
|
84abac95e7 | ||
74dd8fac0b | |||
37a34e22fb | |||
7660f83334 |
12
main.py
12
main.py
@ -1,18 +1,20 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from src.graphics import *
|
from src.graphics import *
|
||||||
from src.waiter import Waiter
|
from src.waiter import *
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# SETUP
|
# SETUP
|
||||||
pygame.init()
|
pygame.init()
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
fps = 40
|
fps = 40
|
||||||
waiter = Waiter()
|
|
||||||
graphics = Graphics()
|
graphics = Graphics()
|
||||||
|
waiter = Waiter(graphics)
|
||||||
|
direction = 0
|
||||||
|
|
||||||
# init functions
|
# init functions
|
||||||
graphics.drawBackground(waiter.matrix)
|
graphics.drawBackground(waiter.matrix)
|
||||||
graphics.update(waiter.X, waiter.Y)
|
graphics.update(waiter.X, waiter.Y, waiter.direction)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@ -28,7 +30,7 @@ if __name__ == "__main__":
|
|||||||
break
|
break
|
||||||
|
|
||||||
graphics.clear(waiter.X, waiter.Y)
|
graphics.clear(waiter.X, waiter.Y)
|
||||||
waiter.update(event)
|
waiter.update(event, graphics, direction)
|
||||||
graphics.update(waiter.X, waiter.Y)
|
graphics.update(waiter.X, waiter.Y, waiter.direction)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(fps)
|
clock.tick(fps)
|
||||||
|
BIN
resources/images/waiter-down.png
Normal file
BIN
resources/images/waiter-down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
resources/images/waiter-left.png
Normal file
BIN
resources/images/waiter-left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
resources/images/waiter-right.png
Normal file
BIN
resources/images/waiter-right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
resources/images/waiter-up.png
Normal file
BIN
resources/images/waiter-up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
15
resources/simulations/simulation_1.txt
Normal file
15
resources/simulations/simulation_1.txt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
______________
|
||||||
|
______________
|
||||||
|
__KW_____KW___
|
||||||
|
_KSWK___KSWK__
|
||||||
|
__KWSK___KWSK_
|
||||||
|
__KWK____KWK__
|
||||||
|
_KSW____KSW___
|
||||||
|
__KWK____KWK__
|
||||||
|
__KWSK___KWSK_
|
||||||
|
_KSWK___KSWK__
|
||||||
|
__KW_____KW___
|
||||||
|
______________
|
||||||
|
______________
|
||||||
|
BBBBB_________
|
||||||
|
FFFFB_________
|
8
resources/simulations/simulation_2.txt
Normal file
8
resources/simulations/simulation_2.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
X___TXFX
|
||||||
|
T_X_X__X
|
||||||
|
X_X_X_XX
|
||||||
|
T_X____T
|
||||||
|
X_X_XX_X
|
||||||
|
X_X____T
|
||||||
|
T_X_XXXX
|
||||||
|
XXX____W
|
2
resources/simulations/simulation_3.txt
Normal file
2
resources/simulations/simulation_3.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
__X
|
||||||
|
___
|
BIN
src/__pycache__/graphics.cpython-37.pyc
Normal file
BIN
src/__pycache__/graphics.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/matrix.cpython-37.pyc
Normal file
BIN
src/__pycache__/matrix.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/tile.cpython-37.pyc
Normal file
BIN
src/__pycache__/tile.cpython-37.pyc
Normal file
Binary file not shown.
BIN
src/__pycache__/waiter.cpython-37.pyc
Normal file
BIN
src/__pycache__/waiter.cpython-37.pyc
Normal file
Binary file not shown.
@ -5,27 +5,46 @@ class Graphics:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.image = {
|
self.image = {
|
||||||
'floor': pygame.image.load('../resources/images/floor.jpg'),
|
'floor': pygame.image.load('../resources/images/floor.jpg'),
|
||||||
'table': pygame.image.load('../resources/images/table.png'),
|
'wall': pygame.image.load('../resources/images/table3.png'), #
|
||||||
|
'bar': pygame.image.load('../resources/images/table3.png'), #
|
||||||
|
'bar_floor': pygame.image.load('../resources/images/waiter.png'), #
|
||||||
|
'table': pygame.image.load('../resources/images/table3.png'),
|
||||||
'waiter': pygame.image.load('../resources/images/waiter.png'),
|
'waiter': pygame.image.load('../resources/images/waiter.png'),
|
||||||
|
'waiter-down': pygame.image.load('../resources/images/waiter-down.png'),
|
||||||
|
'waiter-left': pygame.image.load('../resources/images/waiter-left.png'),
|
||||||
|
'waiter-right': pygame.image.load('../resources/images/waiter-right.png'),
|
||||||
|
'waiter-up': pygame.image.load('../resources/images/waiter-up.png'),
|
||||||
'table2': pygame.image.load('../resources/images/table2.png'),
|
'table2': pygame.image.load('../resources/images/table2.png'),
|
||||||
'table3': pygame.image.load('../resources/images/table3.png')
|
'table3': pygame.image.load('../resources/images/table3.png'),
|
||||||
|
'chair': pygame.image.load('../resources/images/waiter.png'),
|
||||||
|
'chair_up': pygame.image.load('../resources/images/table3.png'), #
|
||||||
|
'chair_down': pygame.image.load('../resources/images/table3.png'), #
|
||||||
|
'chair_left': pygame.image.load('../resources/images/table3.png'), #
|
||||||
|
'chair_right': pygame.image.load('../resources/images/table3.png') #
|
||||||
}
|
}
|
||||||
self.block_size = 50
|
self.block_size = 50
|
||||||
self.height = 15
|
self.height = 15
|
||||||
self.width = 14
|
self.width: int = 14
|
||||||
self.screen = pygame.display.set_mode((self.block_size*self.width, self.block_size*self.height))
|
self.screen = pygame.display.set_mode((self.block_size * self.width, self.block_size * self.height))
|
||||||
|
|
||||||
def drawBackground(self, matrix):
|
def drawBackground(self, matrix):
|
||||||
for y in range(15):
|
for y in range(self.height):
|
||||||
for x in range(14):
|
for x in range(self.width):
|
||||||
self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size))
|
self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size))
|
||||||
|
|
||||||
for y in range(15):
|
for y in range(self.height):
|
||||||
for x in range(14):
|
for x in range(self.width):
|
||||||
self.screen.blit(self.image[matrix.get_type(x, y)], (x * self.block_size, y * self.block_size))
|
self.screen.blit(self.image[matrix.get_type(x, y)], (x * self.block_size, y * self.block_size))
|
||||||
|
|
||||||
def clear(self, x, y):
|
def clear(self, x, y):
|
||||||
self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size))
|
self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size))
|
||||||
|
|
||||||
def update(self, x, y):
|
def update(self, x, y, direction):
|
||||||
self.screen.blit(self.image['waiter'], (x * self.block_size, y * self.block_size))
|
if direction == 1:
|
||||||
|
self.screen.blit(self.image['waiter-up'], (x * self.block_size, y * self.block_size))
|
||||||
|
if direction == 2:
|
||||||
|
self.screen.blit(self.image['waiter-right'], (x * self.block_size, y * self.block_size))
|
||||||
|
if direction == 3:
|
||||||
|
self.screen.blit(self.image['waiter-down'], (x * self.block_size, y * self.block_size))
|
||||||
|
if direction == 4:
|
||||||
|
self.screen.blit(self.image['waiter-left'], (x * self.block_size, y * self.block_size))
|
||||||
|
@ -2,19 +2,41 @@ from src.tile import Tile
|
|||||||
|
|
||||||
|
|
||||||
class Matrix:
|
class Matrix:
|
||||||
def __init__(self):
|
def __init__(self, graphics):
|
||||||
self.matrix = []
|
self.matrix = []
|
||||||
for x in range(14):
|
self.set_default_matrix(graphics)
|
||||||
self.matrix.append([0] * 15)
|
self.set_default_restaurant(graphics)
|
||||||
|
|
||||||
for x in range(14):
|
def set_default_matrix(self, graphics):
|
||||||
for y in range(15):
|
for x in range(graphics.width):
|
||||||
self.matrix[x][y] = Tile(type_='floor', watch_through=1)
|
self.matrix.append([0] * graphics.height)
|
||||||
self.matrix[1][0].type = 'table3'
|
|
||||||
self.matrix[1][0].walk_through = 0
|
for x in range(graphics.width):
|
||||||
|
for y in range(graphics.height):
|
||||||
|
self.matrix[x][y] = Tile(type_='floor')
|
||||||
|
|
||||||
|
def set_default_restaurant(self, graphics):
|
||||||
|
lines = [line.rstrip('\n') for line in open('../resources/simulations/simulation_1.txt')]
|
||||||
|
symbols = {
|
||||||
|
'_': 'floor',
|
||||||
|
'W': 'wall',
|
||||||
|
'S': 'table',
|
||||||
|
'B': 'bar',
|
||||||
|
'F': 'bar_floor',
|
||||||
|
'K': 'chair',
|
||||||
|
'X': 'waiter'
|
||||||
|
}
|
||||||
|
|
||||||
|
for x in range(graphics.width):
|
||||||
|
for y in range(graphics.height):
|
||||||
|
sign = lines[y][x]
|
||||||
|
self.matrix[x][y] = Tile(symbols[sign])
|
||||||
|
|
||||||
def get_type(self, x, y):
|
def get_type(self, x, y):
|
||||||
return self.matrix[x][y].type
|
return self.matrix[x][y].type
|
||||||
|
|
||||||
def walk_through(self, x, y):
|
def walk_through(self, x, y):
|
||||||
return self.matrix[x][y].walk_through
|
return self.matrix[x][y].walk_through
|
||||||
|
|
||||||
|
def watch_through(self, x, y):
|
||||||
|
return self.matrix[x][y].watch_through
|
||||||
|
18
src/tile.py
18
src/tile.py
@ -1,7 +1,17 @@
|
|||||||
# TILE
|
# TILE
|
||||||
class Tile:
|
class Tile:
|
||||||
def __init__(self, type_, watch_through):
|
def __init__(self, type_):
|
||||||
self.watch_through = watch_through
|
|
||||||
self.walk_through = 1
|
|
||||||
self.action_required = 0
|
|
||||||
self.type = type_
|
self.type = type_
|
||||||
|
|
||||||
|
if self.type == 'wall':
|
||||||
|
self.watch_through = 0
|
||||||
|
self.walk_through = 0
|
||||||
|
elif self.type == 'table' or self.type == 'bar' or self.type == 'chair':
|
||||||
|
self.watch_through = 1
|
||||||
|
self.walk_through = 0
|
||||||
|
else:
|
||||||
|
self.walk_through = 1
|
||||||
|
self.watch_through = 1
|
||||||
|
|
||||||
|
self.action_required = 0
|
||||||
|
|
||||||
|
@ -1,30 +1,53 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
from src.matrix import Matrix
|
from src.matrix import Matrix
|
||||||
|
|
||||||
|
|
||||||
# WAITER
|
# WAITER
|
||||||
class Waiter(pygame.sprite.Sprite):
|
class Waiter(pygame.sprite.Sprite):
|
||||||
def __init__(self):
|
def __init__(self, graphics):
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.X = 0
|
self.X = 0
|
||||||
self.Y = 0
|
self.Y = 0
|
||||||
|
self.direction = 2
|
||||||
self.frame = 0
|
self.frame = 0
|
||||||
self.matrix = Matrix()
|
self.matrix = Matrix(graphics=graphics)
|
||||||
|
|
||||||
# Borders
|
# Borders
|
||||||
def move(self, x, y):
|
def move(self, x, y, graphics):
|
||||||
if 0 <= self.X + x <= 13 and 0 <= self.Y + y <= 14:
|
if 0 <= self.X + x <= graphics.width - 1 and 0 <= self.Y + y <= graphics.height - 1:
|
||||||
if self.matrix.walk_through(self.X + x, self.Y + y) == 1:
|
if self.matrix.walk_through(self.X + x, self.Y + y) == 1:
|
||||||
self.X += x
|
self.X += x
|
||||||
self.Y += y
|
self.Y += y
|
||||||
|
|
||||||
def update(self, event):
|
def arrow(self, direction):
|
||||||
|
self.direction = direction
|
||||||
|
|
||||||
|
def update(self, event, graphics, direction):
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_LEFT:
|
if event.key == pygame.K_LEFT:
|
||||||
self.move(-1, 0)
|
self.arrow(4)
|
||||||
|
#self.move(-1, 0, graphics)
|
||||||
if event.key == pygame.K_RIGHT:
|
if event.key == pygame.K_RIGHT:
|
||||||
self.move(1, 0)
|
self.arrow(2)
|
||||||
|
#self.move(1, 0, graphics)
|
||||||
if event.key == pygame.K_UP:
|
if event.key == pygame.K_UP:
|
||||||
self.move(0, -1)
|
self.arrow(1)
|
||||||
|
#self.move(0, -1, graphics)
|
||||||
if event.key == pygame.K_DOWN:
|
if event.key == pygame.K_DOWN:
|
||||||
self.move(0, 1)
|
self.arrow(3)
|
||||||
|
#self.move(0, 1, graphics)
|
||||||
|
if event.key == pygame.K_SPACE:
|
||||||
|
#up
|
||||||
|
if self.direction == 1:
|
||||||
|
self.move(0, -1, graphics)
|
||||||
|
#righ
|
||||||
|
if self.direction == 2:
|
||||||
|
self.move(1, 0, graphics)
|
||||||
|
#down
|
||||||
|
if self.direction == 3:
|
||||||
|
self.move(0, 1, graphics)
|
||||||
|
#left
|
||||||
|
if self.direction == 4:
|
||||||
|
self.move(-1, 0, graphics)
|
||||||
|
print(self.X, self.Y)
|
||||||
|
Loading…
Reference in New Issue
Block a user