Player::Player(PhysicsSimulatorPtr simulator, SpritePtr sprite, Vector2 pos)
{
	Rect2Df newSize = sprite->GetRect();
	newSize.size *= 0.95f;
	m_sprite = sprite;
	m_pos = pos;
	m_bodyId = simulator->CreatePolygon(Rect2Df(Vector2(pos.x, pos.y + sprite->GetRect().size.y / 2), newSize.size), 1.0f);	
}
inline Vector2 TouchButton::GetButtonSize(const SpritePtr& sprite)
{
	Vector2 frameSize(sprite->GetBitmapSizeF());
	if (sprite->GetRect().size != Vector2(0, 0))
	{
		frameSize = sprite->GetRect().size;
	}
	return frameSize;
}
void PlayerManager::Update(VideoPtr video, InputPtr input, ShootManagerPtr shootManager, SpritePtr playerSprite, SpritePtr shootSprite)
{
	static Vector2 hitPos, releasePos;
	static int turn = 0;
	if (input->GetTouchState(0) == GSKS_HIT)
	{	
		if (IsInArea(GetAbsolutePos(input, video), Rect2Df(GetPlayer(turn)->GetPos(), playerSprite->GetRect().size), Vector2(0.5f, 0.5f), video))
		{
			hitPos = input->GetTouchPos(0, video);
		}
		else
		{
			hitPos = GS_NO_TOUCH;
		}
	}
	if (input->GetTouchState(0) == GSKS_DOWN)
	{
		releasePos = hitPos - input->GetTouchPos(0, video);
	}
	if (input->GetTouchState(0) == GSKS_RELEASE && hitPos != GS_NO_TOUCH)
	{
		{
			Vector2 pos = m_simulator->GetPosition(GetPlayer(turn)->GetBodyId());
			shootManager->Shoot(pos, turn, releasePos);
			turn = !turn;
		}
	}
	if (hitPos == GS_NO_TOUCH)
	{
		video->MoveCamera(input->GetTouchMove(0) * -1);
	}
}
void ZombieManager::CheckZombieStatus(SpriteResourceManager& spr, ZombiePtr zombie, EffectManagerPtr fxManager, VideoPtr video, AudioPtr audio, PawnManagerPtr pawnManager)
{
	SpritePtr zombieSprite = zombie->GetSprite();

	const float rectSize = zombieSprite->GetRect().size.x;
	const float radiusSum = m_ball->GetRadius(spr, video) + (rectSize / 4.0f);
	if (SquaredDistance(m_ball->GetPos(), zombie->GetPos()) < radiusSum*radiusSum)
	{
		StateManager::m_aud.GetSample(audio, GS_L("zombiedeath.ogg"))->Play();
		zombie->Kill();
		pawnManager->AddToScore(m_ball->GetTouchOwnerId(), 0.5f);

		fxManager->Add(TemporaryEffectPtr(new SingleParticle(video, GS_L("blood01.png"), zombie->GetPos(), 0.0f, 400, 0.0f,
					   Vector2(128, 128), 1.0f, false, false, 0.0f)));
		fxManager->Add(TemporaryEffectPtr(new SingleParticle(video, GS_L("blood01.png"), zombie->GetPos(), 0.0f, 400, 0.0f,
					   Vector2(128, 128), 1.0f, false, false, 180.0f)));

		const float size = 64.0f + Randomizer::Float(64.0f);

		fxManager->Add(TemporaryEffectPtr(new SingleParticle(video, m_bloodDecals[Randomizer::Int(10) % 2], zombie->GetPos(), 0.0f, 14000, 0.0f,
					   Vector2(size, size), 1.0f, false, true, Randomizer::Float(360.0f), false)), true);
	}
}