Example #1
0
 def buildbasepath(self):
     self.forbiddentiles = []
     for building in self.buildings:
         #print building.btype, building.rsquares()
         self.forbiddentiles.extend(building.rsquares())
     self.pathdistance = {}
     self.pathparent = {}
     tileq, d = self.hq.rsquares(), 0
     #print tileq
     while tileq:
         for tile in tileq:
             self.pathdistance[tile] = d
         if d >= 25: break
         ntileq = set()
         for x0, y0 in tileq:
             for dx in (-1, 1):
                 for dy in (-1, 1):
                     x, y = x0 + dx, y0 + dy
                     if (x, y
                         ) in self.forbiddentiles or terrain.isunderwater(
                             x, y):
                         continue
                     if (x, y) not in self.pathdistance:
                         ntileq.add((x, y))
                         self.pathparent[(x, y)] = (x0, y0)
         tileq = sorted(ntileq)
         d += 1
	def buildbasepath(self):
		self.forbiddentiles = []
		for building in self.buildings:
			#print building.btype, building.rsquares()
			self.forbiddentiles.extend(building.rsquares())
		self.pathdistance = {}
		self.pathparent = {}
		tileq, d = self.hq.rsquares(), 0
		#print tileq
		while tileq:
			for tile in tileq:
				self.pathdistance[tile] = d
			if d >= 25: break
			ntileq = set()
			for x0,y0 in tileq:
				for dx in (-1,1):
					for dy in (-1,1):
						x,y = x0+dx,y0+dy
						if (x,y) in self.forbiddentiles or terrain.isunderwater(x, y):
							continue
						if (x,y) not in self.pathdistance:
							ntileq.add((x,y))
							self.pathparent[(x,y)] = (x0,y0)
			tileq = sorted(ntileq)
			d += 1
	def explore(self):
		self.exploret = 0
		import time
		t0 = time.time()
		sx0, sy0 = self.get_current_sector()
		# TODO: look into performance
		nexplored = set((sx0+dx, sy0+dy) for dx in (-1,0,1) for dy in (-1,0,1))
		# remove aliens that are way out there
		self.sprites = [s for s in self.sprites if s is self.player or s.getsector() in nexplored]
		# populate sectors that are newly explored
		nnew = len(nexplored - self.explored)
		for sx, sy in nexplored - self.explored:
			d = math.sqrt((self.cx//60 - sx) ** 2 + (self.cy//60 - sy)**2)
			if d < 2:
				atypes = [sprite.CheapAlien] * 20
			elif d < 3:
				atypes = [sprite.CheapAlien] * 16 + [sprite.QuickAlien] * 8
			elif d < 4:
				atypes = [sprite.CheapAlien] * 12 + [sprite.QuickAlien] * 12 + [sprite.StrongAlien] * 2
			else:
				atypes = [sprite.CheapAlien] * 20 + [sprite.QuickAlien] * 18 + [sprite.StrongAlien] * 12
			for atype in atypes:
				x, y = (sx + random.random()) * 60., (sy + random.random()) * 60.
				rx, ry = terrain.toRender(x, y)
				if self.is_wild(rx, ry) and not terrain.isunderwater(rx, ry):
					self.sprites.append(atype(x, y, True))
		self.explored = nexplored
		if nnew:
			pass #print("Explored %s new sectors in %.3fs" % (nnew, time.time() - t0))
	def deploy(self, scene, target, btype):
		X0, Y0 = terrain.toModel(target.x, target.y)
		#print self.hq.x, self.hq.y, X0, Y0, X0 - Y0, -X0 - Y0
		r = 3
		while True:
			theta = random.random() * 1000
			X = int((X0 + r * math.sin(theta))//1)
			Y = int((Y0 + r * math.cos(theta))//1)
			x, y = terrain.nearesttile(X - Y, -X - Y)
			if not terrain.isunderwater(x, y) and not self.border.iswithin(x, y):
				break
			r += 0.2
		alien = btype(X, Y)
		alien.settarget(target)
		self.attackers.append(alien)
Example #5
0
 def deploy(self, scene, target, btype):
     X0, Y0 = terrain.toModel(target.x, target.y)
     #print self.hq.x, self.hq.y, X0, Y0, X0 - Y0, -X0 - Y0
     r = 3
     while True:
         theta = random.random() * 1000
         X = int((X0 + r * math.sin(theta)) // 1)
         Y = int((Y0 + r * math.cos(theta)) // 1)
         x, y = terrain.nearesttile(X - Y, -X - Y)
         if not terrain.isunderwater(x, y) and not self.border.iswithin(
                 x, y):
             break
         r += 0.2
     alien = btype(X, Y)
     alien.settarget(target)
     self.attackers.append(alien)
 def cango(self, isempty, x, y, exclude=None):
     if terrain.isunderwater(x, y):
         return False
     if not isempty(x, y, exclude) and isempty(self.x, self.y):
         return False
     return True
	def cango(self, isempty, x, y, exclude=None):
		if terrain.isunderwater(x, y):
			return False
		if not isempty(x, y, exclude) and isempty(self.x, self.y):
			return False
		return True