@Override
 protected void controlUpdate(float tpf) {
   if (chasingBall) {
     // moveTo(ball.getWorldTranslation());
   }
   lookAt(ball.getWorldTranslation());
 }
Example #2
0
  private void injectModel(Model e) throws Exception {
    if (model.name().length() > 0) e.setName(model.name());

    if (!model.asset().isEmpty()) {
      Node n = (Node) EntityManager.getAssetManager().loadModel(model.asset());
      if (model.smartReference()) n.setUserData(ENTITY_MODEL_REFERENCE, e);

      for (Field f : subModels) {
        SubModelComponent a = EntityManager.getAnnotation(SubModelComponent.class, f);
        if (a != null) {
          Spatial s = n.getChild(a.name());
          if (s != null) {
            OnlyPosition opA = EntityManager.getAnnotation(OnlyPosition.class, f);
            if (opA != null) {
              Vector3f pos = null;
              if (opA.positionVector() == OnlyPosition.TYPE_POSITION.LOCAL) {
                pos = s.getLocalTranslation().clone();
              } else {
                pos = s.getWorldTranslation().clone();
              }
              f.set(e, pos);
            } else {
              if (a.rayPickResponse() && s instanceof Geometry) {
                s.setUserData(ENTITY_GEOMETRY_REFERENCE, e);
              }

              f.set(e, s);
            }
            if (a.dettach() && s.getParent() != null) s.getParent().detachChild(s);
          } else {
            log.warning("No submodel with name: " + a.name());
          }
        } else {
          SubModelMapComponent anot = EntityManager.getAnnotation(SubModelMapComponent.class, f);
          if (anot != null) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            getChildMap(map, n, n, anot.nameStartsWith(), anot.rayPickResponse());

            f.set(e, map);
          }
        }
      }

      e.attachChild(n);
    }
  }
Example #3
0
 public Vector3f getPosition() {
   return followBox.getWorldTranslation();
 }
Example #4
0
  @Override
  public void simpleUpdate(float tpf) {
    for (Planet planet : planets) {
      planet.getGeom().rotate(0, 0, planet.getRotationSpeed() * tpf);
      planet.getPivot().rotate(0, planet.getTranslationSpeed() * tpf, 0);
    }

    for (Spatial spatial : explosions.getChildren()) {
      ParticleEmitter explosion = (ParticleEmitter) spatial;
      if (explosion.getNumVisibleParticles() < 1) {
        explosion.removeFromParent();
      }
    }

    Vector3f rotation = new Vector3f(0, 0, 0);
    if (left) {
      rotation.addLocal(0, 1, 0);
    }
    if (right) {
      rotation.addLocal(0, -1, 0);
    }
    if (up) {
      rotation.addLocal(1, 0, 0);
    }
    if (down) {
      rotation.addLocal(-1, 0, 0);
    }
    if (leftSide) {
      rotation.addLocal(0, 0, 1);
    }
    if (rightSide) {
      rotation.addLocal(0, 0, -1);
    }

    Vector3f transformed = new Vector3f(0, 0, 0);
    spaceship.getLocalRotation().mult(rotation, transformed);
    spaceship.getControl().setAngularVelocity(transformed);

    Vector3f movement = new Vector3f(0, 0, 0);
    if (moving) {
      spaceship.getWorldRotation().mult(new Vector3f(0, 0, -6), movement);
    }
    spaceship.getControl().setLinearVelocity(movement);

    bloom.setBloomIntensity(bloom.getBloomIntensity() + (bloomDirection * tpf / 8));
    if (bloom.getBloomIntensity() > 4) {
      bloomDirection = -1;
    }
    if (bloom.getBloomIntensity() < 2) {
      bloomDirection = 1;
    }

    Vector3f direction = spaceship.getRear().getWorldTranslation().subtract(cam.getLocation());
    float magnitude = direction.length();
    if (magnitude > 0) {
      cam.setLocation(
          cam.getLocation().add(direction.normalize().mult(tpf * magnitude * magnitude / 2)));
    }
    cam.lookAt(spaceship.getFront().getWorldTranslation(), Vector3f.UNIT_Y);

    for (Spatial spatial : asteroids.getChildren()) {
      if (spatial.getWorldTranslation().subtract(Vector3f.ZERO).length() > 200) {
        spatial.removeFromParent();
      }
    }

    if (Math.random() < 0.01 && asteroids.getChildren().size() < MAX_ASTEROIDS) {
      generateRandomAsteroid();
    }

    for (Spatial spatial : lasers.getChildren()) {
      Laser laser = (Laser) spatial;
      if (laser.getWorldTranslation().subtract(Vector3f.ZERO).length() > 200) {
        bap.getPhysicsSpace().remove(laser.getControl());
        laser.removeFromParent();
        continue;
      }
      laser.move(laser.getDirection().mult(laser.getSpeed()));
    }

    scoreText.setText("Score: " + score);
  }