#include "CS_PuppyWater.h"
#include "CS_Puppy.h"
const int CS_PuppySTATENAME_WATER = GetNextEntityStateID();
CS_PuppyWater::CS_PuppyWater()
{
	enable = true;
	stateID = CS_PuppySTATENAME_WATER;
}

void CS_PuppyWater::State()
{
	auto we = e.lock();
	if (!we)
		return;

	auto mychar = std::static_pointer_cast<CS_Puppy>(we);
	auto& stateGravity = mychar->stateGravity;
	mychar->SetPhysice(we->cbRect.inWater);
	if (we->cbRect.pxaBottom == 0x12)
		mychar->SetPhysice(true);

	//入水水花效果
	if (we->cbRect.inWater)
	{
		if (fallToWater && setSplash && we->vy >= stateGravity.max_fall_speed / 2)
		{
			//产生水花
			auto nE = we->gameFunc->GameCreateEntity(L"pe_splash");
			nE->x = we->x;
			nE->y = we->y;
			//岩浆红
			if (we->cbRect.inLava)
				nE->color = RGBA(0xff, 0, 0, 0xff);
			we->gameFunc->SetEntity(we, nE);
			fallToWater = false;
		}
		else
		{
			//速度未达到但仍然在水中
			setSplash = false;
		}
	}
	else
	{
		//重置水花产生条件
		fallToWater = true;
		setSplash = true;
	}
}
