package strategy;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.collision.Collidable;
import com.jme3.collision.CollisionResults;
import com.jme3.input.ChaseCamera;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Rectangle;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.RectangleMesh;
import java.time.Instant;
/**
* This is the Main Class of your Game. It should boot up your game and do initial initialisation
* Move your Logic into AppStates or Controls or other java classes
*/
public class Strategy extends SimpleApplication {
public static void main(String[] args) {
Strategy app = new Strategy();
app.setShowSettings(false); //Settings dialog not supported on mac
app.start();
}
Node shootables;
BulletAppState bulletAppState;
@Override
public void simpleInitApp() {
setUpLight();
inputManager.setCursorVisible(true);
flyCam.setDragToRotate(true);
shootables = new Node("Shootables");
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
Spatial model = assetManager.loadModel("Models/level.glb");
shootables.attachChild(model);
// shootables.attachChild(makeCube("a Dragon", -2f, 0f, 1f));
// shootables.attachChild(makeCube("a tin can", 1f, 0f, 0f));
// shootables.attachChild(makeCube("the Sheriff", 0f, 0f, -2f));
// shootables.attachChild(makeCube("the Deputy", 1f, 0f, -4f));
cursor = makeCube("cursor", 0, 0f, 0);
shootables.attachChild(cursor);
rootNode.attachChild(shootables);
inputManager.addMapping("Target",new MouseButtonTrigger(MouseInput.BUTTON_RIGHT)); // trigger 2: left-button click
inputManager.addListener(actionListener,"Target");
cam.setLocation(new Vector3f(0,5f,0));
cam.lookAtDirection(new Vector3f(0,-5,0), new Vector3f(0,0,0));
//flyCam.setEnabled(false);
//ChaseCamera chaseCam = new ChaseCamera(cam, cursor, inputManager);
}
Geometry cursor;
private Geometry makeCube(String name, float x, float y, float z) {
Box box = new Box(1, 1, 1);
Geometry cube = new Geometry(name, box);
cube.setLocalTranslation(x, y, z);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.randomColor());
cube.setMaterial(mat1);
return cube;
}
@Override
public void simpleUpdate(float tpf) {
cameraControl();
}
private void cameraControl(){
Vector2f click2d = inputManager.getCursorPosition();
float width = getContext().getSettings().getWidth();
float height =getContext().getSettings().getHeight();
Vector3f position = cursor.getLocalTranslation();
//System.out.println(click2d);
if((0 < click2d.x) && (10 > click2d.x)){
cursor.setLocalTranslation(position.x + 0.1f, position.y, position.z);
}
if((width- 10f < click2d.x) && (width > click2d.x)){
cursor.setLocalTranslation(position.x - 0.1f, position.y, position.z);
}
if((height - 10f < click2d.y)){
cursor.setLocalTranslation(position.x, position.y, position.z+0.1f);
}
if((10f > click2d.y) && (0 < click2d.x)){
cursor.setLocalTranslation(position.x, position.y, position.z-0.1f);
}
Vector3f direction = cursor.getLocalTranslation().subtract(cam.getLocation()).normalize();
cam.lookAtDirection(direction, new Vector3f(0,0,0));
cam.setLocation(new Vector3f(position.x-0.5f,position.y+8f,position.z-4.5f));
}
@Override
public void simpleRender(RenderManager rm) {
//add render code here (if any)
}
private void setUpLight() {
// We add light so we see the scene
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(5.3f));
rootNode.addLight(al);
DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
rootNode.addLight(dl);
DirectionalLight dl2 = new DirectionalLight();
dl2.setColor(ColorRGBA.White);
dl2.setDirection(new Vector3f(100,3,26).normalizeLocal());
rootNode.addLight(dl2);
DirectionalLight dl3 = new DirectionalLight();
dl3.setColor(ColorRGBA.White);
dl3.setDirection(new Vector3f(-100,3,26).normalizeLocal());
rootNode.addLight(dl3);
}
}
The embedded YouTube videos play at full sound blast. Please consider that next time… please…
1 Like
delete sound