Esempio n. 1
0
def getbounce(objs, dt):
	ds = [[0, 0] for _ in objs]
	for i, j in getcollisions(objs):
		x0, y0, r0, m0 = objs[i]
		x1, y1, r1, m1 = objs[j]
		if (x0 - x1) ** 2 + (y0 - y1) ** 2 < (r0 + r1) ** 2:
			dx = x1 - x0
			dy = y1 - y0
			if dx == 0 and dy == 0:
				a = random.angle()
				dx = 1.0 * math.sin(a)
				dy = 1.0 * math.cos(a)
			d = math.sqrt(dx ** 2 + dy ** 2)
			f = math.clamp(20 * (r0 + r1 - d), 50, 200)
			dx *= dt / d * f
			dy *= dt / d * f
			da = math.sqrt(dx ** 2 + dy ** 2)
			if d + da > 1.001 * (r0 + r1):
				db = 1.001 * (r0 + r1) - d
				dx *= db / da
				dy *= db / da
			f0, f1 = (1, 0) if m1 > 100 * m0 else (0, 1) if m0 > 100 * m1 else (m1 / (m0 + m1), m0 / (m1 + m0))
#			f0, f1 = (m1 / (m0 + m1), m0 / (m1 + m0))
			ds[i][0] -= dx * f0
			ds[i][1] -= dy * f0
			ds[j][0] += dx * f1
			ds[j][1] += dy * f1
	return ds
Esempio n. 2
0
def getbounce(objs, dt):
    ds = [[0, 0] for _ in objs]
    for i, j in getcollisions(objs):
        x0, y0, r0, m0 = objs[i]
        x1, y1, r1, m1 = objs[j]
        if (x0 - x1)**2 + (y0 - y1)**2 < (r0 + r1)**2:
            dx = x1 - x0
            dy = y1 - y0
            if dx == 0 and dy == 0:
                a = random.angle()
                dx = 1.0 * math.sin(a)
                dy = 1.0 * math.cos(a)
            d = math.sqrt(dx**2 + dy**2)
            f = math.clamp(20 * (r0 + r1 - d), 50, 200)
            dx *= dt / d * f
            dy *= dt / d * f
            da = math.sqrt(dx**2 + dy**2)
            if d + da > 1.001 * (r0 + r1):
                db = 1.001 * (r0 + r1) - d
                dx *= db / da
                dy *= db / da
            f0, f1 = (1, 0) if m1 > 100 * m0 else (
                0, 1) if m0 > 100 * m1 else (m1 / (m0 + m1), m0 / (m1 + m0))
            #			f0, f1 = (m1 / (m0 + m1), m0 / (m1 + m0))
            ds[i][0] -= dx * f0
            ds[i][1] -= dy * f0
            ds[j][0] += dx * f1
            ds[j][1] += dy * f1
    return ds
Esempio n. 3
0
 def die(self):
     theta = random.angle()
     for j in range(self.ncarried):
         dx = math.sin(theta + j * math.tau / self.ncarried)
         dy = math.cos(theta + j * math.tau / self.ncarried)
         ant = self.carrytype(x=self.x + 2 * dx, y=self.y + 2 * dy)
         ant.target = self.target
         ant.kick(50 * dx, 50 * dy)
         ant.addtostate()
Esempio n. 4
0
	def die(self):
		theta = random.angle()
		for j in range(self.ncarried):
			dx = math.sin(theta + j * math.tau / self.ncarried)
			dy = math.cos(theta + j * math.tau / self.ncarried)
			ant = self.carrytype(x = self.x + 2 * dx, y = self.y + 2 * dy)
			ant.target = self.target
			ant.kick(50 * dx, 50 * dy)
			ant.addtostate()
Esempio n. 5
0
def stream(etype):
	from . import thing
	theta = random.angle()
	step = random.uniform(30, 60)
	x, y = outstep(theta, step)
	addetype(etype, x, y)
Esempio n. 6
0
def reset(self):
    self.lastshot = self.t
    self.lastangle = random.angle()
Esempio n. 7
0
def reset(self):
	self.lastshot = self.t
	self.lastangle = random.angle()