#include "cGame.h"
#include "cZombieGhost.h"
#include "MediaVars.h"

cZombieGhost::cZombieGhost(cGame *g, double xx, double yy)
{
	game = g;
	x = xx;
	y = yy;
	depth = 100000;
	facing = false;
	objectType = ZOMBIEGHOST;
	destroyed = false;
	collide.SetLeft(20);
	collide.SetTop(48);
	collide.SetRight(44);
	collide.SetBottom(64);
	chasing = false;
	chasingPrevious = false;
}

void cZombieGhost::Update()
{
	if (game->GetPlayer()->GetX()+32 < x+32)
	{
		facing = true;
	}
	if (game->GetPlayer()->GetX()+32 > x+32)
	{
		facing = false;
	}
	collide.SetPosition(x,y);
}

void cZombieGhost::Draw()
{
	sprZombieGhost->SetPosition((float)(int)x,(float)(int)y-12);
	if (facing)
		sprZombieGhost->FlipX(facing);
	game->GetWindow()->Draw(*sprZombieGhost);
	if (facing)
		sprZombieGhost->FlipX(!facing);
	// Draw Shadow
	sprShadow->SetPosition((float)(int)x,(float)(int)y);
	if (facing)
		sprShadow->FlipX(facing);
	game->GetWindow()->Draw(*sprShadow);
	if (facing)
		sprShadow->FlipX(!facing);
	// Exclamation
	if (game->PlayerHasBrain())
	{
		if (point_distance(x,y,game->GetPlayer()->GetX(),game->GetPlayer()->GetY()) < 200)
		{
			chasing = true;
			if (!chasingPrevious)
				game->PlaySound(sndChase);
			sprExclaim->SetPosition((float)(int)x+12,(float)(int)y-48);
			game->GetWindow()->Draw(*sprExclaim);
			x += 2*cos(point_direction(x,y,game->GetPlayer()->GetX(),game->GetPlayer()->GetY()));
			y += 2*sin(point_direction(x,y,game->GetPlayer()->GetX(),game->GetPlayer()->GetY()));
		}
		else
			chasing = false;
	}
	chasingPrevious = chasing;

}