feat: store constants in .env for easier adjustments during presentations

This commit is contained in:
Wojciech Kubicki 2024-04-27 20:37:12 +02:00
parent 4d9fda66e8
commit c6b61e8f69
5 changed files with 29 additions and 9 deletions

View File

@ -13,8 +13,18 @@ pip install pytholog
Stwórz plik `.env` w głównym folderze projektu o poniższej treści: Stwórz plik `.env` w głównym folderze projektu o poniższej treści:
``` ```
# adjust TILE_SIZE to fit your screen well # window size
TILE_SIZE=64 TILE_SIZE=64
# game speed
TICK_RATE=10
# coordinates of destination tile
FINAL_X=15
FINAL_Y=15
# tiles without plants modifier
FREE_TILES=2
``` ```
Uruchom środowisko używając komend: Uruchom środowisko używając komend:

View File

@ -1,6 +1,16 @@
import os import os
from dotenv import find_dotenv, load_dotenv from dotenv import find_dotenv, load_dotenv
# you can set TILE_SIZE in the .env file to adjust the window size
load_dotenv(find_dotenv()) load_dotenv(find_dotenv())
# window size
TILE_SIZE = int(os.getenv("TILE_SIZE")) TILE_SIZE = int(os.getenv("TILE_SIZE"))
# game speed
TICK_RATE = int(os.getenv("TICK_RATE"))
# coordinates of destination tile
FINAL_X = int(os.getenv("FINAL_X"))
FINAL_Y = int(os.getenv("FINAL_Y"))
FREE_TILES = int(os.getenv("FREE_TILES"))

View File

@ -2,7 +2,7 @@ import sys
import pygame import pygame
from field import Field from field import Field
import os import os
from config import TILE_SIZE from config import TILE_SIZE, TICK_RATE
if __name__ == "__main__": if __name__ == "__main__":
pygame.init() pygame.init()
@ -24,4 +24,4 @@ if __name__ == "__main__":
field.draw(screen) field.draw(screen)
pygame.display.flip() pygame.display.flip()
pygame.time.Clock().tick(10) pygame.time.Clock().tick(TICK_RATE)

View File

@ -3,7 +3,7 @@ import pygame
from kb import tractor_kb from kb import tractor_kb
import pytholog as pl import pytholog as pl
import random import random
from config import TILE_SIZE from config import TILE_SIZE, FREE_TILES
class Tile(pygame.sprite.Sprite): class Tile(pygame.sprite.Sprite):
@ -16,7 +16,7 @@ class Tile(pygame.sprite.Sprite):
self.field = field self.field = field
# temporary solution to have vegetables act as obstacles # temporary solution to have vegetables act as obstacles
if random.randint(1, 10) % 3 == 0: if random.randint(1, 10) % FREE_TILES == 0:
vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)")) vegetables = tractor_kb.query(pl.Expr("warzywo(Nazwa_warzywa)"))
random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa'] random_vegetable = vegetables[random.randint(0, len(vegetables)-1)]['Nazwa_warzywa']
self.set_type(random_vegetable) self.set_type(random_vegetable)

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 from config import TILE_SIZE, FINAL_X, FINAL_Y
from collections import deque from collections import deque
import heapq import heapq
import random import random
@ -19,8 +19,8 @@ class Tractor(pygame.sprite.Sprite):
self.direction = 'east' self.direction = 'east'
# 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 = (0, 0)
self.final = (8, 14) self.final = (FINAL_X, FINAL_Y)
print('final target @', self.final[0], self.final[1]) print('destination @', self.final[0], self.final[1])
self.rect.topleft = (0, 0) self.rect.topleft = (0, 0)
self.water = 50 self.water = 50