feat: enable setting starting coords and direction from .env

This commit is contained in:
Wojciech Kubicki 2024-04-29 15:32:52 +02:00
parent c6b61e8f69
commit f85f5b4cdc
3 changed files with 21 additions and 9 deletions

View File

@ -14,17 +14,23 @@ Stwórz plik `.env` w głównym folderze projektu o poniższej treści:
``` ```
# window size # window size
TILE_SIZE=64 TILE_SIZE = 32
# game speed # 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 # coordinates of destination tile
FINAL_X=15 FINAL_X = 15
FINAL_Y=15 FINAL_Y = 15
# tiles without plants modifier # tiles without plants modifier
FREE_TILES=2 FREE_TILES = 2
``` ```
Uruchom środowisko używając komend: Uruchom środowisko używając komend:

View File

@ -9,6 +9,12 @@ TILE_SIZE = int(os.getenv("TILE_SIZE"))
# game speed # game speed
TICK_RATE = int(os.getenv("TICK_RATE")) 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 # coordinates of destination tile
FINAL_X = int(os.getenv("FINAL_X")) FINAL_X = int(os.getenv("FINAL_X"))
FINAL_Y = int(os.getenv("FINAL_Y")) FINAL_Y = int(os.getenv("FINAL_Y"))

View File

@ -2,7 +2,7 @@ import pygame
import os import os
from kb import ile_podlac, multi_sasiedzi from kb import ile_podlac, multi_sasiedzi
from tile import Tile 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 from collections import deque
import heapq import heapq
import random import random
@ -16,12 +16,12 @@ class Tractor(pygame.sprite.Sprite):
self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE)) self.image = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
self.direction = 'east' self.direction = STARTING_DIRECTION
# TODO: enable tractor to start on other tile than (0,0) # 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) self.final = (FINAL_X, FINAL_Y)
print('destination @', self.final[0], self.final[1]) 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 self.water = 50