Example #1
0
    def test_actor_position_changes_on_tick_notification_when_on_move_vector_is_not_zero_normalized_with_the_fps(
            self):
        Game.set_display_configuration(DisplayConfiguration(800, 600, 30))
        an_actor = Actor()
        an_actor.position = Point3D(5, 5, 5)
        an_actor.move_vector = Vector3D(15, -15, 30)

        an_actor.end_tick()

        assert an_actor.position == Point3D(5.5, 4.5, 6)
Example #2
0
    def __init__(self):
        super().__init__()
        body = Polygon([Point3D(5, 0, 0), Point3D(0, 5, 0), Point3D(5, 5, 0)])

        body.translate(Vector3D(0, 0, 0, origin=body.center))

        self.add_component(HitboxComponent(body))
        self.add_component(PolygonComponent(body))
        self.position = Point3D(-15, 5, 0)
        self.spinning_speed = 3
Example #3
0
 def __init__(self):
     lifespan = random.uniform(0.5, 2)
     super().__init__(lifespan)
     self.add_component(
         PolygonComponent(
             Polygon([
                 Point3D(-0.05, 0, 0),
                 Point3D(0.05, 0.1, 0),
                 Point3D(0.05, -0.1, 0)
             ])))
     self.add_component(ColorComponent(RGB(0.3, 0.7, 0.3)))
Example #4
0
 def __init__(self):
     super().__init__()
     body = Polygon([
         Point3D(-1, -1, 0),
         Point3D(1, -1, 0),
         Point3D(1, 1, 0),
         Point3D(-1, 1, 0)
     ])
     self.add_component(ColorComponent(RGB(1, 0, 0.5)))
     self.add_component(HitboxComponent(body))
     self.add_component(PolygonComponent(body))
     self.position = Point3D(0, 10, 0)
Example #5
0
 def __init__(self):
     super().__init__()
     self.rgb = RGB(0, 1, 0)
     polygon = Polygon(
         [Point3D(0, 0, 0),
          Point3D(0, 1, 0),
          Point3D(1, 0.5, 0)])
     self.add_component(PolygonComponent(polygon))
     self.add_component(HitboxComponent(polygon, is_collision_source=True))
     self.add_component(ColorComponent(self.rgb))
     self.position.x = 15
     self.position.y = 15
Example #6
0
 def __init__(self):
     lifespan = random.uniform(2, 4)
     super().__init__(lifespan)
     body = Polygon(
         [Point3D(-0.1, 0, 0),
          Point3D(0.1, 0.2, 0),
          Point3D(0.1, -0.2, 0)])
     self.add_component(PolygonComponent(body))
     self.add_component(HitboxComponent(body))
     self.add_component(ColorComponent(RGB(0.3, 0.7, 0.3)))
     # self.spinning_speed = 30
     self.collision_mask = 0x01
Example #7
0
 def __init__(self):
     super().__init__()
     body = Polygon([
         Point3D(-2.5, -2.5, 0),
         Point3D(2.5, -2.5, 0),
         Point3D(2.5, 2.5, 0),
         Point3D(-2.5, 2.5, 0)
     ])
     self.add_component(HitboxComponent(body))
     self.add_component(PolygonComponent(body))
     self.position = Point3D(15, -10, 0)
     self.spinning_speed = -5
Example #8
0
 def __init__(self):
     super().__init__()
     body = Polygon([
         Point3D(-1, -1, 0),
         Point3D(1, -1, 0),
         Point3D(1, 1, 0),
         Point3D(-1, 1, 0)
     ])
     self.add_component(ColorComponent(RGB(0, 0.7, 0)))
     self.add_component(OutlineComponent(RGB(1, 0, 0), thickness=4))
     self.add_component(HitboxComponent(body))
     self.add_component(PolygonComponent(body))
     self.position = Point3D(-3, 8, 0)
Example #9
0
 def __init__(self):
     super().__init__()
     body = Polygon(
         [Point3D(0, 0, 0),
          Point3D(-3, -1, 0),
          Point3D(-3, 1, 0)])
     self.add_component(HitboxComponent(body))
     self.add_component(PolygonComponent(body))
     self.position = Point3D(-10, 15, 0)
     particle_emitter = ParticleEmitterComponent(TriangleParticle,
                                                 10,
                                                 Vector3D(6, 0, 0),
                                                 speed_variability=0.5,
                                                 direction_variability=60)
     self.add_component(particle_emitter)
Example #10
0
 def __init__(self):
     super().__init__()
     self.rgb = RGB(1, 1, 1)
     polygon = Polygon(
         [Point3D(0, 0, 0),
          Point3D(0, 1, 0),
          Point3D(1, 0.5, 0)])
     self.add_component(PolygonComponent(polygon))
     self.add_component(HitboxComponent(polygon, is_collision_source=True))
     self.add_component(ColorComponent(self.rgb))
     self.subscribe_to_event(collision_event.CollisionEvent,
                             self.__on_collision_event)
     self.collision_sound = Audio.new_sound(
         'sound_samples/rubber_ducky.wav')
     self.__collision_timeout = 0
     self.collision_mask = 0x01
Example #11
0
 def __to_polygon(cls, _geometry, position):
     _polygon = Polygon([
         cls.__decouple_point_from_position(
             Point3D(point_2d_tuple[0], point_2d_tuple[1], 0), position)
         for point_2d_tuple in _geometry.exterior.coords
     ])
     return _polygon
Example #12
0
 def __init__(self):
     self.__position = Point3D(0, 0, 0)
     self.__move_vector = Vector3D(0, 0, 0)
     self.__rotation = Rotation(rotation_callback=self.__rotation_callback)
     self.__spinning_speed = 0
     self.__event_handler = event_handler.EventHandler()
     self.__components = []
     self.__collision_mask = 0x0
Example #13
0
    def test_should_update_move_vector_when_receiving_arrow_key_press_event(self):
        event = key_event.KeyEventPress(key_event.Key.RIGHT_ARROW)
        actor = PlayerActor()

        actor.receive_event(event)
        actor.end_tick()

        assert Point3D(15, 0, 0) == actor.move_vector
Example #14
0
    def test_setting_a_component(self):
        point = Point3D(0, 0, 0)

        point.x = 1
        point.y = 2
        point.z = 3

        assert (1, 2, 3) == point.as_tuple()
Example #15
0
    def test_should_create_3D_point(self):
        point = Point3D(x=2, y=4, z=6)

        assert 2 == point.x
        assert 4 == point.y
        assert 6 == point.z
        assert (2, 4, 6) == point.as_tuple()
        assert '(2,4,6)' == '{0}'.format(point)
Example #16
0
def start_engine_poc():
    display_config = DisplayConfiguration(width_px=800,
                                          height_px=600,
                                          fps=60,
                                          scaled=True)
    camera = Camera(Point3D(0, 0, -50), Rotation(0, 0, 0), 45, 0.1, 100.0)
    initial_scene = scene.Scene
    Game.initialize(display_config, camera, initial_scene)
    __add_some_actors(Game.current_scene())
    Game.run()
Example #17
0
def __add_some_actors(_scene):
    _scene.add_actor(APlayerActor())
    _scene.add_actor(RotatingTriangle())
    _scene.add_actor(RotatingSquare())
    _scene.add_actor(ColoredSquare())
    _scene.add_actor(ColoredAndOutlinedSquare())
    _scene.add_actor(EmitterActor())
    _scene.add_actor(VeryCompoundActor())
    _scene.add_actor(MovingActor())
    fps_actor = FPSActor()
    fps_actor.position = Point3D(25, -20, 0)
    _scene.add_actor(fps_actor)
Example #18
0
 def __init__(self):
     super().__init__()
     body = Polygon([Point3D(0, 0, 0), Point3D(3, 1, 0), Point3D(3, -1, 0)])
     self.add_component(PolygonComponent(body))
     self.position = Point3D(10, 10, 0)
     self.add_component(ColorComponent(RGB(0.2, 0.2, 1)))
     movement_node_list = [
         MoveComponentNode(Vector3D(-5, 0, 0), 1),
         MoveComponentNode(Vector3D(0, -5, 0), 1),
         MoveComponentNode(Vector3D(5, 0, 0), 1),
         MoveComponentNode(Vector3D(0, 5, 0), 1),
     ] * 50
     self.add_component(MoveComponent(movement_node_list))
     particle_emitter = ParticleEmitterComponent(RotatingParticle,
                                                 10,
                                                 Vector3D(-6, 0, 0),
                                                 speed_variability=0,
                                                 direction_variability=0)
     shoot_pattern_node_list = [
         ShootPatternComponentNode(particle_emitter, 0.3),
         ShootPatternComponentNode(None, 0.3)
     ] * 999
     self.add_component(ShootPatternComponent(shoot_pattern_node_list))
Example #19
0
 def __init__(self):
     super().__init__()
     body1 = Polygon([
         Point3D(0, -0.25, 0),
         Point3D(3, -0.25, 0),
         Point3D(3, 0.25, 0),
         Point3D(0, 0.25, 0)
     ])
     body2 = Polygon(
         [Point3D(3.5, -1, 0),
          Point3D(3.5, 1, 0),
          Point3D(5, 0, 0)])
     polygon1 = PolygonComponent(body1)
     polygon1.add_component(ColorComponent(RGB(1, 0, 0)))
     polygon1.add_component(OutlineComponent(RGB(0, 0, 1), thickness=4))
     polygon2 = PolygonComponent(body2)
     polygon2.add_component(ColorComponent(RGB(0, 1, 0)))
     polygon2.add_component(OutlineComponent(RGB(0.5, 0, 0.5), thickness=8))
     self.add_component(HitboxComponent(body1))
     self.add_component(polygon1)
     self.add_component(HitboxComponent(body2))
     self.add_component(polygon2)
     self.position = Point3D(5, -15, 0)
     self.spinning_speed = 0.6
     self.subscribe_to_event(collision_event.CollisionEvent,
                             self.__on_collision_event)
     self.collision_sound = Audio.new_sound(
         'sound_samples/metal_crunch.wav')
     particle_emitter = ParticleEmitterComponent(RotatingParticle,
                                                 5,
                                                 Vector3D(9, 0, 0),
                                                 speed_variability=0.1,
                                                 direction_variability=0.1)
     particle_emitter.position_offset_relative_to_actor = Vector3D(5, 0, 0)
     self.add_component(particle_emitter)
     self.collision_mask = 0x01
Example #20
0
 def test_comparing_two_vectors(self):
     assert Vector3D(1, 2, 3) == Vector3D(1, 2, 5, origin=Point3D(0, 0, 2))
     assert Vector3D(1, 2, 3) != Vector3D(1, 2, 5)
Example #21
0
    def setUp(self):
        self.actor1 = DummyActor()
        self.actor2 = DummyActor()
        self.actor3 = DummyActor()
        self.actor1.position = Point3D(0, 0, 0)
        self.actor2.position = Point3D(0.5, 0, 0)
        self.actor3.position = Point3D(3, 3, 0)

        self.actor1.collision_mask = 0x01
        self.actor2.collision_mask = 0x01
        self.actor3.collision_mask = 0x01

        component1 = HitboxComponent(Polygon(
            [Point3D(0, 0, 0),
             Point3D(1, 0, 0),
             Point3D(0, 1, 0)]),
                                     is_collision_source=True)
        self.actor1.add_component(component1)

        component2 = HitboxComponent(
            Polygon([Point3D(0, 0, 0),
                     Point3D(1, 1, 0),
                     Point3D(0, 1, 0)]))
        self.actor2.add_component(component2)

        component3 = HitboxComponent(
            Polygon([
                Point3D(0, 0, 0),
                Point3D(1, 0, 0),
                Point3D(1, 1, 0),
                Point3D(0, 1, 0)
            ]))
        self.actor3.add_component(component3)

        self.collision_engine = CollisionEngine()
Example #22
0
    def test_creating_actor_at_default_position(self):
        an_actor = Actor()

        assert Point3D(0, 0, 0) == an_actor.position
Example #23
0
    def test_changing_actor_position(self):
        an_actor = Actor()

        an_actor.position = Point3D(3, 2, 1)

        assert Point3D(3, 2, 1) == an_actor.position
Example #24
0
 def test_raising_exception_when_constructing_a_polygon_with_insufficient_points(
         self):
     self.assertRaises(
         PolygonConstructionError, Polygon,
         [Point3D(0, 0, 0), Point3D(1, 1, 1)])
Example #25
0
    def test_creating_a_polygon(self):
        point_list = [Point3D(0, 0, 0), Point3D(1, 1, 1), Point3D(2, 2, 2)]

        polygon = Polygon(point_list)

        assert polygon.point_list == point_list
Example #26
0
    def test_comparing_two_points_return_true_when_are_equal(self):
        p1 = Point3D(1, 2, 3)
        p2 = Point3D(1, 2, 3)

        assert p1 == p2
Example #27
0
    def test_comparing_two_points_return_false_when_are_not_equal(self):
        p1 = Point3D(1, 3, 0)
        p2 = Point3D(1, 2, 0)

        assert p1 != p2
Example #28
0
    def test_adding_two_points(self):
        p1 = Point3D(1, 2, 3)
        p2 = Point3D(1, 2, 3)

        assert Point3D(2, 4, 6) == p1 + p2
Example #29
0
    def test_substracting_two_points(self):
        p1 = Point3D(3, 6, 9)
        p2 = Point3D(1, 2, 3)

        assert Point3D(2, 4, 6) == p1 - p2
Example #30
0
    def test_creating_a_3d_vector_setting_an_origin_point(self):
        vector = Vector3D(5, 6, 7, origin=Point3D(1, 3, 5))

        assert vector.x == 4
        assert vector.y == 3
        assert vector.z == 2