diff --git a/Board.py b/Main/Board.py similarity index 100% rename from Board.py rename to Main/Board.py diff --git a/Field.py b/Main/Field.py similarity index 100% rename from Field.py rename to Main/Field.py diff --git a/Tractor.py b/Main/Tractor.py similarity index 100% rename from Tractor.py rename to Main/Tractor.py diff --git a/constants.py b/Main/constants.py similarity index 100% rename from constants.py rename to Main/constants.py diff --git a/Main/drawUI.py b/Main/drawUI.py new file mode 100644 index 0000000..8d9f443 --- /dev/null +++ b/Main/drawUI.py @@ -0,0 +1,36 @@ +from Main.constants import * +from Main.images import * +import pygame + + +def drawUI(board, display, tractor_horizontal_index, tractor_vertical_index): + display.fill(WHITE) + makeField(board, display) + drawTractor(display, tractor_right, tractor_horizontal_index, tractor_vertical_index) + pygame.display.update() + + +def makeField(board, screen: pygame.Surface): + for i in range(int(HORIZONTAL_TILES_NUMBER)): + for j in range(int(VERTICAL_TILES_NUMBER)): + field = board[i][j] + + pos_x = i * TILE_SIZE + TILE_SIZE // 2 + pos_y = j * TILE_SIZE + TILE_SIZE // 2 + + if field.state == 0: + do_podlania_rect.center = (pos_x, pos_y) + screen.blit(do_podlania, do_podlania_rect) + elif field.state == 1: + do_zaorania_rect.center = (pos_x, pos_y) + screen.blit(do_zaorania, do_zaorania_rect) + elif field.state == 2: + do_zasiania_rect.center = (pos_x, pos_y) + screen.blit(do_zasiania, do_zasiania_rect) + elif field.state == 3: + do_zebrania_rect.center = (pos_x, pos_y) + screen.blit(do_zebrania, do_zebrania_rect) + + +def drawTractor(screen: pygame.Surface, tractor_image, tractor_horizontal_index, tractor_vertical_index): + screen.blit(tractor_image, (tractor_horizontal_index * TILE_SIZE,tractor_vertical_index * TILE_SIZE)) diff --git a/driving.py b/Main/driving.py similarity index 97% rename from driving.py rename to Main/driving.py index f0d8c0a..8df5380 100644 --- a/driving.py +++ b/Main/driving.py @@ -1,7 +1,6 @@ -from Main.constants import * +from Main.drawUI import * import pygame - def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_horizontal_index, tractor_vertical_index): if not cruiseControl: horizontal_change = 0 @@ -18,6 +17,7 @@ def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horiz if event.key == pygame.K_LEFT and tractor_horizontal_index > 0: vertical_change = 0 horizontal_change = -1 + elif event.key == pygame.K_RIGHT and tractor_horizontal_index < HORIZONTAL_TILES_NUMBER - 1: horizontal_change = 1 vertical_change = 0 diff --git a/Main/images.py b/Main/images.py new file mode 100644 index 0000000..85ad395 --- /dev/null +++ b/Main/images.py @@ -0,0 +1,35 @@ +import pygame +from constants import * + +tractor_up_image = pygame.image.load("resources/traktor_up.png") +tractor_up = pygame.transform.scale(tractor_up_image, (TILE_SIZE, TILE_SIZE)) + +tractor_right_image = pygame.image.load("resources/traktor_right.png") +tractor_right = pygame.transform.scale(tractor_right_image, (TILE_SIZE, TILE_SIZE)) + +tractor_down_image = pygame.image.load("resources/traktor_down.png") +tractor_down = pygame.transform.scale(tractor_down_image, (TILE_SIZE, TILE_SIZE)) + +tractor_left_image = pygame.image.load("resources/traktor_left.png") +tractor_left = pygame.transform.scale(tractor_left_image, (TILE_SIZE, TILE_SIZE)) + +do_podlania_image = pygame.image.load("resources/do_podlania.png") +do_podlania = pygame.transform.scale(do_podlania_image, (TILE_SIZE, TILE_SIZE)) + +do_zaorania_image = pygame.image.load("resources/do_zaorania.png") +do_zaorania = pygame.transform.scale(do_zaorania_image, (TILE_SIZE, TILE_SIZE)) + +do_zasiania_image = pygame.image.load("resources/do_zasiania.png") +do_zasiania = pygame.transform.scale(do_zasiania_image, (TILE_SIZE, TILE_SIZE)) + +do_zebrania_image = pygame.image.load("resources/do_zebrania.png") +do_zebrania = pygame.transform.scale(do_zebrania_image, (TILE_SIZE, TILE_SIZE)) + +tractor_up_rect = tractor_up.get_rect() +tractor_right_rect = tractor_right.get_rect() +tractor_down_rect = tractor_down.get_rect() +tractor_left_rect = tractor_left.get_rect() +do_podlania_rect = do_podlania.get_rect() +do_zaorania_rect = do_zaorania.get_rect() +do_zasiania_rect = do_zasiania.get_rect() +do_zebrania_rect = do_zebrania.get_rect() \ No newline at end of file diff --git a/main.py b/Main/main.py similarity index 100% rename from main.py rename to Main/main.py diff --git a/Main/resources/do_podlania.png b/Main/resources/do_podlania.png new file mode 100644 index 0000000..73b8da9 Binary files /dev/null and b/Main/resources/do_podlania.png differ diff --git a/Main/resources/do_zaorania.png b/Main/resources/do_zaorania.png new file mode 100644 index 0000000..d987cd1 Binary files /dev/null and b/Main/resources/do_zaorania.png differ diff --git a/Main/resources/do_zasiania.png b/Main/resources/do_zasiania.png new file mode 100644 index 0000000..d64e76f Binary files /dev/null and b/Main/resources/do_zasiania.png differ diff --git a/Main/resources/do_zebrania.png b/Main/resources/do_zebrania.png new file mode 100644 index 0000000..ebc7a8e Binary files /dev/null and b/Main/resources/do_zebrania.png differ diff --git a/Main/resources/traktor_down.png b/Main/resources/traktor_down.png new file mode 100644 index 0000000..7a63149 Binary files /dev/null and b/Main/resources/traktor_down.png differ diff --git a/Main/resources/traktor_left.png b/Main/resources/traktor_left.png new file mode 100644 index 0000000..449e2ad Binary files /dev/null and b/Main/resources/traktor_left.png differ diff --git a/Main/resources/traktor_right.png b/Main/resources/traktor_right.png new file mode 100644 index 0000000..615378b Binary files /dev/null and b/Main/resources/traktor_right.png differ diff --git a/Main/resources/traktor_up.png b/Main/resources/traktor_up.png new file mode 100644 index 0000000..1a2af5a Binary files /dev/null and b/Main/resources/traktor_up.png differ diff --git a/drawUI.py b/drawUI.py deleted file mode 100644 index 128068e..0000000 --- a/drawUI.py +++ /dev/null @@ -1,35 +0,0 @@ -from Main.constants import * -import pygame - - -def drawUI(board, display, tractor_horizontal_index, tractor_vertical_index): - display.fill(WHITE) - makeField(board, display) - drawTractor(display, tractor_horizontal_index, tractor_vertical_index) - pygame.display.update() - - -def makeField(board, display): - color = BLACK - for i in range(int(HORIZONTAL_TILES_NUMBER)): - for j in range(int(VERTICAL_TILES_NUMBER)): - field = board[i][j] - - if field.state == 0: - color = WHITE - elif field.state == 1: - color = RED - elif field.state == 2: - color = YELLOW - elif field.state == 3: - color = GREEN - elif field.state == 4: - color = BLACK - pygame.draw.rect(display, color, - [i * TILE_SIZE, j * TILE_SIZE, TILE_SIZE, TILE_SIZE]) - - -def drawTractor(display, tractor_horizontal_index, tractor_vertical_index): - pygame.draw.rect(display, BLACK, - [tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE, TRACTOR_WIDTH, - TRACTOR_HEIGHT])