Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- map_content = [ #each dict will be called 'tile_dict'
- {'type': 'Stone', 'symbol': "[]"},
- {'type': 'Air', 'symbol': "O"},
- {'type': 'Grass', 'symbol': "_"},
- {'type': 'Dirt', 'symbol': "*", 'generation': [(2,2),(3,2),(2,3),(4,4),(2,1),(2,2)],'rarity': 50},
- {'type': 'Coal', 'symbol': "5", 'generation': [(1,0),(0,1),(1,1),(1,2),(2,1),(2,2)],'rarity': 10},
- {'type': 'Iron', 'symbol': "Fe", 'generation': [(0,0),(1,0),(0,1),(1,1),(1,2),(2,1)],'rarity': 30}
- ]
- #generatables=['Dirt','Coal','Iron'] # in ascending order of rarity
- game_map=[]
- map_x = 101
- map_y = 101
- for y in range(0,map_y): #makes a blank map
- x_layer = []
- for x in range(0,map_x):
- x_layer.append('')
- game_map.append(x_layer)
- # for x in map:
- # print(x)
- #convinience functions
- def get_index(x,y):
- x_index = (((map_x/2).__ceil__())-1)+x
- y_index = (y*-1)+((map_y/2).__ceil__())-1
- return (y_index,x_index)
- def get_cords(x_index,y_index):
- x = x_index-(((map_x/2).__ceil__())-1)
- y = ((y_index+1)-(map_y/2).__ceil__())*-1
- return (x,y)
- def get_from_map_content(key,key_target,dict): ## not sure about func name
- for tile_dict in dict:
- if tile_dict[key] == key_target: # stopped here
- return tile_dict
- def get_tile_from_map(pos): # receives cords
- x = pos[0]
- y = pos[1]
- index = get_index(x,y)
- tile = game_map[index[0]][index[1]]
- tile_dict = get_from_map_content('symbol',tile,map_content)
- return (tile,tile_dict)
- #=========================================================================================================================#
- #Map gen functions
- # fill = what type of till will be filled in that tile
- def fill_map(point1,point2,content='Air'): #works like minecraft fill command only receives index
- #in content you have to input the type
- max_x = max(point1[1],point2[1])
- min_x = min(point1[1],point2[1])
- max_y = max(point1[0],point2[0])
- min_y = min(point1[0],point2[0])
- fill = get_from_map_content('type',content,map_content)
- fill_symbol = fill['symbol']
- fill_type = fill['type']
- for layer_index, layer in enumerate(game_map):
- for collumn_index, tile in enumerate(layer):
- if min_y <= layer_index <= max_y and min_x <= collumn_index <= max_x:
- game_map[layer_index][collumn_index] = fill_symbol
- def generate(start_point,fill): #fill is tile type
- tile_dict = get_from_map_content('type',fill,map_content)
- tile_generation = tile_dict['generation']
- size = tile_generation[randint(0,len(tile_generation)-1)]
- end_point = (start_point[0]+size[0], start_point[1]+size[1])
- fill_map(start_point,end_point,fill)
- def generate_template():
- fill_map((0, 0), (map_y - 1, map_y - 1), 'Stone')
- for layer_index, layer in enumerate(game_map):
- for collumn_index, tile in enumerate(layer):
- if tile == '[]':
- tile_index = (layer_index, collumn_index)
- def get_rarity(tile_type):
- rarity = get_from_map_content('type', tile_type, map_content)['rarity']
- return rarity
- def seq_wrapper(tile_type):
- if randint(0, get_rarity(tile_type)) == 0:
- generate(tile_index, tile_type)
- return tile_type
- generatables = ['Dirt', 'Coal', 'Iron']
- result = list(map(seq_wrapper, generatables))
- generate_template()
- surface_y = get_cords(0,1)[1]
- print(surface_y)
- fill_map(get_index(0,0),get_index(0,0),'Stone')
- print('==================================================================')
- for x in game_map:
- print(x)
- print(get_tile_from_map((-5,-5),))
Add Comment
Please, Sign In to add comment