// Path: core/src/me/minidigger/projecttd/components/MinionComponent.java
// public class MinionComponent implements Component, Pool.Poolable {
// 
//     public int money = 1;
//     public float speed = 1f;
//     public Minion.MinionType type = Minion.MinionType.LAND;
//     public int points = 10;
// 
//     @Override
//     public void reset() {
//         money = 1;
//         speed = 1f;
//         type = Minion.MinionType.LAND;
//         points = 10;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/components/PathComponent.java
// public class PathComponent implements Component, Pool.Poolable {
// 
//     public int tilesToGoal = -1;
//     public Vector2 nextPoint;
//     public PathFindingSystem.GoalReachedAction completed = (e) -> {
//     };
// 
//     @Override
//     public void reset() {
//         tilesToGoal = -1;
//         nextPoint = null;
//         completed = (e) -> {
//         };
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/components/TransformComponent.java
// public class TransformComponent implements Component, Pool.Poolable {
// 
//     public Vector2 position;
//     public float rotation = 0f;
// 
//     @Override
//     public void reset() {
//         position = new Vector2();
//         rotation = 0f;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/components/VelocityComponent.java
// public class VelocityComponent implements Component, Pool.Poolable {
// 
//     public Vector2 linear = new Vector2();
//     public float angular = 0f;
// 
//     @Override
//     public void reset() {
//         linear = new Vector2();
//         angular = 0f;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/entities/Minion.java
// public class Minion {
// 
//     public static PooledEngine ENGINE;
//     public static Sprite SPRITE;
// 
//     public static Entity newMinion(Vector2 spawn) {
//         Entity entity = ENGINE.createEntity();
// 
//         SpriteComponent spriteComponent = ENGINE.createComponent(SpriteComponent.class);
//         spriteComponent.sprite = SPRITE;
//         entity.add(spriteComponent);
// 
//         VelocityComponent velocityComponent = ENGINE.createComponent(VelocityComponent.class);
//         entity.add(velocityComponent);
// 
//         TransformComponent transformComponent = ENGINE.createComponent(TransformComponent.class);
//         transformComponent.position = spawn;
//         entity.add(transformComponent);
// 
//         HealthComponent healthComponent = ENGINE.createComponent(HealthComponent.class);
//         healthComponent.health = 100;
//         entity.add(healthComponent);
// 
//         PathComponent pathComponent = ENGINE.createComponent(PathComponent.class);
//         entity.add(pathComponent);
// 
//         MinionComponent minionComponent = ENGINE.createComponent(MinionComponent.class);
//         entity.add(minionComponent);
// 
//         ENGINE.addEntity(entity);
//         return entity;
//     }
// 
//     public enum MinionType{
//         LAND,
//         WATER,
//         AIR;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/utils/VectorUtil.java
// public class VectorUtil {
// 
//     // returns radians
//     public static float vectorToAngle(Vector2 vector) {
//         return (float) Math.atan2(-vector.x, vector.y);
//     }
// 
//     // angle = radians
//     public static Vector2 angleToVector(Vector2 outVector, float angle) {
//         outVector.x = -(float) Math.sin(angle);
//         outVector.y = (float) Math.cos(angle);
//         return outVector;
//     }
// }


import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.gdx.ai.utils.ArithmeticUtils;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import me.minidigger.projecttd.components.MinionComponent;
import me.minidigger.projecttd.components.PathComponent;
import me.minidigger.projecttd.components.TransformComponent;
import me.minidigger.projecttd.components.VelocityComponent;
import me.minidigger.projecttd.entities.Minion;
import me.minidigger.projecttd.utils.VectorUtil;
        float distance = toTarget.len();
        // don't go too far!
        if (distance <= 0.05) {
            velocity.linear.setZero();
            velocity.angular = 0;
            path.nextPoint = null;
            return;
        }

        float maxSpeed = minionComponent.speed;
        System.out.println("speed " + maxSpeed);
        // Target velocity combines speed and direction
        Vector2 targetVelocity = toTarget.scl(maxSpeed / distance); // Optimized code for:
        // toTarget.nor().scl(maxSpeed)

        // Acceleration tries to get to the nextPoint velocity without exceeding max acceleration
        targetVelocity.sub(velocity.linear).scl(1f / linearAccelerationTime).limit(maxLinearAcceleration);

        // set it
        velocity.linear.set(toTarget);

        // angular

        // Check for a zero direction, and set to 0 is so
        if (velocity.linear.isZero(zeroThreshold)) {
            velocity.angular = 0;
            return;
        }

        // Calculate the orientation based on the velocity of the owner
// Path: core/src/me/minidigger/projecttd/components/MinionComponent.java
// public class MinionComponent implements Component, Pool.Poolable {
// 
//     public int money = 1;
//     public float speed = 1f;
//     public Minion.MinionType type = Minion.MinionType.LAND;
//     public int points = 10;
// 
//     @Override
//     public void reset() {
//         money = 1;
//         speed = 1f;
//         type = Minion.MinionType.LAND;
//         points = 10;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/components/PathComponent.java
// public class PathComponent implements Component, Pool.Poolable {
// 
//     public int tilesToGoal = -1;
//     public Vector2 nextPoint;
//     public PathFindingSystem.GoalReachedAction completed = (e) -> {
//     };
// 
//     @Override
//     public void reset() {
//         tilesToGoal = -1;
//         nextPoint = null;
//         completed = (e) -> {
//         };
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/components/TransformComponent.java
// public class TransformComponent implements Component, Pool.Poolable {
// 
//     public Vector2 position;
//     public float rotation = 0f;
// 
//     @Override
//     public void reset() {
//         position = new Vector2();
//         rotation = 0f;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/components/VelocityComponent.java
// public class VelocityComponent implements Component, Pool.Poolable {
// 
//     public Vector2 linear = new Vector2();
//     public float angular = 0f;
// 
//     @Override
//     public void reset() {
//         linear = new Vector2();
//         angular = 0f;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/entities/Minion.java
// public class Minion {
// 
//     public static PooledEngine ENGINE;
//     public static Sprite SPRITE;
// 
//     public static Entity newMinion(Vector2 spawn) {
//         Entity entity = ENGINE.createEntity();
// 
//         SpriteComponent spriteComponent = ENGINE.createComponent(SpriteComponent.class);
//         spriteComponent.sprite = SPRITE;
//         entity.add(spriteComponent);
// 
//         VelocityComponent velocityComponent = ENGINE.createComponent(VelocityComponent.class);
//         entity.add(velocityComponent);
// 
//         TransformComponent transformComponent = ENGINE.createComponent(TransformComponent.class);
//         transformComponent.position = spawn;
//         entity.add(transformComponent);
// 
//         HealthComponent healthComponent = ENGINE.createComponent(HealthComponent.class);
//         healthComponent.health = 100;
//         entity.add(healthComponent);
// 
//         PathComponent pathComponent = ENGINE.createComponent(PathComponent.class);
//         entity.add(pathComponent);
// 
//         MinionComponent minionComponent = ENGINE.createComponent(MinionComponent.class);
//         entity.add(minionComponent);
// 
//         ENGINE.addEntity(entity);
//         return entity;
//     }
// 
//     public enum MinionType{
//         LAND,
//         WATER,
//         AIR;
//     }
// }
// 
// Path: core/src/me/minidigger/projecttd/utils/VectorUtil.java
// public class VectorUtil {
// 
//     // returns radians
//     public static float vectorToAngle(Vector2 vector) {
//         return (float) Math.atan2(-vector.x, vector.y);
//     }
// 
//     // angle = radians
//     public static Vector2 angleToVector(Vector2 outVector, float angle) {
//         outVector.x = -(float) Math.sin(angle);
//         outVector.y = (float) Math.cos(angle);
//         return outVector;
//     }
// }


// Path: core/src/me/minidigger/projecttd/systems/MoveToSystem.java
import com.badlogic.ashley.core.ComponentMapper;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.systems.IteratingSystem;
import com.badlogic.gdx.ai.utils.ArithmeticUtils;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import me.minidigger.projecttd.components.MinionComponent;
import me.minidigger.projecttd.components.PathComponent;
import me.minidigger.projecttd.components.TransformComponent;
import me.minidigger.projecttd.components.VelocityComponent;
import me.minidigger.projecttd.entities.Minion;
import me.minidigger.projecttd.utils.VectorUtil;

        float distance = toTarget.len();
        // don't go too far!
        if (distance <= 0.05) {
            velocity.linear.setZero();
            velocity.angular = 0;
            path.nextPoint = null;
            return;
        }

        float maxSpeed = minionComponent.speed;
        System.out.println("speed " + maxSpeed);
        // Target velocity combines speed and direction
        Vector2 targetVelocity = toTarget.scl(maxSpeed / distance); // Optimized code for:
        // toTarget.nor().scl(maxSpeed)

        // Acceleration tries to get to the nextPoint velocity without exceeding max acceleration
        targetVelocity.sub(velocity.linear).scl(1f / linearAccelerationTime).limit(maxLinearAcceleration);

        // set it
        velocity.linear.set(toTarget);

        // angular

        // Check for a zero direction, and set to 0 is so
        if (velocity.linear.isZero(zeroThreshold)) {
            velocity.angular = 0;
            return;
        }

        // Calculate the orientation based on the velocity of the owner
        float targetOrientation = VectorUtil.vectorToAngle(velocity.linear);