/*****************************/
/* Inside The Machine - MKS  */
/*****************************/

#include "eWaypoint.h"
#include "../WorldManager.h"

eWaypoint::eWaypoint()
{
	real = true;
	toDelete = false;
	stat = false;
}
   	
eWaypoint::~eWaypoint()
{
   
}

void eWaypoint::Load()
{
   //On charge les images
   active = false;
   
	ulSetTransparentColor(RGB15(31, 0, 31));
	spr.assign(worldMan->resMan->LoadImage("efs:/Logic_Waypoint.png", UL_IN_VRAM, UL_PF_PAL4));
	ulDisableTransparentColor();

	//Animation
	spr.setFrameWH(16, 32);
	spr.addAnim(0, 0, 0, 7);     //Anim : Standing
	spr.addAnim(0, 0, 3, 7);     //Anim : Active
	
	rect.x1 = 0;
	rect.y1 = 0;
	rect.x2 = 16;
	rect.y2 = 32;
	
}
   
void eWaypoint::Draw(int layer)
{
   //On affiche le message
   if(actif && layer == 1)
   {
   	//On affiche le personnage
   	spr.setXY(x_screen, y_screen);
   	spr.play();
   	spr.draw();
	}
}
   
void eWaypoint::Update()
{
   //Calcul de la position écran de l'entité
   x_screen = x - worldMan->curLevel->map->scrollX;
	y_screen = y - worldMan->curLevel->map->scrollY;
	
	//On vérifie si l'informateur est à l'écran
   if(x_screen < (0-16) || x_screen > (256+16) || y_screen < (0-32) || y_screen > (192+32))
   	actif = false;
   else
   	actif = true;	
   
   //On paramètre la bonne animation 
   if(active)
   	spr.animLoop(1);
   else
   	spr.animLoop(0);
}

void eWaypoint::CheckInteractions()
{
	if(RectCollision(x, y, &rect, UNFIX(worldMan->hero->x), UNFIX(worldMan->hero->y), &worldMan->hero->rect) )
	{	
	   if(active == false)
	   {
	   	//On change les coordonnées du waypoint
			worldMan->waypoint = true;
			worldMan->wayPointx = x;
			worldMan->wayPointy = y;
			active = true; 
	   }   
	}			
}   

void eWaypoint::Destroy()
{
   
}
