package com.temporal;

import ashley.core.Entity;
import ashley.core.Family;
import ashley.systems.IteratingSystem;

import com.badlogic.gdx.Gdx;

public class AiSystem extends IteratingSystem
{
    private Engine engine;
    private Entity player;

    public AiSystem(int priority, Engine engine, Entity player)
    {
        super(Family.getFamilyFor(Enemy.class, Direction.class, Velocity.class, Position.class), priority);
        this.engine = engine;
        this.player = player;
    }

    @Override
    public void processEntity(Entity entity, float deltaTime)
    {
        Enemy enemy = entity.getComponent(Enemy.class);
        Direction enemyDir = entity.getComponent(Direction.class);
        Velocity enemyVel = entity.getComponent(Velocity.class);
        Position enemyPos = entity.getComponent(Position.class);

        Position playerPos = player.getComponent(Position.class);

        switch (enemy.type)
        {
            case Enemy.SHOOTER:
                enemyDir.x = playerPos.x - enemyPos.x;
                enemyDir.y = playerPos.y - enemyPos.y;
                // Normalize
                double length = Math.sqrt(enemyDir.x * enemyDir.x + enemyDir.y * enemyDir.y);
                enemyDir.x /= length;
                enemyDir.y /= length;

                // Shoot at player
                if (enemy.cooldown <= 0.0f)
                {
                    Position bulletPos = new Position(enemyPos.x, enemyPos.y);
                    Velocity bulletVel = new Velocity(enemyDir.x * 100, enemyDir.y * 100);
                    EnemyBullet damage = new EnemyBullet(1);
                    engine.addEnemyBullet(bulletPos, bulletVel, damage);
                    enemy.cooldown = 1.0f;
                }
                else
                {
                    enemy.cooldown -= deltaTime;
                }
                break;
            case Enemy.CHARGER:
                break;
            default:
                break;
        }
    }
}

@@ -981,71 +981,35 @@
     
-enemyDir.x = playerPos.x - enemyPos.x;%0A                
+pointTowardsPlayer(
 enemyDir
 .y =
@@ -1008,12 +1008,9 @@
 yDir
-.y =
+,
  pla
@@ -1019,12 +1019,9 @@
 rPos
-.y -
+,
  ene
@@ -1029,211 +1029,10 @@
 yPos
-.y;%0A                // Normalize%0A                double length = Math.sqrt(enemyDir.x * enemyDir.x + enemyDir.y * enemyDir.y);%0A                enemyDir.x /= length;%0A                enemyDir.y /= length;%0A
+);
 %0A   
@@ -1671,68 +1671,1204 @@
     
-break;%0A            default:%0A                break;%0A        %7D
+// Charge at player%0A                if (enemy.cooldown %3C= 0.0f)%0A                %7B%0A                    pointTowardsPlayer(enemyDir, playerPos, enemyPos);%0A                    double chargeVel = 50;%0A                    enemyVel.x = enemyDir.x * 50;%0A                    enemyVel.y = enemyDir.y * 50;%0A                    enemy.cooldown = 3.0f;%0A                %7D%0A                else if (enemy.cooldown %3C= 1.0f)%0A                %7B%0A                    pointTowardsPlayer(enemyDir, playerPos, enemyPos);%0A                    enemyVel.x = 0;%0A                    enemyVel.y = 0;%0A                    enemy.cooldown -= deltaTime;%0A                %7D%0A                else%0A                %7B%0A                    enemy.cooldown -= deltaTime;%0A                %7D%0A                break;%0A            default:%0A                break;%0A        %7D%0A    %7D%0A%0A    private void pointTowardsPlayer(Direction dir, Position playerPos, Position enemyPos)%0A    %7B%0A        // Point enemy towards player%0A        dir.x = playerPos.x - enemyPos.x;%0A        dir.y = playerPos.y - enemyPos.y;%0A%0A        // Normalize direction vector%0A        double length = Math.sqrt(dir.x * dir.x + dir.y * dir.y);%0A        dir.x /= length;%0A        dir.y /= length;
 %0A   

Add charger ai