Beispiel #1
0
    def test_convert(self):
        self.assertIsInstance(Vector2D.convert((1, 2)), Vector2D)
        self.assertIsInstance(Vector2D.convert([1, 2]), Vector2D)
        self.assertIs(Vector2D.convert(self.vector), self.vector)

        self.assertRaises(TypeError, Vector2D.convert, (1, 2, 3))
        self.assertRaises(TypeError, Vector2D.convert, [1, 2, 3])
Beispiel #2
0
    def test_normalize(self):
        self.vector = Vector2D(3, 5)
        normalized = self.vector.normalize()

        length = self.vector.length
        self.assertEqual(normalized, (3 / length, 5 / length))

        self.assertEqual((0, 0), Vector2D.zeros().normalize())
Beispiel #3
0
    def __init__(self, position, images, **kwargs):
        super(Player, self).__init__(position, **kwargs)
        self.speed = 7
        self.state = Player.State.NORMAL
        self.images = images
        self.image = getattr(self.images, self.state)
        self.mask = convert_to_mask(self.image)

        self._left_move = (-self.speed, 0)
        self._right_move = (self.speed, 0)
        self._direction = Vector2D.zeros()
        self._destroyed_animation_frames = 10
        self._is_destroyed = False
Beispiel #4
0
    def __init__(self, position, image=None, image_mask=None, layers=None,
                 is_enabled=True, is_visible=True):
        """

        :param image: An image to use as object visualization
        :param image_mask: Defines which pixels of image to use when object
        is checked for intersection
        :type position: pygvent.vector2d.Vector2D|list|tuple
        :type is_visible: bool
        """
        super(VisibleGameObject, self).__init__(layers, is_enabled)
        self.image = image
        self.mask = image_mask

        self._is_visible = is_visible
        self._position = Vector2D.convert(position)
Beispiel #5
0
    def test_angles(self):
        self.assertEqual(0, Vector2D.zeros().angle)

        self.vector = Vector2D(0, 3)
        self.assertEquals(self.vector.angle, 90)

        rotated = self.vector.rotate(-90)
        self.assertAlmostEqual(rotated.angle, 0)
        self.assertEqual(rotated.get_angle_between(self.vector), 90)
        self.assertEqual(self.vector.get_angle_between(rotated), -90)

        self.vector.angle -= 90
        self.assertEqual(self.vector.length, rotated.length)
        self.assertEqual(self.vector.angle, 0)
        self.assertEqual(self.vector, [3, 0])

        rotated.rotate(300, inplace=True)
        self.assertAlmostEqual(self.vector.get_angle_between(rotated), -60)
        rotated.rotate(rotated.get_angle_between(self.vector), inplace=True)
        self.assertAlmostEqual(self.vector.get_angle_between(rotated), 0)

        self.vector.angle = 90
        self.assertEqual(self.vector.angle, 90)
        self.assertEqual(round(self.vector, 15), [0, 3])
Beispiel #6
0
    def draw(self, screen):
        if self.can_move(screen):
            self.move(self._direction)
        self._direction = Vector2D.zeros()

        super(Player, self).draw(screen)
Beispiel #7
0
 def test_nonzero(self):
     self.assertTrue(self.vector)
     self.assertFalse(Vector2D.zeros())
     self.assertTrue(Vector2D(0, 1))
     self.assertTrue(Vector2D(1, 0))
Beispiel #8
0
 def __init__(self, position=Vector2D.zeros(), *args, **kwargs):
     super(MockVisibleGameObject, self).__init__(position, *args, **kwargs)