def test_collide_animals(): """Collide two animals together""" animal1 = Animal() animal2 = Animal() animal1.velocity = [1, 1] animal2.velocity = [-1, -1] animal1.put(0, 0) animal2.put(1, 1) collide_animals(animal1, animal2) assert_array_almost_equal(animal1.velocity, [-1, -1]) assert_array_almost_equal(animal2.velocity, [1, 1])
def sample_1(): animal1 = Animal(shape="E", color="red", size=45, mass=2, exertion_magnitude=40, max_health=50) animal2 = Animal(shape="W", color="orange", size=30, mass=1, exertion_magnitude=20, max_health=40, damage_infliction_magnitude=.2) animal3 = Animal(shape="W", color="orange", size=30, mass=1, exertion_magnitude=20, max_health=40, damage_infliction_magnitude=.2) animal1.put_relative(5, 5, screen) animal2.put_relative(95, 95, screen) animal3.put_relative(90, 90, screen) animal1.velocity = [0, 30] animal2.velocity = [0, -30] animal3.velocity = [0, -30] animal1.also_likes_to_eat(animal2, animal3) animal2.also_likes_to_eat(animal1) animal3.also_likes_to_eat(animal1) engine.add_animals(animal1, animal2, animal3)
def test_collide_animal_into_wall(): animal = Animal() screen = pygame.Surface((600, 600)) gameboard = GameBoard(screen) # Send the animal shooting into the top left corner animal.velocity = [-10, -10] collide_animal_into_wall(animal, gameboard.walls["top"]) assert_array_almost_equal(animal.velocity, [-10, 10]) # Toward the left wall now collide_animal_into_wall(animal, gameboard.walls["left"]) assert_array_almost_equal(animal.velocity, [10, 10]) # Toward the bottom wall now collide_animal_into_wall(animal, gameboard.walls["bottom"]) assert_array_almost_equal(animal.velocity, [10, -10]) # Toward the right wall now collide_animal_into_wall(animal, gameboard.walls["right"]) assert_array_almost_equal(animal.velocity, [-10, -10])