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 gameEngine.views.Color;

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


public class MoveImage extends GameComponent{

    private GameObject parent;

    public MoveImage(GameObject parent){
        this.parent = parent;
    }
    @Override
    public GameComponent copy() {
        return this;
    }

    public void update() {

        if(Input.GetKey(GLFW_KEY_O)){
            GameObject gameObject = (GameObject) parent;
            TextMesh textmesh = gameObject.getComponent(TextMesh.class);
            textmesh.setTextSize(textmesh.getTextSize() + 1);
        }
        if(Input.GetKey(GLFW_KEY_P)){
            GameObject gameObject = (GameObject) parent;
            TextMesh textmesh = gameObject.getComponent(TextMesh.class);
            textmesh.setTextSize(textmesh.getTextSize() - 1);
        }
        if(Input.GetKeyDown(GLFW_KEY_I)){
            GameObject gameObject = (GameObject) parent;
            TextMesh textmesh = gameObject.getComponent(TextMesh.class);
            textmesh.setText("popopo");
        }
        if(Input.GetKeyDown(GLFW_KEY_U)){
            GameObject gameObject = (GameObject) parent;
            TextMesh textmesh = gameObject.getComponent(TextMesh.class);
            textmesh.setColor(new Color(1f,0f,1f,1f));
        }

        if (Input.GetKey(GLFW_KEY_W)) {
            float y =  parent.transform.position.y;
            parent.transform.setPosition(parent.transform.position.x, y - 1, parent.transform.position.z);
        }
        if (Input.GetKey(GLFW_KEY_A)) {
            float x =  parent.transform.position.x;
            parent.transform.setPosition(x - 1, parent.transform.position.y, parent.transform.position.z);
        }
        if (Input.GetKey(GLFW_KEY_S)) {
            float y =  parent.transform.position.y;
            parent.transform.setPosition(parent.transform.position.x, y + 1, parent.transform.position.z);
        }
        if (Input.GetKey(GLFW_KEY_D)) {
            float x =  parent.transform.position.x;
            parent.transform.setPosition(x + 1,  parent.transform.position.y, parent.transform.position.z);
        }
        if (Input.GetKey(GLFW_KEY_Q)) {
            float z =  parent.transform.position.z;
            parent.transform.setPosition(parent.transform.position.x,  parent.transform.position.y, z - 1);
        }
        if (Input.GetKey(GLFW_KEY_E)) {
            float z =  parent.transform.position.z;
            parent.transform.setPosition(parent.transform.position.x,  parent.transform.position.y, z + 1);
        }
        if (Input.GetKey(GLFW_KEY_Z)) {
            float rotation = parent.transform.rotation.x;
            rotation -= 1;
            if (rotation < 0) rotation += 360;

            parent.transform.setRotation(rotation, parent.transform.rotation.y, parent.transform.rotation.z);  // 左回転
        }
        if (Input.GetKey(GLFW_KEY_C)) {
            float rotation = parent.transform.rotation.x;
            rotation += 1;
            if (rotation >= 360) rotation -= 360;
            parent.transform.setRotation(rotation , parent.transform.rotation.y, parent.transform.rotation.z);  // 右回転
        }
        if (Input.GetKey(GLFW_KEY_UP)) {
            float rotation = parent.transform.rotation.y;
            rotation -= 1;
            if (rotation < 0) rotation += 360;

            parent.transform.setRotation(parent.transform.rotation.x, rotation, parent.transform.rotation.z);  // 左回転
        }
        if (Input.GetKey(GLFW_KEY_DOWN)) {
            float rotation = parent.transform.rotation.y;
            rotation += 1;
            if (rotation >= 360) rotation -= 360;
            parent.transform.setRotation(parent.transform.rotation.x, rotation, parent.transform.rotation.z);  // 右回転
        }
        if (Input.GetKey(GLFW_KEY_LEFT)) {
            float rotation = parent.transform.rotation.z;
            rotation -= 1;
            if (rotation < 0) rotation += 360;

            parent.transform.setRotation(parent.transform.rotation.x, parent.transform.rotation.y, rotation);  // 左回転
        }
        if (Input.GetKey(GLFW_KEY_RIGHT)) {
            float rotation = parent.transform.rotation.z;
            rotation += 1;
            if (rotation >= 360) rotation -= 360;
            parent.transform.setRotation(parent.transform.rotation.x, parent.transform.rotation.y, rotation);  // 右回転
        }
    }
}