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

#include "eJaunty.h"
#include "../WorldManager.h"

eJaunty::eJaunty()
{
	real = true;
	toDelete = false;
	stat = false;
	type = 5;
   genre = 3;
}
   	
eJaunty::~eJaunty()
{
   
}

void eJaunty::Load()
{
   //On charge les images
	ulSetTransparentColor(RGB15(31, 0, 31));
	spr.assign(worldMan->resMan->LoadImage("efs:/Friend_Jaunty.png", UL_IN_VRAM, UL_PF_PAL4));
	bulle.assign(worldMan->resMan->LoadImage("efs:/Static_Bulle.png", UL_IN_VRAM, UL_PF_PAL2));	
	ulDisableTransparentColor();

	//Animation
	spr.setFrameWH(32, 32);
	spr.addAnim(0, 0, 3, 7);     //Anim : Standing
	
	rect.x1 = 0;
	rect.y1 = 0;
	rect.x2 = 32;
	rect.y2 = 32;
	
	alpha = 0;
}
   
void eJaunty::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();
   	
   	ulSetAlpha(UL_FX_ALPHA, alpha, 0);
   	//On affiche la bulle
   	if(alpha > 0)
   	{
	   	bulle.setXY(x_screen - 110, y_screen - 31);
	   	bulle.draw();
	   	//On affiche le texte
	   	ulSetTextColor(RGB15(0,0,0));
	   	ulDrawTextBox(x_screen - 106, y_screen - 28, x_screen + 5, y_screen - 3, text, 0);
		}   
   	ulSetAlpha(UL_FX_DEFAULT, alpha, 0);
	}
}
   
void eJaunty::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-32) || x_screen > (256+32) || y_screen < (0-32) || y_screen > (192+32))
   	actif = false;
   else
   	actif = true;
   
   /*if(actif)
   {
	   
	}*/			
}

void eJaunty::CheckInteractions()
{
	if(RectCollision(x, y, &rect, UNFIX(worldMan->hero->x), UNFIX(worldMan->hero->y), &worldMan->hero->rect) )
	{	
	   if(alpha < 31)
	   	alpha++;
	}
	else
	{
	 	if(alpha > 0)
	   	alpha--;  
	}				
}   

void eJaunty::Destroy()
{
   
}
