Ejemplo n.º 1
0
	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))
Ejemplo n.º 2
0
	def is_within_borders(self, user_id, sector_x, sector_y, local_mx, local_my, s=1):
		border = self.borders_by_user[user_id]
		for dx in range(s):
			for dy in range(s):
				if not border.iswithin(*terrain.toRender(local_mx+dx, local_my+dy)):
					return False
		return True
Ejemplo n.º 3
0
 def setModelXY(self, x, y):
     self.x, self.y = terrain.toRender(self.x - .5, self.y - .5)
Ejemplo n.º 4
0
	def setModelXY(self, x, y):
		self.x, self.y = terrain.toRender(self.x - .5, self.y - .5)