#include "CS_PeWaterfall.h"

CS_PeWaterfall::CS_PeWaterfall()
{
	type = 3;
	ani.png = L"CS_CaveStoryMod";
	ani.sprite_index = L"pe_waterfall";
	drawBeforeOtherEntity = true;
	//启用碰撞
	cbRect.enableCbRect = true;
	vy = 0x330 / ts;
}

void CS_PeWaterfall::Step()
{
	if (ready_counter > 0)
	{
		ready_counter--;
		//执行运动
		Entity::Step();
	}
	else
	{
		//清除最后一次碰撞结果
		Entity::ClearCollisionResult();
		//执行运动
		Entity::Step();
		//执行碰撞
		Entity::Collision();
		if (cbRect.cbBottom || cbRect.inWater)
		{
			bLeave = true;
		}
		if (bLeave)
		{
			if (leave_counter > 0)
				leave_counter--;
			if (leave_counter == 0)
				Destroy();
		}
	}
}

void SetCS_PeWaterfall(std::shared_ptr<Entity> parent, float x, float y, int style)
{
	auto pe = std::make_shared<CS_PeWaterfall>();
	pe->x = x;
	pe->y = y;
	pe->ani.image_index = style;
	parent->gameFunc->SetEntity(parent, pe);
}
