package net.phatcode.rel;

import net.phatcode.rel.math.Vector2D;
import net.phatcode.rel.utils.Explosion;

public class ShotEntity extends Entity
{

	public static enum TYPE
	{
		NORMAL, WAVE
	}
 
	public static final int SHOT_ENERGY = 1;
	
	protected TYPE type = TYPE.NORMAL;
	protected BehaviorShot behavior = new BehaviorShot();
	protected float radius = 0;
	
	public ShotEntity()
	{
		
		direction = new Vector2D( 0 , -1 );
		speed = 8.0f;
		animator = new Animator( 23,3 );
		active = false;
		type = TYPE.NORMAL;
		initHitBox( position.x, position.y, 20, 20 );
		
	}
	
	public ShotEntity( float x, float y, int baseFrame ) 
	{
		position = new Vector2D( x , y );
		direction = new Vector2D( 0 , -1 );
		speed = 8.0f;
		animator = new Animator( baseFrame, 1 );
		active = true;
		type = TYPE.NORMAL;
		initHitBox( position.x, position.y, 20, 20 );
		
	}
	
	public ShotEntity( float x, float y, int baseFrame, float angle ) 
	{
		position = new Vector2D( x , y );
		direction = new Vector2D( (float)Math.cos(angle) , (float)Math.sin(angle) );
		speed = 8.0f;
		animator = new Animator( baseFrame, 1 );
		active = true;
		this.angle = angle;
		initHitBox( position.x, position.y, 20, 20 );
		
	}
	
	public ShotEntity( float x, float y, int baseFrame, float angle, TYPE type ) 
	{
		position = new Vector2D( x , y );
		direction = new Vector2D( 0 , -1 );
		speed = 8.0f;
		animator = new Animator( baseFrame, 1 );
		active = true;
		this.angle = angle;
		this.type = type;
		initHitBox( position.x, position.y, 20, 20 );
		
	}
	
	public void set( float x, float y, int baseFrame, float angle ) 
	{
		this.position.set( x , y );
		this.direction.set( (float)Math.cos(angle) , (float)Math.sin(angle) );
		this.speed = 8.0f;
		this.animator.set( baseFrame, 1 );
		this.active = true;
		this.angle = angle;
		
		this.counter = 0;
		this.radius = 0;
		this.active = true;
		this.type = TYPE.NORMAL;
		
		initHitBox( position.x, position.y, 20, 20 );
		
	}
	
	public void set( float x, float y, int baseFrame, float angle, TYPE type ) 
	{
		this.position.set( x , y );
		this.direction.set( 0 , -1 );
		this.speed = 8.0f;
		this.animator.set( baseFrame, 1 );
		this.active = true;
		this.angle = angle;
		this.type = type;
		
		this.counter = 0;
		this.radius = 0;
		this.active = true;
		
		initHitBox( position.x, position.y, 20, 20 );
		
	}
	
	@Override
	public void update()
	{
		counter++;
		behavior.update( this, type );
		updateHitBox();
		
	}
	
	@Override
	public void explode()
	{
		Explosion.getInstance().spawn( position, 
									   direction,
									   speed/2,
									   47, 5 );	
		kill();
	}
	
	public int getFrame()
	{
		return animator.getFrame();
	}
	
}
