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.Mesh;
import gameEngine.input.Input;

import static org.lwjgl.glfw.GLFW.*;
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);

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

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

    @Override
    public void update(float dt) {

        if (Input.GetKey(GLFW_KEY_W)) {
            float y =  gameObjects.get("sprite").transform.position.y;
            gameObjects.get("sprite").transform.setPosition(gameObjects.get("sprite").transform.position.x, y - 1, 0);
        }
        if (Input.GetKey(GLFW_KEY_A)) {
            float x =  gameObjects.get("sprite").transform.position.x;
            gameObjects.get("sprite").transform.setPosition(x - 1, gameObjects.get("sprite").transform.position.y, 0);
        }
        if (Input.GetKey(GLFW_KEY_S)) {
            float y =  gameObjects.get("sprite").transform.position.y;
            gameObjects.get("sprite").transform.setPosition(gameObjects.get("sprite").transform.position.x, y + 1, 0);
        }
        if (Input.GetKey(GLFW_KEY_D)) {
            float x =  gameObjects.get("sprite").transform.position.x;
            gameObjects.get("sprite").transform.setPosition(x + 1,  gameObjects.get("sprite").transform.position.y, 0);
        }

        if (Input.GetKey(GLFW_KEY_LEFT)) {
            float rotation = gameObjects.get("sprite").transform.rotation.z;
            gameObjects.get("sprite").transform.setRotation(0, 0, rotation - 1);  // 左回転
        }
        if (Input.GetKey(GLFW_KEY_RIGHT)) {
            float rotation = gameObjects.get("sprite").transform.rotation.z;
            gameObjects.get("sprite").transform.setRotation(0, 0, rotation + 1);  // 右回転
        }
    }

}