From 968013d375e8ee74f73751eb3c9cfaeb19c008a1 Mon Sep 17 00:00:00 2001 From: v7eZ3t Date: Mon, 29 Mar 2021 02:53:27 +0200 Subject: [PATCH] v. 1.12 --- Field.py | 3 ++- constants.py | 14 ++++++++------ drawUI.py | 3 ++- driving.py | 6 +++--- main.py | 18 +++++++++++++----- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Field.py b/Field.py index 4162935..6194dd6 100644 --- a/Field.py +++ b/Field.py @@ -10,4 +10,5 @@ class Field: @state.setter def state(self, state): - self.__state = state + if state == 0 or state == 1 or state == 2 or state == 3 or state == 4: + self.__state = state diff --git a/constants.py b/constants.py index c78d8dc..3e0ccf4 100644 --- a/constants.py +++ b/constants.py @@ -1,15 +1,17 @@ #constants # display size in pixels -DISPLAY_SIZE_HORIZONTAL = 600 -DISPLAY_SIZE_VERTICAL = 600 +from math import ceil + +DISPLAY_SIZE_HORIZONTAL = 1600 +DISPLAY_SIZE_VERTICAL = 900 #TILE DIVIDER = TILE SIZE -TILE_SIZE = 30 +TILE_SIZE = 100 # number of tiles -HORIZONTAL_TILES_NUMBER = DISPLAY_SIZE_HORIZONTAL/TILE_SIZE -VERTICAL_TILES_NUMBER = DISPLAY_SIZE_VERTICAL/TILE_SIZE +HORIZONTAL_TILES_NUMBER = ceil(DISPLAY_SIZE_HORIZONTAL/TILE_SIZE) +VERTICAL_TILES_NUMBER = ceil(DISPLAY_SIZE_VERTICAL/TILE_SIZE) #TILE_SIZE @@ -27,7 +29,7 @@ TRACTOR_WIDTH = TILE_SIZE TRACTOR_HEIGHT = TILE_SIZE #FRAMES PER SECOND -FPS = 5 +FPS = 100 diff --git a/drawUI.py b/drawUI.py index f7febce..2551bd1 100644 --- a/drawUI.py +++ b/drawUI.py @@ -39,6 +39,7 @@ def drawTractor(screen: pygame.Surface, tractor_horizontal_index, tractor_vertic screen.blit(tractor_down, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE)) elif direction == "LEFT": screen.blit(tractor_left, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE)) - elif direction == "RIGHT": screen.blit(tractor_right, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE)) + else: + screen.blit(tractor_right, (tractor_horizontal_index * TILE_SIZE, tractor_vertical_index * TILE_SIZE)) diff --git a/driving.py b/driving.py index 95808d6..1f47f8f 100644 --- a/driving.py +++ b/driving.py @@ -6,9 +6,9 @@ def cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor_hor if not cruiseControl: horizontal_change = 0 vertical_change = 0 - if tractor_horizontal_index < 1 or tractor_horizontal_index >= HORIZONTAL_TILES_NUMBER - 1: + if tractor_horizontal_index <= 0 or tractor_horizontal_index >= HORIZONTAL_TILES_NUMBER - 1: horizontal_change = 0 - if tractor_vertical_index < 1 or tractor_vertical_index >= VERTICAL_TILES_NUMBER - 1: + if tractor_vertical_index <= 0 or tractor_vertical_index >= VERTICAL_TILES_NUMBER - 1: vertical_change = 0 return horizontal_change, vertical_change @@ -32,7 +32,7 @@ def manualTurning(event, tractor_horizontal_index, tractor_vertical_index, horiz def getDirection(horizontal_change, vertical_change): - direction = "NO" + direction = "STOP" if vertical_change == -1: direction = "UP" elif vertical_change == 1: diff --git a/main.py b/main.py index beec347..68ff90d 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,7 @@ pygame.display.set_caption('Tractor') working = True cruiseControl = True +lastDirection = "RIGHT" horizontal_change = 0 vertical_change = 0 @@ -33,15 +34,22 @@ while working: horizontal_change, vertical_change = driving.manualTurning(event, tractor.horizontal_index, tractor.vertical_index, horizontal_change, vertical_change) - - tractor.horizontal_index += horizontal_change - tractor.vertical_index += vertical_change + #todo usunąć /10 + tractor.horizontal_index += horizontal_change/10 + tractor.vertical_index += vertical_change/10 horizontal_change, vertical_change = driving.cruiseControl(cruiseControl, horizontal_change, vertical_change, tractor.horizontal_index, tractor.vertical_index) - drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index, - driving.getDirection(horizontal_change, vertical_change)) + direction = driving.getDirection(horizontal_change, vertical_change) + + if direction != "STOP": + lastDirection = direction + drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index, + direction) + else: + drawUI.drawUI(board, display, tractor.horizontal_index, tractor.vertical_index, + lastDirection) clock.tick(FPS)