Exemplo n.º 1
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()
Exemplo n.º 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
Exemplo n.º 3
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
Exemplo n.º 4
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)))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 7
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)
Exemplo n.º 8
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
Exemplo n.º 9
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)
Exemplo n.º 10
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
Exemplo n.º 11
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)
Exemplo n.º 12
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
Exemplo n.º 13
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))
Exemplo n.º 14
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