diff --git a/.gitignore b/.gitignore index fa8bd9d..53151b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -VENV \ No newline at end of file +VENV +env +**/__pycache__ +.vscode +*.swp diff --git a/DataModels/GC.py b/DataModels/GC.py index dd45707..ec52007 100644 --- a/DataModels/GC.py +++ b/DataModels/GC.py @@ -1,5 +1,6 @@ from DataModels.Cell import Cell from DataModels.Road import Road +from config import GRID_WIDTH, GRID_HEIGHT class GC(Cell): @@ -9,10 +10,11 @@ class GC(Cell): def move(self, direction, environment): x, y = [self.x, self.y] movement = { - "right": (x + 1, y) if environment[x + 1][y] == Road else (x, y), - "left": (x - 1, y) if environment[x - 1][y] == Road else (x, y), - "up": (x, y + 1) if environment[x][y + 1] == Road else (x, y), - "down": (x, y - 1) if environment[x][y - 1] == Road else (x, y) + "right": (x + 1, y) if x + 1 < GRID_WIDTH and type(environment[x + 1][y]) == Road else (x, y), + "left": (x - 1, y) if x - 1 >= 0 and type(environment[x - 1][y]) == Road else (x, y), + "down": (x, y + 1) if y + 1 < GRID_HEIGHT and type(environment[x][y + 1]) == Road else (x, y), + "up": (x, y - 1) if y - 1 >= 0 and type(environment[x][y - 1]) == Road else (x, y) } self.x, self.y = movement[direction] print(self.x, self.y) + self.update_rect(self.x, self.y) diff --git a/DataModels/__pycache__/Cell.cpython-36.pyc b/DataModels/__pycache__/Cell.cpython-36.pyc deleted file mode 100644 index 186a46b..0000000 Binary files a/DataModels/__pycache__/Cell.cpython-36.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Cell.cpython-37.pyc b/DataModels/__pycache__/Cell.cpython-37.pyc deleted file mode 100644 index 38ad71a..0000000 Binary files a/DataModels/__pycache__/Cell.cpython-37.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Container.cpython-36.pyc b/DataModels/__pycache__/Container.cpython-36.pyc deleted file mode 100644 index 391e59b..0000000 Binary files a/DataModels/__pycache__/Container.cpython-36.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Container.cpython-37.pyc b/DataModels/__pycache__/Container.cpython-37.pyc deleted file mode 100644 index 52884c2..0000000 Binary files a/DataModels/__pycache__/Container.cpython-37.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Dump.cpython-36.pyc b/DataModels/__pycache__/Dump.cpython-36.pyc deleted file mode 100644 index ed8d52a..0000000 Binary files a/DataModels/__pycache__/Dump.cpython-36.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Dump.cpython-37.pyc b/DataModels/__pycache__/Dump.cpython-37.pyc deleted file mode 100644 index 619f4a5..0000000 Binary files a/DataModels/__pycache__/Dump.cpython-37.pyc and /dev/null differ diff --git a/DataModels/__pycache__/GC.cpython-36.pyc b/DataModels/__pycache__/GC.cpython-36.pyc deleted file mode 100644 index c3ac277..0000000 Binary files a/DataModels/__pycache__/GC.cpython-36.pyc and /dev/null differ diff --git a/DataModels/__pycache__/GC.cpython-37.pyc b/DataModels/__pycache__/GC.cpython-37.pyc deleted file mode 100644 index 714ffe8..0000000 Binary files a/DataModels/__pycache__/GC.cpython-37.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Grass.cpython-36.pyc b/DataModels/__pycache__/Grass.cpython-36.pyc deleted file mode 100644 index e0e9c67..0000000 Binary files a/DataModels/__pycache__/Grass.cpython-36.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Grass.cpython-37.pyc b/DataModels/__pycache__/Grass.cpython-37.pyc deleted file mode 100644 index b1f90a1..0000000 Binary files a/DataModels/__pycache__/Grass.cpython-37.pyc and /dev/null differ diff --git a/DataModels/__pycache__/House.cpython-36.pyc b/DataModels/__pycache__/House.cpython-36.pyc deleted file mode 100644 index c33f300..0000000 Binary files a/DataModels/__pycache__/House.cpython-36.pyc and /dev/null differ diff --git a/DataModels/__pycache__/House.cpython-37.pyc b/DataModels/__pycache__/House.cpython-37.pyc deleted file mode 100644 index 8c95180..0000000 Binary files a/DataModels/__pycache__/House.cpython-37.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Road.cpython-36.pyc b/DataModels/__pycache__/Road.cpython-36.pyc deleted file mode 100644 index db9525c..0000000 Binary files a/DataModels/__pycache__/Road.cpython-36.pyc and /dev/null differ diff --git a/DataModels/__pycache__/Road.cpython-37.pyc b/DataModels/__pycache__/Road.cpython-37.pyc deleted file mode 100644 index f32e8bc..0000000 Binary files a/DataModels/__pycache__/Road.cpython-37.pyc and /dev/null differ diff --git a/Resources/Maps/map_001.txt b/Resources/Maps/map_001.txt index 4333db7..4c03fdc 100644 --- a/Resources/Maps/map_001.txt +++ b/Resources/Maps/map_001.txt @@ -1,4 +1,5 @@ 9 9 +2 1 E E E H E E E E E E Y R R E H E E E E R E R E R E G E @@ -8,4 +9,3 @@ R R R R R E R R E E B R H E R R H E E E R R R R E E E E E E E H R R R H -3 1 diff --git a/Resources/Maps/map_002.txt b/Resources/Maps/map_002.txt index 19807a0..f55bca5 100644 --- a/Resources/Maps/map_002.txt +++ b/Resources/Maps/map_002.txt @@ -1,6 +1,7 @@ 6 5 +1 0 Y R R R E H E R E R R R H R B R H R E R R R R G -E H E E R H \ No newline at end of file +E H E E R H diff --git a/Resources/Maps/map_003.txt b/Resources/Maps/map_003.txt index b5f82f9..5f24c00 100644 --- a/Resources/Maps/map_003.txt +++ b/Resources/Maps/map_003.txt @@ -1,5 +1,6 @@ 13 4 +3 0 E Y R R R H H R R R E E E H R R H R R R R H R R H E E E R E H E R H R E R R G -H R R E E B R R R H E R H \ No newline at end of file +H R R E E B R R R H E R H diff --git a/Resources/Maps/map_004.txt b/Resources/Maps/map_004.txt index 01a932b..2627a89 100644 --- a/Resources/Maps/map_004.txt +++ b/Resources/Maps/map_004.txt @@ -1,4 +1,5 @@ 12 10 +1 0 Y R R R E H R R R R R E E R E R R E R E H E R H H R R H R R R R R R R E diff --git a/__pycache__/config.cpython-36.pyc b/__pycache__/config.cpython-36.pyc deleted file mode 100644 index b9af045..0000000 Binary files a/__pycache__/config.cpython-36.pyc and /dev/null differ diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc deleted file mode 100644 index b73b88f..0000000 Binary files a/__pycache__/config.cpython-37.pyc and /dev/null differ diff --git a/config.py b/config.py index d34b059..0b315ab 100644 --- a/config.py +++ b/config.py @@ -4,7 +4,9 @@ CELL_SIZE = 64 FPS = 60 map = open( sys.argv[1], 'r' ) + GRID_WIDTH, GRID_HEIGHT = [int(x) for x in map.readline().split()] +GC_X, GC_Y = [int(x) for x in map.readline().split()] WINDOW_HEIGHT = GRID_HEIGHT * CELL_SIZE WINDOW_WIDTH = GRID_WIDTH * CELL_SIZE diff --git a/main.py b/main.py index fe18c6b..5c6999d 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import pygame import sys from random import randint -from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS +from config import WINDOW_HEIGHT, WINDOW_WIDTH, GRID_HEIGHT, GRID_WIDTH, HOUSE_CAPACITY, FPS, GC_X, GC_Y from DataModels.Grass import Grass from DataModels.House import House @@ -17,6 +17,7 @@ GAME_WINDOW = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), 0, 32) map = open(sys.argv[1], 'r') map.readline() +map.readline() map_objects = [[None for y in range(0, GRID_WIDTH)] for x in range(0, GRID_HEIGHT)] @@ -37,8 +38,9 @@ def generate(letter): i = 0 for y in map.readlines(): for x in y.split(): - x_coord = i % GRID_WIDTH - y_coord = i // GRID_WIDTH + + y_coord = i % GRID_WIDTH + x_coord = (i - y_coord)//GRID_WIDTH yellow, green, blue = [randint(0, HOUSE_CAPACITY // 2), randint( 0, HOUSE_CAPACITY // 2), randint(0, HOUSE_CAPACITY // 2)] @@ -69,8 +71,9 @@ for line in map_objects: for item in line: pygame_sprites.add(item) -gc = GC(0, 0, 10) -pygame_sprites.add() +gc = GC(GC_X, GC_Y, 2) +print("GC: " + str(GC_X) + str(GC_Y)) +pygame_sprites.add(gc) while True: