//---------------------------
// Includes
//---------------------------
#include "StdAfx.h"
#include "resource.h"
#include "Goblin.h"

#include "Painter.h"
#include "ResourceLoader.h"
#include "InputState.h"
#include "CollisionMesh.h"
#include "Image.h"
#include "TextFormat.h"
#include "Audio.h"

//---------------------------
// Constructor & Destructor
//---------------------------
Goblin::Goblin(ResourceLoader* resourceLoaderPtr,const String& imagename,int hitPoints)
:MovingEnemy(resourceLoaderPtr,imagename,hitPoints)
{
	m_VCollisionMeshPtr->CreateRect((50/2)-2,18,4,50);
	m_HCollisionMeshPtr->CreateRect(0,20,50,48*2.0/2.5);
	m_DamageAmount = -5;
}

Goblin::~Goblin()
{
	delete m_VCollisionMeshPtr;
	delete m_HCollisionMeshPtr;
	delete m_WeaponCollisionMeshPtr;
	SafeDelete(&m_ImagePtr);
}

void Goblin::Paint(Painter *painterPtr, Matrix2D matView)
{
	//Draw the image
	int width = 85;
	int height = 68;
	int space = 2;

	switch(m_CurrentState)
	{
	case STATE_WAITING:
		switch(m_CurrentAnimationStep)
		{
		case 0:
			m_SpriteBox.Set(0,0+space,width,height);
			break;
		case 15:
			m_SpriteBox.Set(width,0+space,width*2,height);
			break;
		}
		break;

	case STATE_WALKING:
		switch(m_CurrentAnimationStep)
		{
		case 0:
			m_SpriteBox.Set(width*2,0+space,width*3,height);
			break;
		case 7:
			m_SpriteBox.Set(width*3,0+space,width*4-6,height);
			break;
		}
		break;
	case STATE_JUMPING:
		m_SpriteBox.Set(width*4,height*3+space,width*5,height*4);
		break;
	case STATE_FALLING:
		m_SpriteBox.Set(width*4,height*2+space,width*5,height*3);
		break;
	case STATE_LIGHT_ATTACK1:
		switch(m_CurrentAnimationStep)
		{
		case 0:
			m_SpriteBox.Set(width*4,space,width*5,height*1);
			break;
		case 6:
			m_SpriteBox.Set(width*0,height*1+space,width*1,height*2);
			break;
		case 12:
			m_SpriteBox.Set(width*1,height*1+space,width*2-6,height*2-1);
			break;
		}
		break;
	case STATE_LIGHT_ATTACK2:
		switch(m_CurrentAnimationStep)
		{
		case 0:
			m_SpriteBox.Set(width*2-6,height*1+space,width*3-6,height*2);
			break;
		case 4:
			m_SpriteBox.Set(width*3,height*1+space,width*4,height*2);
			break;
		case 7:
			m_SpriteBox.Set(width*4,height*1+space,width*5,height*2);
			break;
		case 10:
			m_SpriteBox.Set(0,height*2+space,width,height*3);
			break;
		}
		break;

	case STATE_HEAVY_ATTACK:
		switch(m_CurrentAnimationStep)
		{
		case 0:
			m_SpriteBox.Set(width,height*4+space,width*2,height*5);
			break;
		case 20:
			m_SpriteBox.Set(width*2,height*4+space,width*3,height*5);
			break;
		case 25:
			m_SpriteBox.Set(width*3,height*4+space,width*4,height*5);
			break;
		}
		break;
	case STATE_BLOCKING:
		if(m_CurrentAnimationStep < 5)
		{
			m_SpriteBox.Set(width*1,height*3+space,width*2,height*4);
		} else {
			m_SpriteBox.Set(width*2,height*3+space,width*3,height*4);
		}
		break;
	case STATE_HIT:
		switch(m_CurrentAnimationStep)
		{
		case 0:
			m_SpriteBox.Set(width*1,height*2+space,width*2,height*3);
			break;

		case 4: 
			m_SpriteBox.Set(width*2,height*2+space,width*3,height*3);
			break;

		case 8: 
			m_SpriteBox.Set(width*3,height*2+space,width*4,height*3);
			break;
		}
		break;
	case STATE_DYING:
		switch(m_CurrentAnimationStep)
		{
		case 0:
			m_SpriteBox.Set(width*2,height*5+space,width*3,height*6);
			break;

		case 10: 
			m_SpriteBox.Set(width*3,height*5+space,width*4,height*6);
			break;
		case 20: 
			m_SpriteBox.Set(width*4,height*5+space,width*5,height*6);
			break;

		case 30: 
			m_SpriteBox.Set(width*0,height*6+space,width*1,height*7);
			break;

		case 53: 
			m_SpriteBox.Set(width*3,height*7+space,width*4,height*8);
			break;

		case 76: 
			m_SpriteBox.Set(width*4,height*7+space,width*5,height*8);
			break;

		case 99: 
			m_SpriteBox.Set(width*0,height*8+space,width*1,height*9);
			break;

		case 122: 
			m_SpriteBox.Set(width*1,height*8+space,width*2,height*9);
			break;

		case 145: 
			m_SpriteBox.Set(width*2,height*8+space,width*3,height*9);
			break;

		case 168: 
			m_SpriteBox.Set(width*3,height*8+space,width*4,height*9);
			break;

		case 191: 
			m_SpriteBox.Set(width*4,height*8+space,width*5,height*9);
			break;
		}
		break;
	}

	painterPtr->SetTransformMatrix(m_MatWorld * matView);
	painterPtr->DrawImage(m_ImagePtr,0,0,m_SpriteBox);

	//Draw the collisionMesh
	/*painterPtr->SetColor(0,0,255,127);
	painterPtr->SetTransformMatrix(matView);
	painterPtr->FillCollisionMesh(GetHCollisionMesh());
	painterPtr->FillCollisionMesh(GetVCollisionMesh());*/

}
