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

import gameEngine.entites.Entity;
import gameEngine.entites.GameObject;
import gameEngine.entites.gameComponents.*;
import gameEngine.input.Input;

import java.awt.event.KeyEvent;
import java.util.HashMap;

import static org.lwjgl.opengl.GL11.glClearColor;

public class GameScene extends Scene {

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

    public GameScene(HashMap<String, Entity> editorEntities) {
        for(Entity EditorEntity : editorEntities.values()){
            GameObject editorObject = (GameObject) EditorEntity;
            if(editorObject.getComponent(EntityView.class) != null) addNewObject(editorObject);
        }
        System.out.println("Active Game scene");
        glClearColor(1, 1, 1, 0);
    }

    public void addNewObject(GameObject editorObject) {
        enqueueTask(() -> addNewGameObject(editorObject));
    }


    private GameObject createGameObject(){
        int entitiesLength = entities.size();
        String newId = Integer.toString(entitiesLength);
        GameObject gameObject = new GameObject(newId);
        addEntity(newId, gameObject);
        return gameObject;
    }

    private void addNewGameObject(GameObject editorObject) {
        GameObject object = createGameObject();
        object.transform.setPosition(editorObject.transform.position.x,editorObject.transform.position.y,0);

        for(GameObject.Connectiontype connectionType: editorObject.ComponentConnections) {
            if(connectionType == GameObject.Connectiontype.Mesh){
                object.addComponent(new Mesh(object, Mesh.MeshType.SPRITE, "GameEngine/resources/0.png"));
            }
            if(connectionType == GameObject.Connectiontype.MoveImage){
                object.addComponent(new MoveImage(object));
            }
        }
    }

    @Override
    public void update(float dt) {
        changeScene(0, dt);    //Editorシーンへの以降処理
        for (Entity entity : entities.values()) {
            if (entity instanceof GameObject gameObject) {
                if(gameObject.getComponent(EntityView.class) != null) continue;
                if(gameObject.getComponent(ComponentView.class) != null)  continue;
                if(gameObject.getComponent(TextMesh.class) != null) continue;
                gameObject.updateComponents();
            }
        }
    }
}