90 lines
2.1 KiB
Python
90 lines
2.1 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)
|
||
|
|
||
|
print("assets/fields/" + field_string + "/" + self.name + ".jpg")
|
||
|
img = pygame.image.load("./assets/fields/" + field_string + "/" + self.name + ".jpg")
|
||
|
print(img)
|
||
|
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:
|
||
|
type = Type.SPECIAL
|
||
|
name = 'cobble'
|
||
|
|
||
|
def __init__(self):
|
||
|
self.tile = Tile(self.name, self.type)
|
||
|
self.block = Block(self.name + "_block", self.type)
|
||
|
|
||
|
|
||
|
class Grass:
|
||
|
type = Type.DEFAULT
|
||
|
name = 'grass'
|
||
|
|
||
|
def __init__(self):
|
||
|
self.tile = Tile(self.name, self.type)
|
||
|
self.block = Block(self.name + "_block", self.type)
|
||
|
|
||
|
# DIRT_IMG = pygame.image.load("assets/fields/plant/dirt.jpg")
|
||
|
# DIRT = pygame.transform.scale(DIRT_IMG, (50, 50))
|
||
|
# DIRT_BLOCK_IMG = pygame.image.load("assets/fields/plant/dirt_block.jpg")
|
||
|
# DIRT_BLOCK = pygame.transform.scale(DIRT_BLOCK_IMG, (800, 800))
|