Пример #1
0
class ObstaclesOccGrid(FieldGen):
    def __init__(self, bzrc):
        super(ObstaclesOccGrid, self).__init__(bzrc)

        self.bzrc = bzrc
        self.world_map = WorldMap(bzrc)
        self.time_diff = 3
        self.last_time = time.time() - self.time_diff

    def vector_at(self, x, y):
        # update the occ grid if enough time has passed
        if time.time() - self.last_time >= self.time_diff:
            self.world_map.update_grid(self.bzrc)
            self.last_time = time.time()

        closest_edge = self.world_map.obstacle_edge_at(x, y, EFFECTIVE_RANGE)
        if closest_edge is None:
            return Vec2d(0, 0), False

        # position vector
        vector_s = Vec2d(x, y)

        # vector for endpoint 1
        vector_a = Vec2d(closest_edge[0])

        # vector for endpoint 2
        vector_c = Vec2d(closest_edge[1])

        # final vector is the sum of vector from C to S and from A to S
        final_vector = (vector_s - vector_c) + (vector_s - vector_a)

        return final_vector.normalized(), False
    def GenAirplanes(self):
        iNbAirplanes = random.randint(10, 15)
        i = 0
        Output.debug("Generating %d airplanes" % iNbAirplanes)
        lstCityNames = sorted(WorldMap.keys())
        while i < iNbAirplanes:
            szOrigin = random.choice(lstCityNames)
            j = random.randint(0, len(lstCityNames) - 1)
            k = 0
            while k < len(lstCityNames):
                szDestination = lstCityNames[(j + k) % len(lstCityNames)]
                iDistance = (WorldMap[szDestination][0] - WorldMap[szOrigin][0]
                             )**2 + (WorldMap[szDestination][1] -
                                     WorldMap[szOrigin][1])**2
                if iDistance >= 100000 and (abs(WorldMap[szDestination][0] -
                                                WorldMap[szOrigin][0]) > 100):
                    break
                k += 1

            if k < len(lstCityNames):
                szId = "A_%.4d" % random.randint(10 * i, 10 * i + 9)
                self.__dicAirplanes[szId] = CAirplane(szId, szOrigin,
                                                      szDestination)
                i += 1

        return True
Пример #3
0
    def __init__(self, bzrc):
        super(ObstaclesOccGrid, self).__init__(bzrc)

        self.bzrc = bzrc
        self.world_map = WorldMap(bzrc)
        self.time_diff = 3
        self.last_time = time.time() - self.time_diff
Пример #4
0
def main():
	if len(sys.argv) > 1:
		randomseed = int(sys.argv[1])
		seed(randomseed)

	global draw_offset_x
	global draw_offset_y

	p1 = NoiseGrid(size=64, precision=4)
	p2 = NoiseGrid(size=64, precision=4)
	p3 = NoiseGrid(size=64, precision=4)
	noisegrids = [p1, p2, p3]

	libtcod.console_set_custom_font('arial10x10.png', 
		libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	root = libtcod.console_init_root(screen_width, screen_height, 
			'world gen', False, 
			libtcod.RENDERER_SDL2, vsync=True)
	con = libtcod.console.Console(screen_width, screen_height)
	printbiome = ''

	world = WorldMap(map_width, map_height)
	region = None
	adjregions = {}
	draw_offset_x = (int)((screen_width - map_width) / 2)
	draw_offset_y = (int)((screen_height - map_height) / 2)
	printworld(root, con, world)
	libtcod.console_flush()

	viewstate = ViewState.WORLD

	while True:
		for event in tcod.event.wait():
			if event.type == "QUIT":
				raise SystemExit()
	
		# print canvas
		con.clear()
		#printUI(con, world, region, viewstate)
		libtcod.console_flush()
Пример #5
0
def main():
	if len(sys.argv) > 1:
		randomseed = int(sys.argv[1])
		seed(randomseed)

	global draw_offset_x
	global draw_offset_y

	p1 = NoiseGrid(size=64, precision=4)
	p2 = NoiseGrid(size=64, precision=4)
	p3 = NoiseGrid(size=64, precision=4)
	noisegrids = [p1, p2, p3]

	libtcod.console_set_custom_font('arial10x10.png', 
		libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
	root = libtcod.console_init_root(screen_width, screen_height, 
			'world gen', False, 
			libtcod.RENDERER_SDL2, vsync=True)
	con = libtcod.console.Console(screen_width, screen_height)
	printbiome = ''

	world = WorldMap(map_width, map_height)
	region = None
	adjregions = {}
	draw_offset_x = (int)((screen_width - map_width) / 2)
	draw_offset_y = (int)((screen_height - map_height) / 2)
	printworld(root, con, world)
	libtcod.console_flush()

	viewstate = ViewState.WORLD

	while True:
		for event in tcod.event.wait():
			if event.type == "QUIT":
				raise SystemExit()

			elif viewstate == ViewState.WORLD:
				draw_offset_x = (int)((screen_width - map_width) / 2)
				draw_offset_y = (int)((screen_height - map_height) / 2)

				printworld(root, con, world)
				if event.type == "MOUSEBUTTONDOWN":
					scrx, scry = event.tile
					mapx = scrx - draw_offset_x
					mapy = scry - draw_offset_y
					if (mapx >= 0 and
						mapx < map_width and
						mapy >= 0 and
						mapy < map_height):

						if event.button == libtcod.event.BUTTON_LEFT:
							region = RegionMap(
								mapx, mapy, 
								world,
								noisegrids,
								regionside=regionside)
							viewstate = ViewState.REGION
							con.clear()
							printUI(con, world, region, viewstate)
							libtcod.console_flush()
						else:
							print(event.button)
				elif event.type == "KEYDOWN":
					if event.sym == libtcod.event.K_ESCAPE:
						raise SystemExit()
			elif viewstate == ViewState.REGION:
				draw_offset_x = (int)((screen_width - regionside) / 2)
				draw_offset_y = (int)((screen_height - regionside) / 2)

				printregion(root, con, region, adjregions)
				if event.type == "MOUSEBUTTONDOWN":
					scrx, scry = event.tile
					mapx = scrx - draw_offset_x
					mapy = scry - draw_offset_y
					if (mapx >= 0 and
						mapx < regionside and
						mapy >= 0 and
						mapy < regionside):

						if event.button == libtcod.event.BUTTON_LEFT:
							#localmap = LocalMap()
							viewstate = ViewState.LOCAL
							con.clear()
							printUI(con, world, region, viewstate)
							libtcod.console_flush()
						elif event.button == libtcod.event.BUTTON_RIGHT:
							newadj = {}
							cx, cy = (regionside//2, regionside//2)
							x, y = region.worldpos
							if (mapx < cx):
								if ((-1, 0) in adjregions):
									newadj[(-1, 0)] = \
										adjregions[(-1, 0)]
								else:
									newadj[(-1, 0)] = \
										RegionMap(
											x-1, y, 
											world,
											noisegrids,
											regionside=regionside)
							if (mapx >= cx):
								if ((1, 0) in adjregions):
									newadj[(1, 0)] = \
										adjregions[(1, 0)]
								else:
									newadj[(1, 0)] = \
										RegionMap(
											x+1, y, 
											world,
											noisegrids,
											regionside=regionside)
							if (mapy < cy):
								if ((0, -1) in adjregions):
									newadj[(0, -1)] = \
										adjregions[(0, -1)]
								else:
									newadj[(0, -1)] = \
										RegionMap(
											x, y-1, 
											world,
											noisegrids,
											regionside=regionside)
							if (mapy >= cy):
								if ((0, 1) in adjregions):
									newadj[(0, 1)] = \
										adjregions[(0, 1)]
								else:
									newadj[(0, 1)] = \
										RegionMap(
											x, y+1, 
											world,
											noisegrids,
											regionside=regionside)
							adjregions.clear()
							for key in newadj:
								adjregions[key] = newadj[key]

				elif event.type == "KEYDOWN":
					if event.sym == libtcod.event.K_ESCAPE:
						viewstate = ViewState.WORLD
						adjregions.clear()

			elif viewstate == ViewState.LOCAL:
				draw_offset_x = (int)((screen_width - map_width) / 2)
				draw_offset_y = (int)((screen_height - map_height) / 2)

				#printlocal(root, con, localmap)
				if event.type == "MOUSEBUTTONDOWN":
					scrx, scry = event.tile
					mapx = scrx - draw_offset_x
					mapy = scry - draw_offset_y
					if (mapx >= 0 and
						mapx < map_width and
						mapy >= 0 and
						mapy < map_height):

						if event.button == libtcod.event.BUTTON_LEFT:
							pass

				elif event.type == "KEYDOWN":
					if event.sym == libtcod.event.K_ESCAPE:
						viewstate = ViewState.REGION
						con.clear()
						libtcod.console_flush()
	
		con.clear()
		printUI(con, world, region, viewstate)
		libtcod.console_flush()