Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / scenes / GameScene.java
NoranekoFelician on 7 Oct 2 KB Editor用Windowを仮で作成
package gameEngine.scenes;

import gameEngine.entites.GameObject;
import gameEngine.entites.gameComponents.ColorController;
import gameEngine.entites.gameComponents.Mesh;
import gameEngine.input.Input;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.glClearColor;

public class GameScene extends Scene {

    private boolean isCreateObject = false;
    private boolean isAddComponent = false;

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

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

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

    @Override
    public void update(float dt) {

        if(isCreateObject)
        {
            createGameObject();
            isCreateObject = false;
        }
        if (Input.GetKey(GLFW_KEY_W)) {
            float y =  gameObjects.get(1).transform.position.y;
            gameObjects.get(1).transform.setPosition(gameObjects.get(1).transform.position.x, y - 1, 0);
        }
        if (Input.GetKey(GLFW_KEY_A)) {
            float x =  gameObjects.get(1).transform.position.x;
            gameObjects.get(1).transform.setPosition(x - 1, gameObjects.get(1).transform.position.y, 0);
        }
        if (Input.GetKey(GLFW_KEY_S)) {
            float y =  gameObjects.get(1).transform.position.y;
            gameObjects.get(1).transform.setPosition(gameObjects.get(1).transform.position.x, y + 1, 0);
        }
        if (Input.GetKey(GLFW_KEY_D)) {
            float x =  gameObjects.get(1).transform.position.x;
            gameObjects.get(1).transform.setPosition(x + 1,  gameObjects.get(1).transform.position.y, 0);
        }
        if (Input.GetKey(GLFW_KEY_LEFT)) {
            float rotation = gameObjects.get(1).transform.rotation.z;
            gameObjects.get(1).transform.setRotation(0, 0, rotation - 1);  // 左回転
        }
        if (Input.GetKey(GLFW_KEY_RIGHT)) {
            float rotation = gameObjects.get(1).transform.rotation.z;
            gameObjects.get(1).transform.setRotation(0, 0, rotation + 1);  // 右回転
        }

    }

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

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

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

    private void addComponent(){
        gameObjects.get(0).addComponent(new ColorController());
    }


}