2ce075c29f
Signed-off-by: Neerka <kuba.markil0220@gmail.com>
31 lines
923 B
Python
31 lines
923 B
Python
import pygame
|
|
|
|
|
|
class Tileset:
|
|
|
|
def __init__(self, file, mult, margin=1, spacing=1):
|
|
self.file = file
|
|
self.size = (mult, mult)
|
|
self.margin = margin
|
|
self.spacing = spacing
|
|
self.image = pygame.image.load(file)
|
|
self.image = pygame.transform.scale(self.image, self.size)
|
|
self.rect = self.image.get_rect()
|
|
self.tiles = []
|
|
self.load()
|
|
|
|
def load(self):
|
|
self.tiles = []
|
|
x0 = y0 = self.margin
|
|
w, h = self.rect.size
|
|
dx = self.size[0] + self.spacing
|
|
dy = self.size[1] + self.spacing
|
|
for x in range(x0, w, dx):
|
|
for y in range(y0, h, dy):
|
|
tile = pygame.Surface(self.size)
|
|
tile.blit(self.image, (0, 0), (x, y, *self.size))
|
|
self.tiles.append(tile)
|
|
|
|
def __str__(self):
|
|
return f'{self.__class__.__name__} file:{self.file} tile:{self.size}'
|