Trashmaster/mapa.py

28 lines
842 B
Python
Raw Permalink Normal View History

2022-03-25 11:54:32 +01:00
import pygame as pg
import pytmx
class TiledMap:
2022-04-07 19:40:39 +02:00
# loading file
2022-03-25 11:54:32 +01:00
def __init__(self, filename):
tm = pytmx.load_pygame(filename, pixelalpha=True)
self.width = tm.width * tm.tilewidth
self.height = tm.height * tm.tileheight
self.tmxdata = tm
2022-04-07 19:40:39 +02:00
# rendering map
2022-03-25 11:54:32 +01:00
def render(self, surface):
ti = self.tmxdata.get_tile_image_by_gid
for layer in self.tmxdata.visible_layers:
if isinstance(layer, pytmx.TiledTileLayer):
for x, y, gid, in layer:
tile = ti(gid)
if tile:
surface.blit(tile, (x * self.tmxdata.tilewidth, y * self.tmxdata.tilewidth))
2022-04-07 19:40:39 +02:00
2022-03-25 11:54:32 +01:00
def make_map(self):
temp_surface = pg.Surface((self.width, self.height))
self.render(temp_surface)
2022-04-07 19:40:39 +02:00
return temp_surface