package holo.bolt.entity.hostiles;

import holo.bolt.entity.Entity;
import holo.bolt.entity.EntityPlayer;
import holo.bolt.entity.IProjectile;
import holo.bolt.render.RenderEntity;
import holo.bolt.world.World;
import holo.bolt.world.map.tile.Tile;

import org.newdawn.slick.geom.Vector2f;

public class EntityArrow extends Entity implements IProjectile
{
	public RenderEntity render;
	public float damage;
	
	public EntityArrow(float[] position, World world, Vector2f dir, float dmg)
	{
		super(position, new float[]{8,8}, world);
		this.render = new RenderEntity(this);
		this.facing = dir;
		this.render.rotateImage(this.facing.getTheta());
		damage = dmg;
	}
	
	public void onUpdate(int delta)
	{
		super.onUpdate(delta);
		this.addVelocity(this.facing.copy().normalise().scale(0.02F));
	}

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

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

	@Override
	public void onCollideWithEntity(Entity ent)
	{
		if(!(ent instanceof EntityPlayer))
			return;
		
		ent.damage(2, this.facing.copy().scale(0.1F));
		this.setDead();
	}

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

	@Override
	public void onCollideWithTile(Tile t)
	{
		this.setDead();
	}

}