Creating Custom Components

PlayerMovement.java
public class PlayerMovement extends Component {

    public float movementSpeed = 0.5f;

    public PlayerMovement(float movementSpeed) {
        this.name = "Player Movement";
        this.movementSpeed = movementSpeed;
    }

    @Override
    public void Update() {

        if(gameObject == null)
            return;

        // Left key
        if(Input.isKeyPressed(37)) {
            gameObject.transform.translate(Vector2.left);
        }
        // Right key
        if(Input.isKeyPressed(39)) {
            gameObject.transform.translate(Vector2.right);
        }
        // Up key
        if(Input.isKeyPressed(38)) {
            gameObject.transform.translate(Vector2.up);
        }
        // Down key
        if(Input.isKeyPressed(40)) {
            gameObject.transform.translate(Vector2.down);
        }

    }

    @Override
    public void Render(Graphics g) {

    }


}

Last updated