def on_enter(id_: StateId):
        from api.sax_engine.vector import Vector2
        x, _ = player.physics_data.velocity
        player.physics_data.velocity = Vector2(x, player.physics_data.JUMP_VELOCITY)
        player.shared_data.jumps_left -= 1

        if id_ == StateId.on_ground:
            from api.sax_engine.core import add_content_to_scene
            from prefabs.debug import PointMarker
            add_content_to_scene(player.scene, PointMarker(player.position, (255, 0, 0)))
 def test_rect2ray(self):
     b = Rectangle(Point(0, 0), Vector2(2, 2))
     r1 = create_ray(Point(-1, -1), Vector2(1, 1))
     self.assertTrue(b.intersect(r1))
     r2 = create_ray(Point(1, 1), Vector2(3, 3))
     self.assertTrue(b.intersect(r2))
     r3 = create_ray(Point(0, 0), Vector2(2, 2))
     self.assertTrue(b.intersect(r3))
     r4 = create_ray(Point(-1, -1), Vector2(3, 3))
     self.assertTrue(b.intersect(r4))
     r5 = create_ray(Point(-1, 0), Vector2(1, 0), 0.99)
     self.assertFalse(b.intersect(r5))
     r6 = create_ray(Point(3, 0), Vector2(-1, 0), 0.99)
     self.assertFalse(b.intersect(r6))
     r7 = create_ray(Point(-1, 1), Vector2(0, -1))
     self.assertFalse(b.intersect(r7))
     r8 = create_ray(Point(-1, 1), Vector2(1, -1))
     self.assertTrue(b.intersect(r8))
     r9 = create_ray(Point(-1, 1), Vector2(2, -1))
     self.assertTrue(b.intersect(r9))
 def test_rect2point(self):
     b = Rectangle(Point(0, 0), Vector2(2, 2))
     p1 = Point(1, 1)
     self.assertTrue(b.intersect(p1))
     p2 = Point(0, 0)
     self.assertTrue(b.intersect(p2))
     p3 = Point(2, 2)
     self.assertTrue(b.intersect(p3))
     p4 = Point(-.1, 1)
     self.assertFalse(b.intersect(p4))
     p5 = Point(3, 1)
     self.assertFalse(b.intersect(p5))
 def test_rect2rect(self):
     b = Rectangle(Point(0, 0), Vector2(2, 2))
     self.assertTrue(b.intersect(b))
     b1 = Rectangle(Point(1, 1), Vector2(2, 2))
     self.assertTrue(b.intersect(b1))
     b2 = Rectangle(Point(2, 2), Vector2(2, 2))
     self.assertTrue(b.intersect(b2))
     b3 = Rectangle(Point(2.1, 2.1), Vector2(2, 2))
     self.assertFalse(b.intersect(b3))
     b4 = Rectangle(Point(1, 1), Vector2(-2, -2))
     self.assertTrue(b.intersect(b4))
     b5 = Rectangle(Point(2, 2), Vector2(-2, -2))
     self.assertTrue(b.intersect(b5))
     b6 = Rectangle(Point(0, 0), Vector2(-2, -2))
     self.assertTrue(b.intersect(b6))
     b7 = Rectangle(Point(-.1, -.1), Vector2(-2, -2))
     self.assertFalse(b.intersect(b7))
    def on_enter(id_: StateId):
        from api.sax_engine.vector import Vector2
        x, _ = player.physics_data.velocity
        player.physics_data.velocity = Vector2(x, player.physics_data.JUMP_VELOCITY)
        player.shared_data.jumps_left -= 1

        if id_ == StateId.on_ground:
            from api.sax_engine.core import add_content_to_scene
            from prefabs.debug import PointMarker
            from api.sax_engine.geometry import Point
            if player.physics_data.absorb.x < 0:
                p = player.position
            else:
                x, y = player.position
                p = Point(x + player.physics_data.size, y)
            add_content_to_scene(player.scene, PointMarker(p, (255, 0, 0), 5))
 def test_rect2circle(self):
     b = Rectangle(Point(0, 0), Vector2(2, 2))
     c1 = Circle(Point(1, 1), 1)
     self.assertTrue(b.intersect(c1))
     c2 = Circle(Point(1, 1), 5)
     self.assertTrue(b.intersect(c2))
     c3 = Circle(Point(0, 0), 1)
     self.assertTrue(b.intersect(c3))
     c4 = Circle(Point(-1, 1), 1)
     self.assertTrue(b.intersect(c4))
     c5 = Circle(Point(-1, 1), 0.99)
     self.assertFalse(b.intersect(c5))
     c6 = Circle(Point(3, 3), math.sqrt(2))
     self.assertTrue(b.intersect(c6))
     c7 = Circle(Point(3.01, 3.01), math.sqrt(2))
     self.assertFalse(b.intersect(c7))
Beispiel #7
0
 def __init__(self, target: _Content):
     self.target = target
     self.velocity = Vector2(0, 0)
 def __init__(self):
     self.jumps_left = 0
     self.look_direction = Vector2(1, 0)
 def __init__(self):
     self.velocity = Vector2(0, 0)
     self.absorb = Vector2(0, 0)
     self.size = Vector2(1, 2)
def grid_size(grid: Grid) -> Vector2:
    return Vector2(len(grid), len(grid[0]))
 def on_exit(id_: StateId):
     actor.physics_data.size = Vector2(1.2, 0.6)
     invert_lookdir(actor)
 def on_enter(id_: StateId):
     actor.physics_data.size = Vector2(0.5, 1.2)
     halt_movement(actor, halt_h=True)