SzybciorSmartTraktor/field.py
Emil Gutkiewicz ac32a5e0b7 added plants
2022-03-25 06:52:06 +01:00

108 lines
2.2 KiB
Python

from enum import Enum
import pygame
import settings
import plant
class Type(Enum):
DEFAULT = 0
PLANT = 1
SPECIAL = 2
@staticmethod
def get_string(_type):
return {
Type.DEFAULT: 'default',
Type.PLANT: 'plant',
Type.SPECIAL: 'special',
}[_type]
# Field Types START
class FieldType:
def __init__(self):
self.field = None
self.plowed = False
def plow(self):
self.plowed = True
def sow(self, seed: plant.Seeds):
if self.plowed:
self.field = plant.Seeds.seed_to_plant(seed)
class Object:
height = width = 0
name = 'default'
type = Type.DEFAULT
def create(self):
field_string = Type.get_string(self.type)
img = pygame.image.load("./assets/fields/" + field_string + "/" + self.name + ".jpg")
return pygame.transform.scale(img, (self.width, self.height))
class Tile(Object):
def __init__(self, name: str, _type: Type):
self.name = name
self.type = _type
self.width = self.height = settings.Field.size()
self.object = self.create()
class Block(Object):
def __init__(self, name: str, _type: Type):
self.name = name
self.type = _type
self.width = settings.Pygame.width()
self.height = settings.Pygame.height()
self.object = self.create()
class Field:
type = Type.DEFAULT
name = 'default'
def __init__(self):
self.tile = Tile(self.name, self.type)
self.block = Block(self.name + "_block", self.type)
self.field_type = FieldType()
def can_be_sown(self):
return self.type == Type.DEFAULT
# Tile Types START
class Dirt(Field):
type = Type.PLANT
name = 'dirt'
def __init__(self):
super(Dirt, self).__init__()
class Cobble(Field):
type = Type.SPECIAL
name = 'cobble'
def __init__(self):
super(Cobble, self).__init__()
class Grass(Field):
type = Type.DEFAULT
name = 'grass'
def __init__(self):
super(Grass, self).__init__()
class Sand(Field):
type = Type.DEFAULT
name = 'sand'
def __init__(self):
super(Sand, self).__init__()
# Tile Types END