コード例 #1
0
	def collision(self, wp):
		#check if in bounding box
		if not (self.minX - wp.r <= wp.x <= self.maxX + wp.r and self.minY - wp.r <= wp.y <= self.maxY + wp.r):
			return False
		epsilon = 2
		L = len(self.LoC)
		if self.inMe:
			inside = True	#still inside
			for i in xrange(L):
				P = self.LoC[i]
				Q = self.LoC[(i + 1) % L]
				R = (wp.x, wp.y)
				nextR = p.vadd((wp.x, wp.y), wp.v)
				det = p.det(P, Q, nextR)
				#if moving away from wall, continue
				if p.det(P, Q, R) >= det: continue
				inside &= (det <= p.dist(P, Q) * (epsilon - wp.r))
				if not inside: break #to retain values of P, Q
			if inside:
				return True #because collision
			#otherwise  check for internal reflection
			base = p.vsub(Q, P)
			if not p.refract(wp.v, base, self.rIndex, 1):
				wp.v = p.reflect(wp.v, base)
				return True
			#otherwise if not complete exit, return collision true
			if det < p.dist(P, Q) * wp.r:
				return True
			#otherwise complete exit, change angle
			self.inMe = False
			wp.v = p.fixNorm(p.refract(wp.v, p.vsub((0, 0), base), self.rIndex, 1), wp.maxSpeed)
			return False
		else:
			#check each individual side
			for i in xrange(L):
				if self.checkEdgeCollision(wp, i):
					return True
			for i in xrange(L):
				if self.checkVertexCollision(wp, i):
					return True
			return False
コード例 #2
0
	def waveVertexCollision(self, wp, w):
		subprocess.Popen(["python", self.path + os.sep + "aud" + os.sep + "twang.py"])
		wp.v = p.reflect(wp.v, w)
コード例 #3
0
	def waveVertexCollision(self, wp, w):
		wp.v = p.reflect(wp.v, w)
		wp.health = 0
コード例 #4
0
	def waveEdgeCollision(self, wp, P, Q):
		subprocess.Popen(["python", self.path + os.sep + "aud" + os.sep + "twang.py"])
		wp.v = p.reflect(wp.v, p.vsub(Q, P))