feat(tile_type): randomly assign each tile a vegetable at init

This commit is contained in:
Wojciech Kubicki 2024-03-25 01:27:20 +01:00
parent eaaac9f277
commit 8ce604df46

View File

@ -1,6 +1,9 @@
import os import os
import pygame import pygame
from dotenv import find_dotenv, load_dotenv from dotenv import find_dotenv, load_dotenv
from kb import tractor_kb
import pytholog as pl
import random
class Tile(pygame.sprite.Sprite): class Tile(pygame.sprite.Sprite):
def __init__(self, id, type, field): def __init__(self, id, type, field):
@ -8,9 +11,13 @@ class Tile(pygame.sprite.Sprite):
self.id = id self.id = id
x = id%16 x = id%16
y = id//16 y = id//16
vegetable_types = tractor_kb.query(pl.Expr("warzywo(X)"))
random_vegetable = vegetable_types[random.randint(0, len(vegetable_types)-1)]['X']
self.type = type self.type = type
self.field = field self.field = field
self.set_type(type) self.set_type(random_vegetable)
self.rect = self.image.get_rect() self.rect = self.image.get_rect()
# you can set TILE_SIZE in the .env file to adjust the window size # you can set TILE_SIZE in the .env file to adjust the window size
load_dotenv(find_dotenv()) load_dotenv(find_dotenv())
@ -22,8 +29,10 @@ class Tile(pygame.sprite.Sprite):
def set_type(self, type): def set_type(self, type):
self.type = type self.type = type
if self.type == 'grass': # if self.type == 'grass':
self.image = pygame.image.load("images/grass.png").convert() # self.image = pygame.image.load("images/grass.png").convert()
self.image = pygame.image.load("images/grass.png").convert()
# you can set TILE_SIZE in the .env file to adjust the window size # you can set TILE_SIZE in the .env file to adjust the window size
load_dotenv(find_dotenv()) load_dotenv(find_dotenv())
TILE_SIZE = int(os.getenv("TILE_SIZE")) TILE_SIZE = int(os.getenv("TILE_SIZE"))