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); } } } }
private void drawTransportLine(Location start, Location end, double cost) { Vector3f lineStart = new Vector3f(start.getX(), 0.5f, start.getY()); Vector3f lineEnd = new Vector3f(end.getX(), 0.5f, end.getY()); Vector3f middle = lineStart.add(lineEnd).divide(2.0f); displayTransportCost(cost, middle); Line line = new Line(lineStart, lineEnd); line.setLineWidth(3.0f); Material lineMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); lineMaterial.setColor("Color", ColorRGBA.Magenta); Geometry lineGeometry = new Geometry("line", line); lineGeometry.setMaterial(lineMaterial); lineNodes.attachChild(lineGeometry); }
private void displayMap() { MapManager mm = gm.getMapManager(); Board bord = mm.getBoard(); List<Location> locations = bord.getLocations(); if (locations != null && locations.size() > 0) { for (Location loc : locations) { Box b = new Box(Vector3f.ZERO, 2.0f, 0.2f, 2.0f); Geometry geom = new Geometry("Box", b); // Spatial geom = app.getAssetManager().loadModel("Models/Suzanne.j3o"); // Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); // mat.setBoolean("UseMaterialColors", true); // mat.setColor("Specular", ColorRGBA.White); // mat.setColor("Diffuse", ColorRGBA.White); // mat.setFloat("Shininess", 5f); // [1,128] Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Orange); geom.setMaterial(mat); geom.setLocalTranslation(loc.getX(), 1, loc.getY()); String geomName = "LOCATION_" + loc.getName(); geom.setName(geomName); geom.setUserData(geomName, loc); displayLocationName(loc.getName(), new Vector3f(loc.getX(), 1, loc.getY())); List<Transport> transports = loc.getTransports(); if (transports != null && transports.size() > 0) { for (Transport transport : transports) { if (transport.getTarget() != loc) { drawTransportLine(loc, transport.getTarget(), transport.getCost()); } } } locationNodes.attachChild(geom); } } }