package net.phatcode.rel;

import java.awt.Graphics2D;

import net.phatcode.rel.utils.AABB;
import net.phatcode.rel.utils.Explosion;
import net.phatcode.rel.utils.ImageAtlas;

public class Shot extends Entity
{
	
	boolean active = false;
	
	Shot()
	{
		x = -1000;
		y = -1000;
		dy = -8;
		baseFrame = 0;
		frame = 0;
		active = true;
		width = 22;
		height = 35;
	}
	
	public void update()
	{
		x += dx;
		y += dy;
		
		if( y < -(width/2))
		{
			active = false;
		}
		
		collisionBox.init(x, y, width, height);
		
	}
	
	public void render( Screen screen, Graphics2D g,
						ImageAtlas imageAtlas )
	{
		int screenX = (int)(x - width/2.0f);
		int screenY = (int)(y - height/2.0f);
		
		g.drawImage( imageAtlas.getSprite( baseFrame + frame ), 
				 screenX,
				 screenY,
		 	     screen );
		//g.drawRect( screenX, screenY, (int)width, (int)height );
	}

	public boolean collidesWith( Entity e )
	{
		if( collisionBox.intersects( e.getCollisionBox() ) )
		{
			return true;
		}
		return false;
	}
	
	public void kill()
	{
		Explosion.getInstance().spawn( x, 
				   y,
				   (float)Math.PI/2 * 3,
				   speed/2,
				   47, 5 );	

		x = -1000;
		y = -1000;
		active = false;
		collisionBox.init(x, y, width, height);
		
	}
	
	public boolean isActive()
	{
		return active;
	}

	public void setActive(boolean active)
	{
		this.active = active;
	}

	public AABB getCollisionBox()
	{
		return collisionBox;
	}

	public void setCollisionBox(AABB collisionBox)
	{
		this.collisionBox = collisionBox;
	}

	
	
}
