From 66b4db91c7671c19fe22c4da913911b953597323 Mon Sep 17 00:00:00 2001 From: Paul Vincent Craven Date: Fri, 17 Apr 2020 16:33:42 -0500 Subject: [PATCH] Add unit tests for line of sight --- tests/unit2/test_line_of_sight.py | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/unit2/test_line_of_sight.py diff --git a/tests/unit2/test_line_of_sight.py b/tests/unit2/test_line_of_sight.py new file mode 100644 index 000000000..42f8c4b7a --- /dev/null +++ b/tests/unit2/test_line_of_sight.py @@ -0,0 +1,41 @@ +import arcade + +def test_line_of_sight(): + player = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png") + player.center_x = 50 + player.center_y = 350 + + enemy = arcade.Sprite(":resources:images/animated_characters/female_person/femalePerson_idle.png") + enemy.center_x = 150 + enemy.center_y = 350 + + wall_list = arcade.SpriteList(use_spatial_hash=True) + + result = arcade.has_line_of_sight(player.position, enemy.position, wall_list) + assert result + + result = arcade.has_line_of_sight(player.position, enemy.position, wall_list, 2000) + assert result + + result = arcade.has_line_of_sight(player.position, enemy.position, wall_list, 20) + assert not result + + wall = arcade.Sprite(":resources:images/tiles/grassCenter.png") + wall.center_x = 0 + wall.center_y = 0 + wall_list.append(wall) + + result = arcade.has_line_of_sight(player.position, enemy.position, wall_list) + assert result + + wall.center_x = 100 + wall.center_y = 350 + + result = arcade.has_line_of_sight(player.position, enemy.position, wall_list) + assert not result + + wall.center_x = 100 + wall.center_y = 450 + + result = arcade.has_line_of_sight(player.position, enemy.position, wall_list) + assert result