#include "CS_RedheadAni.h"

CS_RedheadAni::CS_RedheadAni()
{
	ani.png = L"CS_CaveStoryMod";
	//启用碰撞
	cbRect.enableCbRect = true;
	cbRect.enableSoild = true;
	//设置碰撞框
	cbRect.left = cbRect.right = 28;
	cbRect.top = 11;
	cbRect.bottom = 12;
	drawBeforeOtherEntity = true;
}

void CS_RedheadAni::Step()
{
	switch (stateID)
	{
	case 0://原地缓慢的游动
		break;
	case 1://翻肚皮了
		if (vy > -0x200 / ts)
		{
			vy -= 0x2 / ts;
			if (vy < -0x200 / ts)
				vy = -0x200 / ts;
		}
		break;
	}
	//清除最后一次碰撞结果
	Entity::ClearCollisionResult();
	//执行运动
	Entity::Step();
	//执行碰撞
	Entity::Collision();
}

void CS_RedheadAni::SetState(int stateID, int lr)
{
	this->lr = lr;
	this->stateID = stateID;
	switch (stateID)
	{
	case 0://原地游动
		vx = vy = 0;
		ani.sprite_index = lr == 0 ? L"mc_redhead_l" : L"mc_redhead_r";
		break;
	case 1://翻肚皮了
		ani.sprite_index = L"mc_ironhead_red_lie";
		ani.image_counter_speed = 0;
		break;
	case 2://慢速游动
		ani.image_counter_speed = 0.25f;
		break;
	}
}

void CS_RedheadAni::SetState(std::wstring stateName, int lr)
{
	if (stateName == L"normal")
		SetState(0, lr);
	else if (stateName == L"die")
		SetState(1, lr);
	else if (stateName == L"slow")
		SetState(2, lr);
}

std::shared_ptr<Entity> CreateCS_RedheadAni()
{
	return std::make_shared<CS_RedheadAni>();
}
