SzybciorSmartTraktor/field.py
2022-03-11 03:34:20 +01:00

88 lines
1.8 KiB
Python

from enum import Enum
import pygame
import settings
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]
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)
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__()