Esempio n. 1
0
	def create_map(self, starting_terrain, size, tileset="default"):
		"""
		Procedurally generate a map consisting of different biomes.

		"""
		

		rows = []
		for x in range(0, size):
			row = []
			for y in range(0, size):
				row.append(None)
			rows.append(row)

		modifier = .10
		curr_tile = (0,0)
		draw_prob = 4

		new_map = Map(size)

		def paint(map, tile, terrain, prob, mod, iteration=0, queue=[], visited=[]):
			if random.random() <= prob:
				rows[tile[0]][tile[1]] = 1
				map.zones[tile[0]].tiles[tile[1]].type = terrain
				map.zones[tile[0]].tiles[tile[1]].bg_color = terrain_types[tileset][terrain][0]
				map.zones[tile[0]].tiles[tile[1]].fg_color = terrain_types[tileset][terrain][1]
				map.zones[tile[0]].tiles[tile[1]].fg_symbol = terrain_types[tileset][terrain][2]
				map.zones[tile[0]].tiles[tile[1]].passable = terrain_types[tileset][terrain][3]

				prob -= mod
				mod += .01
				if mod < 0:
					mod = 0
			else:
				terrain = weighted_choice(regional_probabilities[terrain])
				rows[tile[0]][tile[1]] = 1
				map.zones[tile[0]].tiles[tile[1]].type = terrain
				map.zones[tile[0]].tiles[tile[1]].bg_color = terrain_types[tileset][terrain][0]
				map.zones[tile[0]].tiles[tile[1]].fg_color = terrain_types[tileset][terrain][1]
				map.zones[tile[0]].tiles[tile[1]].fg_symbol = terrain_types[tileset][terrain][2]
				map.zones[tile[0]].tiles[tile[1]].passable = terrain_types[tileset][terrain][3]
				prob = 4
				mod = .01
			tiles = get_adjacent(tile[0], tile[1], size)
			random.shuffle(tiles)
			iteration += 1
			for t in tiles:
				if not rows[t[0]][t[1]]:
					paint(map, t, terrain, prob, mod, iteration)

		paint(new_map, curr_tile, starting_terrain, draw_prob, modifier)
	
		path = logic.a_star(new_map.zones[len(new_map.zones)/2].tiles[0], new_map.zones[len(new_map.zones)/2].tiles[-1], check_passable=False)
		for tile in path:
			tile.temp_bg_color = (255,0,0)
		path = logic.a_star(new_map.zones[0].tiles[len(new_map.zones)/2], new_map.zones[-1].tiles[len(new_map.zones)/2], check_passable=False)
		for tile in path:
			tile.temp_bg_color = (255,0,0)
		return new_map
Esempio n. 2
0
	def can_move(self, tile):
		if not tile.occupant and tile.passable and not self.acted:
			dist = calculate_distance(tile, self.location)
			if dist <= self.speed:
				path = a_star(self.location, tile)
				if path:
					self.acted = True
					return path
		return False