#include "CS_PuppyJump.h"
#include "CS_Puppy.h"
const int CS_PuppySTATENAME_JUMP = GetNextEntityStateID();
CS_PuppyJump::CS_PuppyJump()
{
	enable = true;
	SetPhysice(false);
	jump_disable = true;
	jumped = true;
	stateID = CS_PuppySTATENAME_JUMP;
}

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

	auto mychar = std::static_pointer_cast<CS_Puppy>(we);
	//重置状态
	if (we->cbRect.cbBottom)
		jumped = false;
	//锁键
	if (!we->input.GetJump())
		jump_disable = false;
	//通常跳跃
	bool a1 = we->cbRect.cbBottom &&
		!mychar->InAction() &&
		!jumped;
	bool b1 = we->input.GetJump() &&
		!we->blockJump &&
		!jump_disable;

	bool a = a1;
	bool b = b1;
	if (a && b)
	{
		if (a1)
		{
			we->vy = -jump;
		}
		jumped = true;
		jump_disable = true;
		we->gameFunc->PlaySound(L"jumpNormal");
		//是否在空中
		mychar->ChangeState(mychar->stateAir.GetStateID());
		mychar->action_timecounter = 0;
	}
}

void CS_PuppyJump::SetPhysice(bool bInWater)
{
	if (bInWater)
		jump = inwater_jump;
	else
		jump = ground_jump;
}

void CS_PuppyJump::SetJump()
{
	auto we = e.lock();
	if (!we)
		return;

	auto mychar = std::static_pointer_cast<CS_Puppy>(we);
	we->vy = -jump;
	jumped = true;
	jump_disable = true;
}
