#include "CS_PeBubble.h"

CS_PeBubble::CS_PeBubble()
{
	type = 3;
	ani.png = L"CS_CaveStoryMod";
	ani.sprite_index = L"pe_bubble";
	dstSize = Random(0, 3);
	floatWait = Random(0, 40);
	vy_max = Random(2, 5) * -0.1f;
	cbRect.enableCbRect = true;
	cbRect.inWater = true;
}

void CS_PeBubble::Step()
{
	if (ani.image_index == dstSize)
	{
		if (floatWait > 0)
		{
			floatWait--;
		}
		else
		{
			//上浮
			if (y < 0)
			{
				Destroy();
			}
			if (vy > vy_max)
				vy -= 0.005f;
			//执行运动
			Entity::Step();
		}
		ani.image_counter_speed = 0;
	}
	//清除最后一次碰撞结果
	Entity::ClearCollisionResult();
	//执行碰撞
	Entity::Collision();
	if (!cbRect.inWater)
		Destroy();
}

void CS_PeBubble::SetState(int stateID, int lr)
{
	switch (stateID)
	{
	case 1:
		ani.hideLayerList.insert(0);
		ani.hideLayerList.erase(1);
		break;
	}
}

void CS_PeBubble::SetState(std::wstring stateName, int lr)
{
	if(stateName == L"rebirth_bubble")
		SetState(1, lr);
}
