Madra_smieciarka/classes/Tileset.py

31 lines
923 B
Python
Raw Normal View History

2024-03-25 00:05:56 +01:00
import pygame
class Tileset:
def __init__(self, file, mult, margin=1, spacing=1):
2024-03-25 00:05:56 +01:00
self.file = file
self.size = (mult, mult)
2024-03-25 00:05:56 +01:00
self.margin = margin
self.spacing = spacing
self.image = pygame.image.load(file)
self.image = pygame.transform.scale(self.image, self.size)
2024-03-25 00:05:56 +01:00
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}'