private void processPlayerBeginCollision(Entity playerEntity, Entity otherEntity) {
    TypeComponent typeComponent = ComponentMappers.TYPE.get(otherEntity);
    CapsuleControlComponent capsuleControlComponent =
        ComponentMappers.CAPSULE_CONTROL.get(playerEntity);
    StateComponent stateComponent = ComponentMappers.STATE.get(otherEntity);
    if (typeComponent.type == GameObjectType.TYPE_SAFE_CAPSULE
        && capsuleControlComponent == null
        && stateComponent.state == States.STATE_FREE) {
      stateComponent.state = States.STATE_BUSY;
      Body playerBody = ComponentMappers.PHYSIC.get(playerEntity).body;
      Body safeCapsuleBody = ComponentMappers.PHYSIC.get(otherEntity).body;
      playerBody.getFixtureList().get(0).setSensor(true);

      Vector2 posDiff = playerBody.getWorldCenter().sub(playerBody.getPosition()).cpy();
      playerBody.setTransform(safeCapsuleBody.getWorldCenter().sub(posDiff), playerBody.getAngle());

      WeldJointDef jointDef = new WeldJointDef();
      jointDef.initialize(playerBody, safeCapsuleBody, safeCapsuleBody.getWorldCenter());
      safeCapsuleBody.getWorld().createJoint(jointDef);

      JetpackControlComponent jetpackControlComponent = ComponentMappers.JETPACK.get(playerEntity);
      jetpackControlComponent.isActive = false;
      TurnControlComponent turnControlComponent = ComponentMappers.CONTROL.get(playerEntity);
      turnControlComponent.isActive = false;
      PooledEngine engine = (PooledEngine) this.getEngine();
      playerEntity.add(
          engine
              .createComponent(CapsuleControlComponent.class)
              .init(jetpackControlComponent.jetpackActivateKey));
    }
    if (typeComponent.type == GameObjectType.TYPE_ASTEROID) {
      Body playerBody = ComponentMappers.PHYSIC.get(playerEntity).body;
      if (!playerBody.getFixtureList().get(0).isSensor()) {
        OxygenComponent oxygenComponent = ComponentMappers.OXYGEN.get(playerEntity);
        if (oxygenComponent != null)
          oxygenComponent.addModificator(OxygenModificator.createInstantAsteroidModificator());
      }
    }
  }
Beispiel #2
0
 public static Joint addWeld(World world, Body bodyA, Body bodyB, Vector2 anchor) {
   WeldJointDef joint = new WeldJointDef();
   joint.initialize(bodyA, bodyB, anchor);
   return world.createJoint(joint);
 }