package mygame;

import com.jme3.app.DebugKeysAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.app.StatsAppState;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

/**
 * @author Snowsun
 */
public class Main extends SimpleApplication {

    private Spatial player;
    private Spatial projectile;
    private Spatial star;
    private Spatial star2;
    private Spatial star3;
    private PlayerMouseControl playerMouseControl;
    private PlayerShootControl playerShootControl;
    private WeaponProjectileControl weaponProjectileControl;
    private WeaponProjectileCollisionControl weaponProjectileCollisionControl;
    private Node starNode;

    public Main() {
        super(new StatsAppState(), new DebugKeysAppState());
    }

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }

    @Override
    public void simpleInitApp() {
        starNode = new Node("Star Node");
        rootNode.attachChild(starNode);

        Box b = new Box(Vector3f.ZERO, 1, 1, 1);
        player = new Geometry("Player",b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        player.setMaterial(mat);
        
        Box b2 = new Box(Vector3f.ZERO, 1, 1, 1);
        star = new Geometry("Star",b2);
        star.move(4f, 2f, 0);
        Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat3.setColor("Color", ColorRGBA.Orange);
        star.setMaterial(mat3);
        star.addControl(new HitStarControl(starNode));
        star.addControl(new StarPointControl());
        starNode.attachChild(star);
        
        
        Box b3 = new Box(Vector3f.ZERO, 1, 1, 1);
        star2 = new Geometry("Star2",b3);
        star2.move(-4f, 2f, 0);
        Material mat4 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat4.setColor("Color", ColorRGBA.Green);
        star2.setMaterial(mat4);
        star2.addControl(new HitStarControl(starNode));
        star2.addControl(new StarPointControl());
        starNode.attachChild(star2);
        
        
        Box b4 = new Box(Vector3f.ZERO, 1, 1, 1);
        star3 = new Geometry("Star3",b4);
        star3.move(0f, -5f, 0);
        Material mat5 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat5.setColor("Color", ColorRGBA.White);
        star3.setMaterial(mat5);
        star3.addControl(new HitStarControl(starNode));
        star3.addControl(new StarPointControl());
        starNode.attachChild(star3);
        
        
        Box box = new Box(Vector3f.ZERO, 1, 1, 2);
        projectile = new Geometry("Projectile", box);
        projectile.setLocalTranslation(player.getLocalTranslation());
        Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat2.setColor("Color", ColorRGBA.Red);
        projectile.setMaterial(mat2);

        inputManager.setCursorVisible(false);
        playerMouseControl = new PlayerMouseControl(inputManager,cam);
        player.addControl(playerMouseControl);
        playerMouseControl.setSpeed(2);
        
        playerShootControl = new PlayerShootControl(inputManager);
        player.addControl(playerShootControl);
        
        weaponProjectileControl = new WeaponProjectileControl(assetManager, rootNode, inputManager);
        weaponProjectileControl.setPlayer(player);
        projectile.addControl(weaponProjectileControl);
        
        weaponProjectileCollisionControl = new WeaponProjectileCollisionControl(starNode);
        projectile.addControl(weaponProjectileCollisionControl);
        
        rootNode.attachChild(player);
    }

    @Override
    public void simpleUpdate(float tpf) {
    }

    @Override
    public void simpleRender(RenderManager rm) {
    }
}
