Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / scenes / GameScene.java
package gameEngine.scenes;

import gameEngine.entites.GameObject;
import gameEngine.entites.gameComponents.ColorController;
import gameEngine.entites.gameComponents.GameComponent;
import gameEngine.entites.gameComponents.Mesh;
import gameEngine.entites.gameComponents.MoveImage;
import static org.lwjgl.opengl.GL11.glClearColor;

public class GameScene extends Scene {

    private boolean isCreateObject = false;
    private boolean isAddComponent = false;
    private GameObject addComponentObject;

    public GameScene() {
        System.out.println("Active Game scene");
        glClearColor(1, 1, 1, 0);

        gameObjects.put(0, new GameObject(0));
        gameObjects.get(0).addComponent(new ColorController());
        gameObjects.get(0).setName("ColorController");

        gameObjects.put(1, new GameObject(1));
        gameObjects.get(1).addComponent(new Mesh(gameObjects.get(1), Mesh.MeshType.SPRITE, "test.png"));
        gameObjects.get(1).addComponent(new MoveImage(gameObjects.get(1)));
        gameObjects.get(1).setName("Player");
    }

    @Override
    public void update(float dt) {

        if(isCreateObject){
            createGameObject();
            isCreateObject = false;
        }

        if(isAddComponent){
            addComponent();
            addComponentObject = null;
            isAddComponent = false;
        }
    }

    public void CreateNewObject(){
        if(isCreateObject) return;
        isCreateObject = true;
    }

    public void AddComponent(GameObject gameObject){
        if(isAddComponent) return;
        addComponentObject = gameObject;
        isAddComponent = true;
    }

    private void createGameObject(){
        int newId = gameObjects.size();
        gameObjects.put(newId, new GameObject(newId));
        gameObjects.get(newId).addComponent(new Mesh(gameObjects.get(newId), Mesh.MeshType.SPRITE, "test.png"));
        gameObjects.get(newId).setName("Player" + newId);
    }

    private void addComponent(){
        addComponentObject.addComponent(new MoveImage(addComponentObject));
    }


}