예제 #1
0
 def move(self):
     (self.angle, self.speed) = utils.add_vectors(
         (self.angle, self.speed),
         (0,
          0.00025))  # This mysterious tuple is gravity in polar coordinates
     self.speed *= self.drag
     self.x += (math.sin(self.angle) * self.speed)
     self.y += (math.cos(self.angle) * self.speed)
     return
예제 #2
0
	def collide(self, p1, p2):
		dx = p1.x - p2.x
		dy = p1.y - p2.y

		dist = math.hypot(dx, dy)
		if dist < p1.size + p2.size:
			angle = math.atan2(dy, dx) + math.pi/2
			total_mass = p1.mass + p2.mass

			(p1.angle, p1.speed) = utils.add_vectors((p1.angle, p1.speed*(p1.mass-p2.mass)/total_mass),
												(angle+math.pi, 2*p1.speed/total_mass))

			overlap = 0.5*(p1.size + p2.size - dist+1)
			p1.x += math.sin(angle)*overlap
			p1.y -= math.cos(angle)*overlap
			p2.x -= math.sin(angle)*overlap
			p2.y += math.cos(angle)*overlap

			p1.speed *= self.ELASTICITY
			p2.speed *= self.ELASTICITY
		return
예제 #3
0
	def collide(self, p1, p2):
		dx = p1.x - p2.x
		dy = p1.y - p2.y

		dist = math.hypot(dx, dy)
		if dist < p1.size + p2.size:
			angle = math.atan2(dy, dx) + math.pi/2
			total_mass = p1.mass + p2.mass

			(p1.angle, p1.speed) = utils.add_vectors((p1.angle, p1.speed*(p1.mass-p2.mass)/total_mass),
												(angle+math.pi, 2*p1.speed/total_mass))

			overlap = 0.5*(p1.size + p2.size - dist+1)
			p1.x += math.sin(angle)*overlap
			p1.y -= math.cos(angle)*overlap
			p2.x -= math.sin(angle)*overlap
			p2.y += math.cos(angle)*overlap

			p1.speed *= self.ELASTICITY
			p2.speed *= self.ELASTICITY
		return
예제 #4
0
	def move(self):
		(self.angle, self.speed) = utils.add_vectors((self.angle, self.speed), (0, 0.00025)) # This mysterious tuple is gravity in polar coordinates
		self.speed *= self.drag
		self.x += (math.sin(self.angle) * self.speed)
		self.y += (math.cos(self.angle) * self.speed)
		return