forked from seanmcortes/delve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.py
More file actions
31 lines (28 loc) · 1.04 KB
/
map.py
File metadata and controls
31 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pygame
import pytmx
from settings import *
"""
This class creates the Tiled maps. It is used with the .tmx files created in the
third-party Tiled program
"""
class TiledMap:
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
self.image = self.make_map()
self.rect = self.image.get_rect()
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.tileheight))
def make_map(self):
temp_surface = pygame.Surface((self.width, self.height))
self.render(temp_surface)
return temp_surface