Newer
Older
AlgebraicDataflowArchitectureModel / GameEngine / src / main / java / gameEngine / entites / gameComponents / MoveImage.java
package gameEngine.entites.gameComponents;
import gameEngine.entites.Entity;
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 Entity entity;

    public MoveImage(Entity entity){
        this.entity = entity;
    }

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