-
Notifications
You must be signed in to change notification settings - Fork 0
/
world.py
36 lines (24 loc) · 929 Bytes
/
world.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
_world = {}
starting_position = (0,0)
def tile_exists(x,y):
"""
Returns the Tile at the given coordinates, or None
if there is no tile
:param x: the x coordinate of the tile
:param y: the y coordinate of the tile
:return: the tile at the given coordinates or none if none
"""
return world.get((x,y))
def load_tiles():
"""Parses a file that describes a world space into the world object"""
with open('resources/map.txt', 'r') as f:
rows = f.readlines()
x_max = len(rows[0].split('\t'))
for y in range(len(rows)):
cols = rows[y].split('\t')
for x in range(x_max):
tile_name = cols[x].replace('\n', '')
if tile_name == 'StartingRoom':
global starting_position
starting_position = (x,y)
_world[(x,y)] = None if tile_name == '' else getattr(__import__('tiles'), tile_name)(x,y)