#include "EntityStateSplash.h"
const int ES_STATENAME_SPLASH = ++entityStateID;
EntityStateSplash::EntityStateSplash()
{
	enable = true;
	stateID = ES_STATENAME_SPLASH;
}

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

	//入水水花效果
	if (we->cbRect.inWater)
	{
		if (fallToWater && setSplash && we->vy >= 1.5f)
		{
			//产生水花
			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;
	}
}
