From f85f5b4cdcc094291a226dc348a6f38fa2ab8dbc Mon Sep 17 00:00:00 2001 From: Wojciech Kubicki Date: Mon, 29 Apr 2024 15:32:52 +0200 Subject: [PATCH] feat: enable setting starting coords and direction from .env --- README.md | 16 +++++++++++----- src/config.py | 6 ++++++ src/tractor.py | 8 ++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 876bdd77..5c271f0d 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,23 @@ Stwórz plik `.env` w głównym folderze projektu o poniższej treści: ``` # window size -TILE_SIZE=64 +TILE_SIZE = 32 # game speed -TICK_RATE=10 +TICK_RATE = 10 + +STARTING_DIRECTION = north + +# coordinates of initial tile +START_X = 0 +START_Y = 0 # coordinates of destination tile -FINAL_X=15 -FINAL_Y=15 +FINAL_X = 15 +FINAL_Y = 15 # tiles without plants modifier -FREE_TILES=2 +FREE_TILES = 2 ``` Uruchom środowisko używając komend: diff --git a/src/config.py b/src/config.py index 55d7c9d8..a61ab38f 100644 --- a/src/config.py +++ b/src/config.py @@ -9,6 +9,12 @@ TILE_SIZE = int(os.getenv("TILE_SIZE")) # game speed TICK_RATE = int(os.getenv("TICK_RATE")) +STARTING_DIRECTION = str(os.getenv("STARTING_DIRECTION")) + +# coordinates of initial tile +START_X = int(os.getenv("START_X")) +START_Y = int(os.getenv("START_Y")) + # coordinates of destination tile FINAL_X = int(os.getenv("FINAL_X")) FINAL_Y = int(os.getenv("FINAL_Y")) diff --git a/src/tractor.py b/src/tractor.py index 5291d943..af58d461 100644 --- a/src/tractor.py +++ b/src/tractor.py @@ -2,7 +2,7 @@ import pygame import os from kb import ile_podlac, multi_sasiedzi from tile import Tile -from config import TILE_SIZE, FINAL_X, FINAL_Y +from config import TILE_SIZE, FINAL_X, FINAL_Y, START_X, START_Y, STARTING_DIRECTION from collections import deque import heapq import random @@ -16,12 +16,12 @@ class Tractor(pygame.sprite.Sprite): self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE)) self.rect = self.image.get_rect() - self.direction = 'east' + self.direction = STARTING_DIRECTION # TODO: enable tractor to start on other tile than (0,0) - self.start = (0, 0) + self.start = (START_X, START_Y) self.final = (FINAL_X, FINAL_Y) print('destination @', self.final[0], self.final[1]) - self.rect.topleft = (0, 0) + self.rect.topleft = (self.start[0] * TILE_SIZE, self.start[1] * TILE_SIZE) self.water = 50