예제 #1
0
    def fireSideEngine(self, s_power, direction, create_particle,
                       record_metrics):

        if self.sensor.sense() == 2 and direction > 0:
            record_metrics({"Fs": 0}, "actions")
            return None
        elif self.sensor.sense() == 1 and direction < 0:
            record_metrics({"Fs": 0}, "actions")
            return None

        dispersion = self.np_random.uniform(-0.1, +0.1)
        impulse_pos = side_engine_impulse_position(self.body, direction,
                                                   config.SIDE_ENGINE_HEIGHT,
                                                   config.SIDE_ENGINE_AWAY)

        if self.SIDE_ENGINE_POWER:
            p = create_particle(0.7, impulse_pos[0], impulse_pos[1], s_power)
            p.coldGas = True

            Fx, Fy = engine_impulse(direction * self.SIDE_ENGINE_POWER *
                                    s_power,
                                    self.body.angle,
                                    dispersion=dispersion,
                                    orientation=math.pi / 2)

            record_metrics({"Fs": math.sqrt(Fx * Fx + Fy * Fy)}, "actions")

            p.ApplyLinearImpulse((Fx, Fy), impulse_pos, True)
            self.body.ApplyLinearImpulse((-Fx, -Fy), impulse_pos, True)
예제 #2
0
    def fireMainEngine(self, m_power, alpha, create_particle, record_metrics):

        dispersion = self.np_random.uniform(-0.1, +0.1)
        impulse_pos = (self.body.position[0], self.body.position[1])

        if self.MAIN_ENGINE_POWER:
            p = create_particle(
                3.5, impulse_pos[0], impulse_pos[1], m_power
            )  # particles are just a decoration, 3.5 is here to make particle speed adequate
            p.coldGas = False

            Fx, Fy = engine_impulse(self.MAIN_ENGINE_POWER * m_power,
                                    self.body.angle, alpha, dispersion)
            record_metrics({
                "Ft": math.sqrt(Fx * Fx + Fy * Fy),
                "alpha": alpha
            }, "actions")

            p.ApplyLinearImpulse((-Fx, -Fy), impulse_pos, True)
            self.body.ApplyLinearImpulse((Fx, Fy), impulse_pos, True)
            return Fx, Fy, impulse_pos
 def test_engine_impulse_edge(self):
     Fx, Fy = physics.engine_impulse(0, math.pi, math.pi, math.pi)
     expected_Fx = 0
     expected_Fy = 0
     assert round(Fx, 5) == expected_Fx and round(Fy, 5) == expected_Fy
 def test_engine_impulse_90_degree_orientation_with_dispersion(self):
     Fx, Fy = physics.engine_impulse(500, 0, 0.1, math.pi / 2)
     expected_Fx = 497.50208
     expected_Fy = -49.91671
     assert round(Fx, 5) == expected_Fx and round(Fy, 5) == expected_Fy
 def test_engine_impulse_90_degree_orientation(self):
     Fx, Fy = physics.engine_impulse(500, 0, 0, math.pi / 2)
     expected_Fx = 500
     expected_Fy = 0
     assert round(Fx, 5) == expected_Fx and round(Fy, 5) == expected_Fy
 def test_engine_impulse_negative_60_degree(self):
     Fx, Fy = physics.engine_impulse(424.264068712, -math.pi / 3, 0, 0)
     expected_Fx = 367.42346
     expected_Fy = 212.13203
     assert round(Fx, 5) == expected_Fx and round(Fy, 5) == expected_Fy
 def test_engine_impulse_45_degreee_with_dispersion(self):
     Fx, Fy = physics.engine_impulse(424.264068712, 0, 0.1,
                                     math.pi / 4 - 0.1)
     expected_Fx = 300
     expected_Fy = 300
     assert round(Fx, 5) == expected_Fx and round(Fy, 5) == expected_Fy
 def test_engine_impulse_0_degree(self):
     Fx, Fy = physics.engine_impulse(300, 0, 0, 0)
     assert Fx == 0 and Fy == 300