Esempio n. 1
0
	def set_chests(self):

		map = distance_map(self.grid, [11], [0, 2, 3, 4, 5, 6, 8, 9, 23, 24, 25, 26])
		distances = []

		for y in range(0, len(map)):
			for x in range(0, len(map[0])):
				if map[y][x] not in distances and map[y][x] != -1:
					distances.append(map[y][x])

		average = 0
		for i in distances:
			average += i
		average /= len(distances)

		possible_places = []
		for y in range(0, len(map)):
			for x in range(0, len(map[0])):
				if map[y][x] >= average:
					possible_places.append((x, y))


		chests_to_place = len(self.rooms) / 10
		if chests_to_place <= 0:
			chests_to_place = 1
		print 'chests to place:', chests_to_place
		for i in range(0, chests_to_place):

			chance = random.randint(0, 7)
			location = None
			if chance == 1:
				room = random.choice(self.rooms)
				x = random.randint(room.position[0],
								   room.position[0] + (room.size[0]))
				y = random.randint(room.position[1],
								   room.position[1] + (room.size[1]))
				location = (x, y)
			else:
				location = random.choice(possible_places)

			if self.grid[location[1]][location[0]] == 1:
				self.grid[location[1]][location[0]] = 10
				print 'placed!'
Esempio n. 2
0
    def set_objects_monsters(self):

        map = distance_map(self.grid, [11], [0, 2, 3, 4, 5, 6, 7, 8, 9])
        distances = []

        for y in range(0, len(map)):
            for x in range(0, len(map[0])):
                if map[y][x] not in distances and map[y][x] != -1:
                    distances.append(map[y][x])

        average = 0
        for i in distances:
            average += i
        if len(distances) > 1:
            average /= len(distances)-1

        possible_places = []
        for y in range(0, len(map)):
            for x in range(0, len(map[0])):
                if map[y][x] >= average and (self.grid[y][x] == 1 or self.grid[y][x] > 9):
                    possible_places.append((x, y))

        for i in range(0, self.number_items):
            location = random.choice(possible_places)
            possible_places.remove(location)
            self.item_locs.append(location)

        for i in range(0, self.number_monsters):
            location = random.choice(possible_places)
            possible_places.remove(location)
            self.monster_locs.append(location)

        for i in range(0, 15):
            traplocation = random.choice(possible_places)
            possible_places.remove(traplocation)
            self.traps.append(Trap(traplocation[0], traplocation[1]))

        '''