package gameEngine.entites.gameComponents; import gameEngine.Time; import gameEngine.entites.GameObject; import gameEngine.geometry.Transform; public class MoveStraight extends GameComponent{ private GameObject parent; private final int moveSpeed = 100; public enum Direction {UP, DOWN, LEFT, RIGHT} private final Direction direction = Direction.LEFT; public MoveStraight(GameObject parent){ this.parent = parent; } @Override public GameComponent copy() { return this; } public void update() { Transform transform = parent.transform; if (transform != null) { float x = transform.position.x; float y = transform.position.y; float z = transform.position.z; if (direction == Direction.UP) { transform.setPosition(x, y - moveSpeed * Time.deltaTime, z); } if (direction == Direction.LEFT) { transform.setPosition(x - moveSpeed * Time.deltaTime, y, z); } if (direction == Direction.DOWN) { transform.setPosition(x, y + moveSpeed * Time.deltaTime, z); } if (direction == Direction.RIGHT) { transform.setPosition(x + moveSpeed * Time.deltaTime, y, z); } } } }