From 12ecd02a2714c397860e6b5af5b4a4c90984225d Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 00:36:09 +0200 Subject: [PATCH 01/10] Matrix of objects (class Tile) --- src/main.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.py b/src/main.py index 0dcd5e4..d2f1175 100644 --- a/src/main.py +++ b/src/main.py @@ -27,6 +27,12 @@ class Waiter(pygame.sprite.Sprite): screen.blit(self.imageWaiter, (self.moveX * block_size, self.moveY * block_size)) +# TILE +class Tile: + x_position = 0 + y_position = 0 + + # SETUP pygame.init() screen = pygame.display.set_mode((700, 750)) @@ -40,6 +46,7 @@ rect = 1 floor = pygame.image.load('../resources/images/floor.jpg') table = pygame.image.load('../resources/images/table.png') waiter = pygame.image.load('../resources/images/waiter.png') +matrix = [] def drawBackground(): @@ -48,11 +55,23 @@ def drawBackground(): screen.blit(floor, (x * block_size, y * block_size)) +def matrix_creator(): + for y in range(15): + matrix.append([0] * 14) + + for y in range(15): + for x in range(14): + matrix[y][x] = Tile() + matrix[y][x].x_position = x + matrix[y][x].y_position = y + + waiterPly = Waiter() def main(): drawBackground() + matrix_creator() while not done: for event in pygame.event.get(): From a206b3709c01de8004380c2df2bf1f2961cf8938 Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 15:47:08 +0200 Subject: [PATCH 02/10] Small improvements (matrix notation, prep to clear) --- src/main.py => main.py | 25 +++++++++++-------------- src/tile.py | 1 + src/waiter.py | 0 3 files changed, 12 insertions(+), 14 deletions(-) rename src/main.py => main.py (86%) create mode 100644 src/tile.py create mode 100644 src/waiter.py diff --git a/src/main.py b/main.py similarity index 86% rename from src/main.py rename to main.py index d2f1175..b0f4a48 100644 --- a/src/main.py +++ b/main.py @@ -29,8 +29,9 @@ class Waiter(pygame.sprite.Sprite): # TILE class Tile: - x_position = 0 - y_position = 0 + def __init__(self): + self.x_position = 0 + self.y_position = 0 # SETUP @@ -56,20 +57,19 @@ def drawBackground(): def matrix_creator(): - for y in range(15): - matrix.append([0] * 14) + for x in range(14): + matrix.append([0] * 15) - for y in range(15): - for x in range(14): - matrix[y][x] = Tile() - matrix[y][x].x_position = x - matrix[y][x].y_position = y + for x in range(14): + for y in range(15): + matrix[x][y] = Tile() + matrix[x][y].x_position = x + matrix[x][y].y_position = y waiterPly = Waiter() - -def main(): +if __name__ == "__main__": drawBackground() matrix_creator() @@ -94,6 +94,3 @@ def main(): waiterPly.update() pygame.display.flip() clock.tick(fps) - - -main() diff --git a/src/tile.py b/src/tile.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/tile.py @@ -0,0 +1 @@ + diff --git a/src/waiter.py b/src/waiter.py new file mode 100644 index 0000000..e69de29 From 8b1ce733547dac199ee87700d1190ffe395ea3dc Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 16:32:24 +0200 Subject: [PATCH 03/10] Class Table added --- main.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index b0f4a48..7500040 100644 --- a/main.py +++ b/main.py @@ -29,9 +29,19 @@ class Waiter(pygame.sprite.Sprite): # TILE class Tile: - def __init__(self): - self.x_position = 0 - self.y_position = 0 + def __init__(self, x_position, y_position): + self.x_position = x_position + self.y_position = y_position + self.watch_through = 1 + self.walk_through = 1 + self.action_required = 0 + + +# TABLE +class Table(Tile): + def __init__(self, x_position, y_position): + super().__init__(x_position, y_position) + self.walk_through = 0 # SETUP @@ -62,9 +72,7 @@ def matrix_creator(): for x in range(14): for y in range(15): - matrix[x][y] = Tile() - matrix[x][y].x_position = x - matrix[x][y].y_position = y + matrix[x][y] = Tile(x, y) waiterPly = Waiter() @@ -94,3 +102,7 @@ if __name__ == "__main__": waiterPly.update() pygame.display.flip() clock.tick(fps) + + # # Testy funkcjonalne + # matrix[0][0] = Table(0, 0) + # print(matrix[0][0].walk_through, matrix[1][0].walk_through) From b06e38232261fd51883a269e04d9693a140e5aa3 Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 18:49:47 +0200 Subject: [PATCH 04/10] File division, Class Matrix, Waiter, Graphics All graphics in Graphics (draw, clear, update) Waiter movement moved to Waiter Main reduced to minimum --- main.py | 125 +++++++++++------------------------------------- src/graphics.py | 23 +++++++++ src/matrix.py | 15 ++++++ src/tile.py | 8 +++- src/waiter.py | 33 +++++++++++++ 5 files changed, 107 insertions(+), 97 deletions(-) create mode 100644 src/graphics.py create mode 100644 src/matrix.py diff --git a/main.py b/main.py index 7500040..4269adf 100644 --- a/main.py +++ b/main.py @@ -1,108 +1,41 @@ import sys -import pygame +from src.graphics import * +from src.matrix import Matrix +from src.waiter import Waiter -# WAITER -class Waiter(pygame.sprite.Sprite): - def __init__(self): - pygame.sprite.Sprite.__init__(self) - self.moveX = 0 - self.moveY = 0 - self.clearX = 0 - self.clearY = 0 - self.frame = 0 - self.imageWaiter = waiter - self.imageFloor = floor - - def move(self, x, y): - self.moveX += x - self.moveY -= y - - def clear(self, x, y): - cx = self.moveX + x - cy = self.moveY + y - screen.blit(self.imageFloor, (cx * block_size, cy * block_size)) - - def update(self): - screen.blit(self.imageWaiter, (self.moveX * block_size, self.moveY * block_size)) - - -# TILE -class Tile: - def __init__(self, x_position, y_position): - self.x_position = x_position - self.y_position = y_position - self.watch_through = 1 - self.walk_through = 1 - self.action_required = 0 - - -# TABLE -class Table(Tile): - def __init__(self, x_position, y_position): - super().__init__(x_position, y_position) - self.walk_through = 0 - - -# SETUP -pygame.init() -screen = pygame.display.set_mode((700, 750)) -done = False -block_size = 50 -clock = pygame.time.Clock() -fps = 40 -ani = 40 -rect = 1 - -floor = pygame.image.load('../resources/images/floor.jpg') -table = pygame.image.load('../resources/images/table.png') -waiter = pygame.image.load('../resources/images/waiter.png') -matrix = [] - - -def drawBackground(): - for y in range(15): - for x in range(14): - screen.blit(floor, (x * block_size, y * block_size)) - - -def matrix_creator(): - for x in range(14): - matrix.append([0] * 15) - - for x in range(14): - for y in range(15): - matrix[x][y] = Tile(x, y) - - -waiterPly = Waiter() - if __name__ == "__main__": - drawBackground() - matrix_creator() + # SETUP + pygame.init() + clock = pygame.time.Clock() + fps = 40 + # matrix = [] + waiterPly = Waiter() + graphics = Graphics() - while not done: + # init functions + graphics.drawBackground() + graphics.update(waiterPly.moveX, waiterPly.moveY) + + # matrix_creator() + + matrix = Matrix() + + while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() + break + if event.type == pygame.KEYDOWN: - if event.key == pygame.K_LEFT: - waiterPly.move(-rect, 0) - waiterPly.clear(rect, 0) - if event.key == pygame.K_RIGHT: - waiterPly.move(rect, 0) - waiterPly.clear(-rect, 0) - if event.key == pygame.K_UP: - waiterPly.move(0, rect) - waiterPly.clear(0, rect) - if event.key == pygame.K_DOWN: - waiterPly.move(0, -rect) - waiterPly.clear(0, -rect) - waiterPly.update() + if event.key == pygame.K_ESCAPE: + pygame.quit() + sys.exit() + break + + graphics.clear(waiterPly.moveX, waiterPly.moveY) + waiterPly.update(event) + graphics.update(waiterPly.moveX, waiterPly.moveY) pygame.display.flip() clock.tick(fps) - - # # Testy funkcjonalne - # matrix[0][0] = Table(0, 0) - # print(matrix[0][0].walk_through, matrix[1][0].walk_through) diff --git a/src/graphics.py b/src/graphics.py new file mode 100644 index 0000000..0f1ba76 --- /dev/null +++ b/src/graphics.py @@ -0,0 +1,23 @@ +import pygame + + +class Graphics: + def __init__(self): + self.image = { + 'floor': pygame.image.load('../resources/images/floor.jpg'), + 'table': pygame.image.load('../resources/images/table.png'), + 'waiter': pygame.image.load('../resources/images/waiter.png'), + } + self.screen = pygame.display.set_mode((700, 750)) + self.block_size = 50 + + def drawBackground(self): + for y in range(15): + for x in range(14): + self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) + + def clear(self, x, y): + self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) + + def update(self, x, y): + self.screen.blit(self.image['waiter'], (x * self.block_size, y * self.block_size)) diff --git a/src/matrix.py b/src/matrix.py new file mode 100644 index 0000000..2a7f36d --- /dev/null +++ b/src/matrix.py @@ -0,0 +1,15 @@ +from src.tile import Tile + + +class Matrix: + def __init__(self): + self.matrix = [] + for x in range(14): + self.matrix.append([0] * 15) + + for x in range(14): + for y in range(15): + self.matrix[x][y] = Tile(type_='floor', watch_through=1) + + def get_name(self, x, y): + return self.matrix[x][y].type diff --git a/src/tile.py b/src/tile.py index 8b13789..c63e8aa 100644 --- a/src/tile.py +++ b/src/tile.py @@ -1 +1,7 @@ - +# TILE +class Tile: + def __init__(self, type_, watch_through): + self.watch_through = watch_through + self.walk_through = 1 + self.action_required = 0 + self.type = type_ diff --git a/src/waiter.py b/src/waiter.py index e69de29..e1de286 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -0,0 +1,33 @@ +import pygame + +screen = pygame.display.set_mode((700, 750)) +block_size = 50 + + +# WAITER +class Waiter(pygame.sprite.Sprite): + def __init__(self): + pygame.sprite.Sprite.__init__(self) + self.moveX = 0 + self.moveY = 0 + self.clearX = 0 + self.clearY = 0 + self.frame = 0 + + #Borders + def move(self, x, y): + if 0 <= self.moveX + x <= 14: + self.moveX += x + if 0 <= self.moveY + y <= 15: + self.moveY += y + + def update(self, event): + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + self.move(-1, 0) + if event.key == pygame.K_RIGHT: + self.move(1, 0) + if event.key == pygame.K_UP: + self.move(0, -1) + if event.key == pygame.K_DOWN: + self.move(0, 1) From 431dadacbc58a8d7cb818e37d029db4a8dabd4d6 Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 20:15:07 +0200 Subject: [PATCH 05/10] Matrix implemented to waiter --- main.py | 18 ++++++------------ src/graphics.py | 4 ++-- src/matrix.py | 7 ++++++- src/waiter.py | 22 ++++++++++------------ 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/main.py b/main.py index 4269adf..1c5ff22 100644 --- a/main.py +++ b/main.py @@ -3,23 +3,17 @@ from src.graphics import * from src.matrix import Matrix from src.waiter import Waiter - if __name__ == "__main__": # SETUP pygame.init() clock = pygame.time.Clock() fps = 40 - # matrix = [] - waiterPly = Waiter() + waiter = Waiter() graphics = Graphics() # init functions - graphics.drawBackground() - graphics.update(waiterPly.moveX, waiterPly.moveY) - - # matrix_creator() - - matrix = Matrix() + graphics.drawBackground(waiter.matrix) + graphics.update(waiter.X, waiter.Y) while True: for event in pygame.event.get(): @@ -34,8 +28,8 @@ if __name__ == "__main__": sys.exit() break - graphics.clear(waiterPly.moveX, waiterPly.moveY) - waiterPly.update(event) - graphics.update(waiterPly.moveX, waiterPly.moveY) + graphics.clear(waiter.X, waiter.Y) + waiter.update(event) + graphics.update(waiter.X, waiter.Y) pygame.display.flip() clock.tick(fps) diff --git a/src/graphics.py b/src/graphics.py index 0f1ba76..9369b74 100644 --- a/src/graphics.py +++ b/src/graphics.py @@ -11,10 +11,10 @@ class Graphics: self.screen = pygame.display.set_mode((700, 750)) self.block_size = 50 - def drawBackground(self): + def drawBackground(self, matrix): for y in range(15): for x in range(14): - self.screen.blit(self.image['floor'], (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): self.screen.blit(self.image['floor'], (x * self.block_size, y * self.block_size)) diff --git a/src/matrix.py b/src/matrix.py index 2a7f36d..bedfffe 100644 --- a/src/matrix.py +++ b/src/matrix.py @@ -10,6 +10,11 @@ class Matrix: for x in range(14): for y in range(15): self.matrix[x][y] = Tile(type_='floor', watch_through=1) + self.matrix[1][0].type = 'waiter' + self.matrix[1][0].walk_through = 0 - def get_name(self, x, y): + def get_type(self, x, y): return self.matrix[x][y].type + + def walk_through(self, x, y): + return self.matrix[x][y].walk_through diff --git a/src/waiter.py b/src/waiter.py index e1de286..ccb53c6 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -1,25 +1,23 @@ import pygame - -screen = pygame.display.set_mode((700, 750)) -block_size = 50 +from src.matrix import Matrix # WAITER class Waiter(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) - self.moveX = 0 - self.moveY = 0 - self.clearX = 0 - self.clearY = 0 + self.X = 0 + self.Y = 0 self.frame = 0 + self.matrix = Matrix() - #Borders + # Borders def move(self, x, y): - if 0 <= self.moveX + x <= 14: - self.moveX += x - if 0 <= self.moveY + y <= 15: - self.moveY += y + if self.matrix.walk_through(self.X + x, self.Y + y) == 1: + if 0 <= self.X + x <= 14: + self.X += x + if 0 <= self.Y + y <= 15: + self.Y += y def update(self, event): if event.type == pygame.KEYDOWN: From d2114e1ba629242a436f34fa7533efa983a3df15 Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 20:19:19 +0200 Subject: [PATCH 06/10] bugfix --- src/waiter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/waiter.py b/src/waiter.py index ccb53c6..b576242 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -14,9 +14,9 @@ class Waiter(pygame.sprite.Sprite): # Borders def move(self, x, y): if self.matrix.walk_through(self.X + x, self.Y + y) == 1: - if 0 <= self.X + x <= 14: + if 0 <= self.X + x < 14: self.X += x - if 0 <= self.Y + y <= 15: + if 0 <= self.Y + y < 15: self.Y += y def update(self, event): From 8b2ff2527c279f6c3c2a19f693f0d9b8fe47d35a Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 20:24:05 +0200 Subject: [PATCH 07/10] bugfix --- src/waiter.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/waiter.py b/src/waiter.py index b576242..c1a5abc 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -13,10 +13,11 @@ class Waiter(pygame.sprite.Sprite): # Borders def move(self, x, y): - if self.matrix.walk_through(self.X + x, self.Y + y) == 1: - if 0 <= self.X + x < 14: + if 0 <= self.X + x <= 13: + if self.matrix.walk_through(self.X, self.Y) == 1: self.X += x - if 0 <= self.Y + y < 15: + if 0 <= self.Y + y <= 14: + if self.matrix.walk_through(self.X, self.Y) == 1: self.Y += y def update(self, event): From 2573d37d1adf6d9d6fdcfc8a1c5f9bb402597e76 Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 20:37:46 +0200 Subject: [PATCH 08/10] bugfix Waiter out of matrix --- src/waiter.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/waiter.py b/src/waiter.py index c1a5abc..faf2715 100644 --- a/src/waiter.py +++ b/src/waiter.py @@ -13,11 +13,9 @@ class Waiter(pygame.sprite.Sprite): # Borders def move(self, x, y): - if 0 <= self.X + x <= 13: - if self.matrix.walk_through(self.X, self.Y) == 1: + if 0 <= self.X + x <= 13 and 0 <= self.Y + y <= 14: + if self.matrix.walk_through(self.X + x, self.Y + y) == 1: self.X += x - if 0 <= self.Y + y <= 14: - if self.matrix.walk_through(self.X, self.Y) == 1: self.Y += y def update(self, event): From dbcf1005f3aa21f8f9c74342d0b0bffe5e2fc5f5 Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 20:44:27 +0200 Subject: [PATCH 09/10] bugfix of last bugfix (didn't work) --- main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/main.py b/main.py index 1c5ff22..b8f8927 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,5 @@ import sys from src.graphics import * -from src.matrix import Matrix from src.waiter import Waiter if __name__ == "__main__": From 80410b843877b7faaad17816fd290dcb7bdeb4f5 Mon Sep 17 00:00:00 2001 From: s444427 Date: Fri, 3 Apr 2020 21:27:42 +0200 Subject: [PATCH 10/10] graphics of table, double render --- resources/images/table2.png | Bin 0 -> 876 bytes resources/images/table3.png | Bin 0 -> 1057 bytes src/graphics.py | 10 +++++++++- src/matrix.py | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 resources/images/table2.png create mode 100644 resources/images/table3.png diff --git a/resources/images/table2.png b/resources/images/table2.png new file mode 100644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