-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
46 lines (39 loc) · 1.36 KB
/
data.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from bs4 import BeautifulSoup
from constants import *
from drawables import Tile
def load_map(filename, layr, resize=None, collidable=True, extra_groups=[]):
f = open(MAP_DIR + filename, "r")
soup = BeautifulSoup(f, "xml")
f.close()
gerps = [all_sprites_list, tile_sprites_list] + extra_groups
mwidth = soup.map.layer['width']
mheight = soup.map.layer['height']
twidth = int(soup.map.tileset["tilewidth"])
theight = int(soup.map.tileset["tileheight"])
tsetwidth = int(soup.map.tileset.image['width']) / twidth
tsetheight = int(soup.map.tileset.image['height']) / theight
map_csv = None
map_csv =soup.map.find(attrs={'name' : layr}).data.string.split(',')
x = 0;
y = 0;
if not map_csv:
print "No Layer with name: %s" % layr
exit(0)
else:
pass
for num in map_csv:
px = int(x) % int(mwidth)
py = int(x) / int(mwidth)
tx = (int(num) - 1) % tsetwidth
ty = (int(num) - 1) / tsetheight
x += 1
if int(num) == 0:
continue
tile = Tile("TestTiles.png",
x=px, y=py,
w=twidth, h=theight,
tx=tx, ty=ty,
resize=resize,
groups=gerps)
if not collidable:
tile.collidable = False