Example #1
0
	def __init__(self, x, y, m, s):
		self.position = v2.vector2(x,y)
		self.velocity = v2.vector2(0,0)
		self.target = v2.vector2(0,0)
		self.desired = None
		self.steering = v2.vector2(0,0)
		self.avoidance = v2.vector2(0,0)
		self.mass = m
		self.sprite = s
		
		self.wanderAngle = random.randint(-4,4)
Example #2
0
	def obstacleAvoid(self, obstacles):
		self.avoidance = v2.vector2(0,0)
		tv = self.velocity
		tv.norm()
		tv = tv * MAXAVOIDAHEAD
		ahead = self.position + tv
		mostThreatening = None
		
		for i in range(len(obstacles)):
			obstacle = obstacles[i]
			
			if((obstacle.pos - self.position).mag()>96):
				continue
			else:
				if(kd.debug):
					PKFW.drln(self.position.x, self.position.y, obstacle.pos.x, obstacle.pos.y, 0,0,1)
				
			coll = self.lineIntersection(self.position, ahead, obstacle)
			if(coll and ((mostThreatening is None) or (self.position.distance(obstacle.pos) < self.position.distance(mostThreatening.pos)))):
				mostThreatening = obstacle
		
		if(mostThreatening is not None):
			self.avoidance = ahead - mostThreatening.pos
			self.avoidance.norm()
			self.avoidance = self.avoidance * AVOIDFOR
		else:
			self.wander()
Example #3
0
	def rule3(self, aBoid):
		t = v2.vector2(0,0)
		for i in range(len(self.boids)):
			if(self.boids[i] is not aBoid):
				t = t + self.boids[i].velocity
		t = t / (len(self.boids)-1)
		return (t - aBoid.velocity)
			
Example #4
0
	def rule2(self, aBoid):
		t = v2.vector2(0,0)
		for i in range(len(self.boids)):
			if(self.boids[i] is not aBoid):
				d = self.boids[i].position - aBoid.position
				if(d.mag() <= 30):
					t = t - d*2
		return t
Example #5
0
	def rule1(self, aBoid):
		t = v2.vector2(0,0)
		for i in range(len(self.boids)):
			if(self.boids[i] is not aBoid):
				t = t + self.boids[i].position
				
		t = t /(len(self.boids)-1)
		return ((t - aBoid.position) / (len(self.boids)*15))
	def __init__(self):
		self.Sid = -1
		self.pos = v2.vector2(0,0)
		self.gpos = {'x':0,'y':0} #was using dictionaries before i created a vector2 py script ## should replace with vector
		self.reachable = 1
		self.parent=None
		self.Gscore=0
		self.Fscore=0
		self.Hscore=0
Example #7
0
	def lineIntersection(self, pos, ahead, obstacle):
		tv = self.velocity
		tv.norm()
		tv = tv * MAXAVOIDAHEAD * 0.75
		
		ahead2 = self.position + tv
		if(kd.debug):
			PKFW.drln(self.position.x, self.position.y, ahead.x, ahead.y, 1,0,1)
			PKFW.drln(self.position.x, self.position.y, ahead2.x, ahead2.y, 1,1,0)
		n = 52
		if(kd.debug):
			for t in range(n)[::3]:
				th = 2* math.pi * t/n
				th1 = 2* math.pi * (t+1)/n
				v = v2.vector2(n*math.cos(th), n*math.sin(th))
				v1 = v2.vector2(n*math.cos(th1), n*math.sin(th1))
				if(obstacle.gpos['x']>0 and obstacle.gpos['y']>0):
					PKFW.drln(obstacle.pos.x+v.x, obstacle.pos.y+v.y, obstacle.pos.x+v1.x, obstacle.pos.y+v1.y, 1,1,1)
		return (obstacle.pos.distance(ahead)<=n) or (obstacle.pos.distance(ahead2)<=n)
Example #8
0
	def wander(self):
		circCent = self.velocity
		cricCent = circCent.norm()
		circCent = circCent * CIRCDIS
			
		displac = v2.vector2(1,1)
		displac = displac * CIRCRAD
		len = displac.mag()
		
		displac.x = math.cos(self.wanderAngle) * len  * 0.1
		displac.y = math.sin(self.wanderAngle) * len  * 0.1
		
		r = random.random() 
		
		self.wanderAngle = self.wanderAngle + r * ANGLECHANGE - ANGLECHANGE * 0.5
		print(self.wanderAngle);
		self.steering = circCent + displac