#include "CS_PuppyFishWater.h"
#include "CS_PuppyFish.h"
const int CS_PuppyFishSTATENAME_WATER = ++entityStateID;
CS_PuppyFishWater::CS_PuppyFishWater()
{
	enable = true;
	stateID = CS_PuppyFishSTATENAME_WATER;
}

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

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