コード例 #1
0
  /*
   *               __
   *              /  \
   *              \  /
   *   +       /   ""
   *   |\    |/
   *   | \   +--
   *   +--+
   */
  @Test
  public void testTriangleCircleCollisionMovement_BottomLeft_Edge() {
    DummyGameLayer l =
        new DummyGameLayer(
            this.mapWidth,
            this.mapHeight,
            new DummyNoCollisionTileMap(this.mapWidth, this.mapHeight),
            this.expMapScale);

    DummyNoTileCollisionEntity e1 = new DummyNoTileCollisionEntity();
    l.addEntity(e1);
    e1.addCollisionGeo(1 / 3f, 1 / 3f, new CollisionTriangle(e1, 0f, 0f, 0f, 1f, 1f, 0f));

    DummyNoTileCollisionEntity e2 = new DummyNoTileCollisionEntity();
    l.addEntity(e2);
    e2.addCollisionGeo(1 / 2f, 1 / 2f, new CollisionCircle(e2, 1 / 2f));

    e1.setPosition(10, 10);
    e2.setPosition(20, 20);

    assertEquals("0-1-0-0-0-0", e1.dummyCtrSignSummary());
    assertEquals("0-1-0-0-0-0", e2.dummyCtrSignSummary());

    for (int i = 0; i < 8000; i++) e2.movePosition(-0.01f, -0.01f);

    assertEqualsExt(new Vector2(10.34979f, 10.35734f), e2.getPosition(), 0.00005f);

    assertEquals(null, l.collisionMap().getFirstCollider(e1.listCollisionGeometries().next()));
    assertEquals(null, l.collisionMap().getFirstCollider(e2.listCollisionGeometries().next()));

    assertEquals("0-1-0-0-1-0", e2.dummyCtrSignSummary());
    assertEquals("0-1-0-0-0-1", e1.dummyCtrSignSummary());
  }
コード例 #2
0
  @Test
  public void testTriangleCircleCollision_Inside() {
    DummyGameLayer l =
        new DummyGameLayer(
            this.mapWidth,
            this.mapHeight,
            new DummyNoCollisionTileMap(this.mapWidth, this.mapHeight),
            this.expMapScale);

    DummyNoTileCollisionEntity e1 = new DummyNoTileCollisionEntity();
    l.addEntity(e1);
    e1.addCollisionGeo(1 / 3f, 1 / 3f, new CollisionTriangle(e1, 1f, 0f, 1f, 1f, 0f, 1f));

    DummyNoTileCollisionEntity e2 = new DummyNoTileCollisionEntity();
    l.addEntity(e2);
    e2.addCollisionGeo(1 / 2f, 1 / 2f, new CollisionCircle(e2, 0.1f));

    e1.setPosition(100f, 100f);
    e2.setPosition(0f, 0f);

    assertEquals("0-1-0-0-0-0", e1.dummyCtrSignSummary());
    assertEquals("0-1-0-0-0-0", e2.dummyCtrSignSummary());

    e2.setPosition(10.12f, 10.12f);
    e1.setPosition(10f, 10f);

    assertEquals(
        e1.listCollisionGeometries().next(),
        l.collisionMap().getFirstCollider(e2.listCollisionGeometries().next()));
    assertEquals(
        e2.listCollisionGeometries().next(),
        l.collisionMap().getFirstCollider(e1.listCollisionGeometries().next()));

    assertEquals("0-1-1-0-0-0", e1.dummyCtrSignSummary());
    assertEquals("0-1-0-1-0-0", e2.dummyCtrSignSummary());
  }