public void onAnalog(String name, float value, float tpf) {
    if ((Boolean) player.getUserData("alive")) {
      if (name.equals("mousePick")) {
        // shoot Bullet
        if (System.currentTimeMillis() - bulletCooldown > 83f) {
          bulletCooldown = System.currentTimeMillis();

          Vector3f aim = getAimDirection();
          Vector3f offset = new Vector3f(aim.y / 3, -aim.x / 3, 0);

          //                    init bullet 1
          Spatial bullet = getSpatial("Bullet");
          Vector3f finalOffset = aim.add(offset).mult(30);
          Vector3f trans = player.getLocalTranslation().add(finalOffset);
          bullet.setLocalTranslation(trans);
          bullet.addControl(
              new BulletControl(
                  aim, settings.getWidth(), settings.getHeight(), particleManager, grid));
          bulletNode.attachChild(bullet);

          //                    init bullet 2
          Spatial bullet2 = getSpatial("Bullet");
          finalOffset = aim.add(offset.negate()).mult(30);
          trans = player.getLocalTranslation().add(finalOffset);
          bullet2.setLocalTranslation(trans);
          bullet2.addControl(
              new BulletControl(
                  aim, settings.getWidth(), settings.getHeight(), particleManager, grid));
          bulletNode.attachChild(bullet2);

          sound.shoot();
        }
      }
    }
  }
  public void showCar() {
    for (int i = 0; i < 4; i++) {
      cars[i] = factory.getCar(car_names[i], assetManager);
      car_con[i] = cars[i].getControl(VehicleControl.class);
    }
    Camera camera = cam.clone();

    camera.setViewPort(.25f, .9f, .1f, .75f);
    carView = this.app.getRenderManager().createPostView("carview", camera);

    space.add(car_con[index]);
    dl = new DirectionalLight();
    localRootNode.addLight(dl);
    ai = new AmbientLight();
    localRootNode.addLight(ai);
    car_con[index].setPhysicsLocation(new Vector3f(0, 1, 0));
    localRootNode.attachChild(cars[index]);
    floor = assetManager.loadModel("Models/garage/garage.mesh.j3o");
    control = new RigidBodyControl(0);
    floor.addControl(control);
    control.setPhysicsLocation(Vector3f.ZERO);
    space.add(control);
    localRootNode.attachChild(floor);

    camera.setLocation(car_con[index].getPhysicsLocation().add(new Vector3f(3, 1f, 0)));
    camera.lookAt(car_con[index].getPhysicsLocation().add(new Vector3f(0, -1, 0)), Vector3f.UNIT_Y);
    dl.setDirection(camera.getDirection());

    carView.attachScene(localRootNode);
  }
 private void createBlackHole() {
   Spatial blackHole = getSpatial("Black Hole");
   blackHole.setLocalTranslation(getSpawnPosition());
   blackHole.addControl(new BlackHoleControl(particleManager, grid));
   blackHole.setUserData("active", false);
   blackHoleNode.attachChild(blackHole);
 }
 private void createWanderer() {
   Spatial wanderer = getSpatial("Wanderer");
   wanderer.setLocalTranslation(getSpawnPosition());
   wanderer.addControl(new WandererControl(settings.getWidth(), settings.getHeight()));
   wanderer.setUserData("active", false);
   enemyNode.attachChild(wanderer);
 }
 private void createSeeker() {
   Spatial seeker = getSpatial("Seeker");
   seeker.setLocalTranslation(getSpawnPosition());
   seeker.addControl(new SeekerControl(player));
   seeker.setUserData("active", false);
   enemyNode.attachChild(seeker);
 }
  public static Spatial AddModel(Vector3f position, String name) {
    s_Model = Main.s_AssetManager.loadModel("Models/tree.obj");

    s_Model.setLocalTranslation(position);
    s_Model.scale(0.8f);
    s_Model.setName(name);

    s_Model.setShadowMode(ShadowMode.CastAndReceive);

    CollisionShape collision = new CapsuleCollisionShape(0.5f, 1f);
    physicsControl = new RigidBodyControl(collision, 0);
    physicsControl.setKinematic(true);
    s_Model.addControl(physicsControl);
    Main.bulletAppState.getPhysicsSpace().add(s_Model);
    // Main.s_TreeNode.attachChild(s_Model);

    return s_Model;
  }
  public void setSpatial(Spatial model) {
    if (model == null) {
      removeFromPhysicsSpace();
      clearData();
      return;
    }
    targetModel = model;
    Node parent = model.getParent();

    Vector3f initPosition = model.getLocalTranslation().clone();
    Quaternion initRotation = model.getLocalRotation().clone();
    initScale = model.getLocalScale().clone();

    model.removeFromParent();
    model.setLocalTranslation(Vector3f.ZERO);
    model.setLocalRotation(Quaternion.IDENTITY);
    model.setLocalScale(1);
    // HACK ALERT change this
    // I remove the skeletonControl and readd it to the spatial to make sure it's after the
    // ragdollControl in the stack
    // Find a proper way to order the controls.
    SkeletonControl sc = model.getControl(SkeletonControl.class);
    model.removeControl(sc);
    model.addControl(sc);
    // ----

    removeFromPhysicsSpace();
    clearData();
    // put into bind pose and compute bone transforms in model space
    // maybe dont reset to ragdoll out of animations?
    scanSpatial(model);

    if (parent != null) {
      parent.attachChild(model);
    }
    model.setLocalTranslation(initPosition);
    model.setLocalRotation(initRotation);
    model.setLocalScale(initScale);

    logger.log(Level.INFO, "Created physics ragdoll for skeleton {0}", skeleton);
  }
  private void resetWallPhysics(PhysicsSpace space) {
    List<Spatial> children = ((Node) getTerrainNode().getChild("Walls")).getChildren();
    for (Spatial wallNode : children) {
      Spatial wall = ((Node) wallNode).getChild("Wall");
      wall.scale(6f);

      space.removeAll(wallNode);

      CollisionShape meshShape = CollisionShapeFactory.createMeshShape(wall);

      wall.scale(1f / 6f);
      RigidBodyControl wallPhysics = new RigidBodyControl(meshShape, 0);
      wallPhysics.setCollideWithGroups(CollisionGroups.NONE);

      wallPhysics.setFriction(0.5f);
      wall.addControl(wallPhysics);
      wall.getControl(RigidBodyControl.class).setCollisionGroup(CollisionGroups.WALLS);

      space.addAll(wall);
    }
  }
Exemple #9
0
  @Override
  public void simpleInitApp() {

    //        setUpKeys();
    flyCam.setEnabled(false);

    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

    Juggernaut = new Character(this, bulletAppState);

    setUpCameraBoxes();
    // Load in the level
    // Material m = assetManager.loadMaterial("Models/levelLayout - Update.mtl");
    Spatial map = assetManager.loadModel("Models/levelLayout - Update_cameraPos.obj");
    rootNode.attachChild(map);

    Material mark_mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    //       mark_mat.setColor("Color", ColorRGBA.White);
    //       mark.setMaterial(mark_mat);
    //        mark.setLocalTranslation(1f,1f,1f);
    //        rootNode.attachChild(mark);

    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(map);
    landscape = new RigidBodyControl(sceneShape, 0);
    map.addControl(landscape);
    landscape.setCollisionGroup(1);
    landscape.removeCollideWithGroup(2);

    //        //Load Ninja as filler for character model
    //        ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    //        //ninja.rotate(0, -1.5f, 0);
    //        ninja.scale(0.02f, 0.02f, 0.02f);
    //        ninja.setLocalTranslation(new Vector3f(341, 300, 0));
    //        //ninja.setMaterial(mark_mat);
    //        rootNode.attachChild(ninja);
    //        CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1f, 2f);
    //        player = new CharacterControl(capsuleShape, .05f);
    //        player.setJumpSpeed(50);
    //        player.setFallSpeed(50);
    //        player.setGravity(120);
    //        player.setPhysicsLocation(new Vector3f(1f,8f,1f));
    //        player.setViewDirection(new Vector3f(-1.0f, 0, 0));
    //        player.setCollideWithGroups(2);
    //
    //
    //
    //        playerDebug = player.createDebugShape(assetManager);
    //        ninja.addControl(player);
    //        rootNode.attachChild(playerDebug);
    //
    //        bulletAppState.getPhysicsSpace().add(player);
    bulletAppState.getPhysicsSpace().add(landscape);

    // Elevator 1
    elevator1 = new Geometry("Elevator1", new Box(4, 1, 5));
    elevator1.setLocalTranslation(304, 20, 0);
    elevator1.setMaterial(mark_mat);
    elvtr1 = new RigidBodyControl(10);

    elevator1.addControl(elvtr1);
    elvtr1.setFriction(1000.0f);
    elvtr1.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr1);
    rootNode.attachChild(elevator1);

    // Elevator 2
    elevator2 = new Geometry("Elevator2", new Box(4, 1, 5));
    elevator2.setLocalTranslation(192, 208, 0);
    elevator2.setMaterial(mark_mat);
    elvtr2 = new RigidBodyControl(1000000000);

    elevator2.addControl(elvtr2);
    elvtr2.setAngularDamping(100000.0f);
    elvtr2.setFriction(1000.0f);
    //        elvtr2.setKinematic(true);
    bulletAppState.getPhysicsSpace().add(elvtr2);
    rootNode.attachChild(elevator2);

    // Add lights to see the models
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);

    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White);
    rootNode.addLight(al);

    //        cam.setLocation(new Vector3f(player.getPhysicsLocation().x,
    // player.getPhysicsLocation().y + 5, player.getPhysicsLocation().z +40 ));
    //        cam.lookAt(player.getPhysicsLocation(), Vector3f.UNIT_Y);
    cam.setLocation(new Vector3f(0, 5, 40));
    cam.lookAt(new Vector3f(0, 5, 0), Vector3f.UNIT_Y);
  }
  @Override
  public void simpleInitApp() {
    //        setup camera for 2D games
    cam.setParallelProjection(true);
    cam.setLocation(new Vector3f(0, 0, 0.5f));
    getFlyByCamera().setEnabled(false);

    //        turn off stats (you can leave it on, if you want)
    setDisplayStatView(false);
    setDisplayFps(false);

    //        initializing the bloom filter
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    BloomFilter bloom = new BloomFilter();
    bloom.setBloomIntensity(2f);
    bloom.setExposurePower(2);
    bloom.setExposureCutOff(0f);
    bloom.setBlurScale(1.5f);
    fpp.addFilter(bloom);
    guiViewPort.addProcessor(fpp);
    guiViewPort.setClearColor(true);

    //        setup input handling
    inputManager.setMouseCursor((JmeCursor) assetManager.loadAsset("Textures/Pointer.ico"));

    inputManager.addMapping("mousePick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, "mousePick");

    inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("return", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addListener(this, "left");
    inputManager.addListener(this, "right");
    inputManager.addListener(this, "up");
    inputManager.addListener(this, "down");
    inputManager.addListener(this, "return");

    //        setup the hud
    hud = new Hud(assetManager, guiNode, settings.getWidth(), settings.getHeight());
    hud.reset();

    //        sounds
    sound = new Sound(assetManager);
    sound.startMusic();
    sound.spawn();

    //        particles
    particleManager =
        new ParticleManager(
            guiNode,
            getSpatial("Laser"),
            getSpatial("Glow"),
            settings.getWidth(),
            settings.getHeight());

    //        grid
    Rectangle size = new Rectangle(0, 0, settings.getWidth(), settings.getHeight());
    Vector2f spacing = new Vector2f(25, 25);
    grid = new Grid(size, spacing, guiNode, assetManager);

    //        setup the player
    player = getSpatial("Player");
    player.setUserData("alive", true);
    player.move(settings.getWidth() / 2, settings.getHeight() / 2, 0);
    player.addControl(
        new PlayerControl(settings.getWidth(), settings.getHeight(), particleManager));
    guiNode.attachChild(player);

    //        setup the bulletNode
    bulletNode = new Node("bullets");
    guiNode.attachChild(bulletNode);
    //        setup the enemyNode
    enemyNode = new Node("enemies");
    guiNode.attachChild(enemyNode);
    //        setup the blackholeNode
    blackHoleNode = new Node("black_holes");
    guiNode.attachChild(blackHoleNode);
    //        setup the particleNode
    particleNode = new Node("particles");
    guiNode.attachChild(particleNode);
  }