Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / gameComponents / MoveImage.java
package gameEngine.entites.gameComponents;
import gameEngine.entites.GameObject;
import gameEngine.input.*;

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


public class MoveImage extends GameComponent{
    private GameObject gameObject;

    public MoveImage(GameObject gameObject){
        this.gameObject = gameObject;
    }

    public void update() {
        if (Input.GetKey(GLFW_KEY_W)) {
            float y =  gameObject.transform.position.y;
            gameObject.transform.setPosition(gameObject.transform.position.x, y - 1, 0);
        }
        if (Input.GetKey(GLFW_KEY_A)) {
            float x =  gameObject.transform.position.x;
            gameObject.transform.setPosition(x - 1, gameObject.transform.position.y, 0);
        }
        if (Input.GetKey(GLFW_KEY_S)) {
            float y =  gameObject.transform.position.y;
            gameObject.transform.setPosition(gameObject.transform.position.x, y + 1, 0);
        }
        if (Input.GetKey(GLFW_KEY_D)) {
            float x =  gameObject.transform.position.x;
            gameObject.transform.setPosition(x + 1,  gameObject.transform.position.y, 0);
        }
        if (Input.GetKey(GLFW_KEY_LEFT)) {
            float rotation = gameObject.transform.rotation.z;
            gameObject.transform.setRotation(0, 0, rotation - 1);  // 左回転
        }
        if (Input.GetKey(GLFW_KEY_RIGHT)) {
            float rotation = gameObject.transform.rotation.z;
            gameObject.transform.setRotation(0, 0, rotation + 1);  // 右回転
        }
    }
}