Example #1
0
  Node createDebugGeometry() {
    Line l = new Line(from.getPlanet().getPosition(), to.getPlanet().getPosition());

    line = new Geometry("Line #" + from.getPlanet().getID() + " to #" + to.getPlanet().getID(), l);

    Material material =
        new Material(
            SolarWarsApplication.getInstance().getAssetManager(),
            "Common/MatDefs/Misc/Unshaded.j3md");

    Player p = from.getPlanet().getOwner();
    ColorRGBA c;
    if (p == null) {
      c = ColorRGBA.White.clone();
      c.a = 0.5f;
      material.setColor("Color", c);
    } else {
      c = p.getColor();
      c.a = 0.5f;
      material.setColor("Color", c);
    }
    material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    line.setMaterial(material);

    createLabel();
    Node lineNode = new Node(line.getName() + "_Node");
    lineNode.attachChild(line);
    lineNode.attachChild(label);
    //        Vector3f pos = to.getPlanet().getPosition().
    //                subtract(from.getPlanet().getPosition());
    //        lineNode.setLocalTranslation(pos.mult(0.5f));
    return lineNode;
  }
        public void onAction(String name, boolean keyPressed, float tpf) {
          if (name.equals("KEY_R") && !keyPressed) {}

          if (name.equals("KEY_F10") && !keyPressed) {
            showMainMenu();
          }

          if (name.equals("LMB") && !keyPressed) {
            CollisionResults results = new CollisionResults();

            Vector2f click2d = app.getInputManager().getCursorPosition();
            Vector3f click3d =
                app.getCamera().getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
            Vector3f dir =
                app.getCamera()
                    .getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f)
                    .subtractLocal(click3d);
            Ray ray = new Ray(click3d, dir);

            /* Collect intersections between Ray and nodes in results list */
            resourceNodes.collideWith(ray, results);
            farmNodes.collideWith(ray, results);
            locationNodes.collideWith(ray, results);

            if (results.size() > 0) {
              CollisionResult closest = results.getClosestCollision();

              Geometry geom = closest.getGeometry();
              String geomName = geom.getName();

              if (geom.getUserData(geomName) instanceof Farm) {
                Farm farm = (Farm) geom.getUserData(geomName);
                setMessageHUD("Clicked on Farm cost: " + farm.getCost());
              }

              if (geom.getUserData(geomName) instanceof Location) {
                Location loc = (Location) geom.getUserData(geomName);
                setMessageHUD("Clicked on Location: " + loc.getName());
              }

              if (geom.getUserData(geomName) instanceof Resource) {
                Resource res = (Resource) geom.getUserData(geomName);
                Integer cost = null;

                if (res.getType() == Resource.CHICK) {
                  cost = gm.getResourceManager().getCurrentPriceChicken();
                } else if (res.getType() == Resource.LAMB) {
                  cost = gm.getResourceManager().getCurrentPriceLamb();
                } else if (res.getType() == Resource.PIGLET) {
                  cost = gm.getResourceManager().getCurrentPricePiglet();
                } else if (res.getType() == Resource.CALF) {
                  cost = gm.getResourceManager().getCurrentPriceCalf();
                }

                setMessageHUD("Clicked on " + res.getName() + " cost: " + cost);
              }
            }
          }
        }