コード例 #1
0
ファイル: Car.py プロジェクト: MBCook/IttyBittyCity
	def calculateNewPath(self):
		"""Get a new path for us to follow."""

		nodeDict = self.simulationHandle.getMap().getNodeDict()
		distDict = self.simulationHandle.getMap().getDistDict()

		self.path = pathfinder.findPath(self.currentNode, self.goalNode, nodeDict, distDict)
コード例 #2
0
def getSolution(myX, myY, desX, desY, myDir, obstacleList):
	myPath = findPath(myX, myY, myDir, desX, desY, obstacleList)
	direction = findDirection(myPath, 1)
	display(myPath, obstacleList)
	return [myPath, direction]

#print getSolution(2, 3, 8, 10, 0, [[2,5],[9,2]])
コード例 #3
0
ファイル: monsters.py プロジェクト: codelurker/UGUIR
 def updateState(self, map):
     mapPos = map.getCellAtPos(self.pos)
     if self.dead == True:
         return
     if mapPos.visible:
         self.currentPath = []
         pFinder = findPath(map,self.pos,map.player.pos)
         pIter = pFinder.iter
         pIter.next()
         for p in pIter:
             self.currentPath.append(p)
         self.playerOldPos = map.player.pos
         try:
             next = self.currentPath.pop(0)
         except IndexError:
             return
         self.moveOrAttack(map, mapPos, next)
コード例 #4
0
ファイル: Main.py プロジェクト: MBCook/IttyBittyCity
def main():
	"""The main program."""

	print ""

	# Initialize Pygame

	print "Starting Pygame..."

	pygame.init()

	# First we set some stuff up.

	print "Initializing stuff..."

	prefs = Preferences.Preferences()
	prefs.loadPreferences()
	video = Video.Video(prefs)
	video.prepareVideo()

	carObject = Car.Car()
	groundObject = Map.Map()

	groundObject.loadMapData(test_map.t_d, test_map.t_w, test_map.t_h)
	groundObject.setupObjects()

	carObject.setXYPosition(8.0, 9.0)

	carDir = 0.0

	print "Unpickleing dictionaries..."

	nodeFile = open("Objects/Map/node_list.dat", "r")
	distFile = open("Objects/Map/node_distances.dat", "r")

	nodeDict = pickle.load(nodeFile)
	distDict = pickle.load(distFile)

	nodeFile.close()
	distFile.close()

	# Our two test nodes

	startNode = "0200BL"
	endNode = "1619BR"

	# Now we do things

	print "Preparing lists for drawing paths..."

	(points, lines) = VideoRoutines.drawPathsPrep(nodeDict, distDict)

	print "Preparing a path from '%s' to '%s'..." % (startNode, endNode)

	specialPath = pathfinder.findPath(startNode, endNode, nodeDict, distDict)

#	print "Path found was:"
#	print specialPath
#	print ""

	print "Starting main loop..."

	while 1:

		for event in pygame.event.get():
			if event.type == pygame.QUIT:
				sys.exit()

		carDir += 1.0
		if (carDir >= 360.0):
			carDir -= 360.0
		carObject.setAngle(carDir)

		video.prepareNewFrame()
		video.setupCamera()
		video.setupLights()

		# Drawing happens here

		glLoadIdentity()

		groundObject.draw()
		carObject.draw()

		glLoadIdentity()

		VideoRoutines.drawPaths(points, lines, 20.0, 1.0, 3.0)
		VideoRoutines.drawSpecialPath(specialPath, nodeDict, 20.0, 1.0, 3.0)

		video.finishNewFrame()

		pygame.time.wait(33)

	print "Exiting..."
	print ""
コード例 #5
0
ファイル: map.py プロジェクト: unnheulu/Luna-Pyweek
 def findRoute(self,workerPos,targetPos):
     route = findPath(self.blockedMap,workerPos,targetPos)
     self.highlighted = route
     
     return route