def test_vector_set_angle(self): i = Vector2D(1.0, 0) j = Vector2D(0, 1.0) a = random.random() * 360.0 k = Vector2D.from_angle(a) self.assertAlmostEqual(Vector2D.from_angle(0), i, 5, "failed to set angle") self.assertAlmostEqual(Vector2D.from_angle(90.0), j, 5, "failed to set angle") self.assertAlmostEqual(Vector2D.from_angle(180.0), -i, 5, "failed to set angle") self.assertAlmostEqual(Vector2D.from_angle(270.0), -j, 5, "failed to set angle") self.assertAlmostEqual(k.angle, a, 5, "failed to set angle")
def onMouseDown(self, event): if event.button == 1: num_puffs = 8.0 for i in range(int(num_puffs) + 1): theta = 0 + (360 * (i / num_puffs)) e = PuffEmitter(2000) e.position = Vector2D(Game.camera_to_world(event.pos)) e.velocity = Vector2D.from_angle(theta) * -180.0 self.add(e)
def __init__(self, image, lifetime): super(Particle, self).__init__(image) self.__velocity = Vector2D.from_angle(random.randrange(80, 100)) * -1.35 sheet = ImageSheet(ResourceLoader.load('data//puffs.png'), (32, 32)) puff = [(sheet[3], int(lifetime * 0.2)), (sheet[2], int(lifetime * 0.1)), (sheet[1], int(lifetime * 0.3)), (sheet[0], int(lifetime * 2.0))] self.animation = Animation('puff', puff) self.add(self.animation) self.add(DestroyAfter(lifetime))
def update(self, milliseconds=0): self.angle += self.angular_velocity * milliseconds / 16.66 offset = Vector2D.from_angle(self.angle) * self.radius # Rotate about the local 0, 0 self.game_object.transform.local_position = offset
def forward(self): return Vector2D.from_angle(self.rotation)