def test_collision_effect(self):
     po = PhysicsObject(50, 50, 1, 50, [(25, 75), (25, 75)])
     for i in range(0, 1000):
         po._vel = Vector(random.randint(0, self.MAX_RANDOM_VELOCITY), random.randint(0, self.MAX_RANDOM_VELOCITY))
         expected_velocity = po._vel * PhysicsObject.COEFFICIENT_OF_BORDER_COLLISION
         po.collision_effect()
         self.assertTrue(abs(po._vel.x - expected_velocity.x) < 0.1 and abs(po._vel.y - expected_velocity.y) < 0.1)
 def test_friction(self):
     po = PhysicsObject(50, 50, 1, 50, [(25, 75), (25, 75)])
     for i in range(0, 1000):
         po._vel = Vector(random.randint(0, self.MAX_RANDOM_VELOCITY), random.randint(0, self.MAX_RANDOM_VELOCITY))
         expected_velocity = po._vel * PhysicsObject.COEFFICIENT_OF_FRICTION \
             if po._vel > PhysicsObject.STOPPING_VELOCITY else 0
         po.friction()
         self.assertTrue(abs(po._vel.x - expected_velocity.x) < 0.1 and abs(po._vel.y - expected_velocity.y) < 0.1)
Exemple #3
0
    def __init__(self, radius, pos_x, pos_y, mass, player, borders):
        """
        Initialize Mallet object
        :param radius: int/float radius of Mallet
        :param pos_x: int/float - x position of Mallet
        :param pos_y: int/float - x position of Mallet
        :param mass: mass of Mallet
        :param player: Player - Mallet owner
        :param borders: list of tuples - borders in which mallet can move
        :return:
        """

        MalletInterface.__init__(self)
        PhysicsObject.__init__(self, pos_x, pos_y, mass, radius, borders)
        self._player = player
        self.load_image()