//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * アンズ大ダメージ状態実装
 * @author Junpee
 */

#include "Core/Utility/stdafx.h"
#include "Player/Anzu/AnzuBigDamageState.h"
#include "Game/Sound/SoundSystem.h"
#include "Player/System/Player.h"

#include "Player/Anzu/AnzuDeathState.h"
#include "Player/Anzu/AnzuGetUpState.h"

//------------------------------------------------------------------------------
// 生成、破棄
//------------------------------------------------------------------------------
// コンストラクタ
AnzuBigDamageState::AnzuBigDamageState(Anzu* anzu) : AnzuState(anzu){
}
//------------------------------------------------------------------------------
// デストラクタ
AnzuBigDamageState::~AnzuBigDamageState(){
}
//------------------------------------------------------------------------------
// 実行
//------------------------------------------------------------------------------
// 初期化
void AnzuBigDamageState::initialize(){
	// 向きの設定
	Vector3 direction = -getDamageDirection();
	direction.y = 0.f;
	setDirection(direction);
	clearDamage();
	// アニメーションシーケンス設定
	getAnimation()->setSequence(4);
	// 実行カウンタクリア
	runCounter_ = 0;
	// 速度の初期化
	setVelocity(Vector3(0.f, 2.5f, 0.f));
	// 音を鳴らす
	getSoundSystem()->play("AnzuBigDamage");
}
//------------------------------------------------------------------------------
// 後始末
void AnzuBigDamageState::finalize(){
}
//------------------------------------------------------------------------------
// 実行
void AnzuBigDamageState::run(){
	// 定数
	float animationScale = 1.f;

	// ステート変更
	if(runCounter_ == 120){
		if(isDeath()){
			// 死亡
			getPlayer()->setState(new AnzuDeathState(getAnzu()));
		}else{
			// 死んでいなければ起き上がる
			getPlayer()->setState(new AnzuGetUpState(getAnzu()));
		}
	}

	// 位置と速度の計算
	float rate = (1.f - ((float)runCounter_ / 120.f)) * 0.4f;
	calcVelocityAndPosition(-getDirection() * rate);

	// 地形コリジョン
	landCollide();

	// 描画セットアップ
	drawSetup(animationScale);

	// 実行カウンタインクリメント
	runCounter_++;
}
//------------------------------------------------------------------------------
