#include "CS_SantaFishWater.h"
#include "CS_SantaFish.h"
const int CS_SantaFishSTATENAME_WATER = ++entityStateID;
CS_SantaFishWater::CS_SantaFishWater()
{
	enable = true;
	stateID = CS_SantaFishSTATENAME_WATER;
}

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

	auto mychar = std::static_pointer_cast<CS_SantaFish>(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;
	}
}
