package holo.bolt.entity;

import holo.bolt.render.RenderEntity;
import holo.bolt.world.World;
import holo.bolt.world.map.tile.Tile;

import java.util.ArrayList;

import org.newdawn.slick.geom.Vector2f;

public class EntityBolt extends Entity implements IProjectile
{
	public RenderEntity render;
	public boolean hasCollided;
	public ArrayList<Entity> hasHit;
	
	public EntityBolt(float[] position, World world, Vector2f dir)
	{
		super(position, new float[]{3,3}, world);
		this.render = new RenderEntity(this);
		this.facing = dir;
		this.render.rotateImage(this.facing.getTheta());
		hasCollided = false;
		hasHit = new ArrayList<Entity>();
	}
	
	public void onUpdate(int delta)
	{
		super.onUpdate(delta);
		if(!this.hasCollided)
			this.setVelocity(this.facing.copy().normalise().scale(0.75F));
	}

	@Override
	public String getTextureLoc()
	{
		return "res/Bolt.png";
	}

	@Override
	public RenderEntity getRender()
	{
		return render;
	}

	@Override
	public void onCollideWithEntity(Entity ent)
	{
		if(ent instanceof EntityPlayer || hasCollided)
			return;
		
		if(!hasHit.contains(ent))
		{
			ent.damage(3, this.facing.copy().scale(3.0F));
			hasHit.add(ent);
		}
	}

	@Override
	public void damage(float damage, Vector2f direction){}
	
	@Override
	public float maxHealth()
	{
		return 1;
	}

	@Override
	public void onCollideWithTile(Tile t)
	{
		this.hasCollided = true;
	}

}
