/*
	The way this is implemented is really, really aweful ;-);
	Its almost a staight conversion of the crap I originally created in C#/XNA, and due to my
	utter laziness it actually abuses my collision system and the damage to handle collection
	of the items ;-). It simply assumes that nothing really deals negative damage and uses this
	as a special case. It ignores every damage dealt to it and simply returns its (negative) id
	as the damage it deals;
	In order to collect it, the hit method must be called with a NULL pointer ;-);
	I warned you, its really aweful, but it works ;-)
	
*/

namespace rectangle_battle
{
	enum ITEM_TYPE
	{
		ATTACK=-1,
		BARRIER=-2
	};
	
	class item:public rectangle_battle::collision_mgr::collision_obj
	{
		private:
		ITEM_TYPE type;
		kos_gfx::pvr::texture_fragment img;
		
		rectangle_battle::collision_mgr::element collision_elem;
		public:
		item(kos_gfx::pvr::texture_fragment tex, kos_gfx::math::vector2d<> pos, kos_gfx::math::vector2d<> vel, ITEM_TYPE it_type)
		{
			collision_elem=rectangle_battle::collision_mgr::register_missile(this);
			
			dying=false;
			dead=false;
			
			img=tex;
			w=img.w;
			h=img.h;
			
			position=pos;
			velocity=vel;
			
			type=it_type;
			dmg=it_type;
		};
		
		~item()
		{
			rectangle_battle::collision_mgr::unregister_missile(collision_elem);
		};
		
		void hit(rectangle_battle::collision_mgr::collision_obj *other)
		{
			if(other==NULL)
				dead=true;
		};
		
		void update()
		{
			if(dead)
				return;
			
			position+=velocity;
			
			if((position.x+img.w<0 && velocity.x<0) ||
			(position.y+img.h<0 && velocity.y<0) ||
			(position.x>kos_gfx::pvr::SCREEN_WIDTH && velocity.x>0) ||
			(position.y>kos_gfx::pvr::SCREEN_HEIGHT && velocity.y>0))
				dead=true;
		};
		
		void draw()
		{
			if(!dead)
				kos_gfx::pvr::draw(img,position.x,position.y);
		};
	};
};
