/***************************************************************/
//
//
//		DirectX	[ explosion.cpp ]
//
//											Author	kazuki tanaka
//											Date	2016 9/2
/*---------------------------------------------------------------
■Update : 2016/9/2
			explosion.cppの作成

/*---------------------------------------------------------------
	インクルードファイル
---------------------------------------------------------------*/

#include <time.h>

#include "main.h"
#include "explosion.h"

#include "rendererdx9.h"

#include "particle.h"
//#include "locus.h"

#include "input.h"
//#include "sound.h"

#include "mouse.h"

//#include <Windows.h>
//#include <stdio.h>
//#include <d3dx9.h>

//#pragma comment (lib,"d3d9.lib")
//#pragma comment (lib,"d3dx9.lib")
//#pragma comment (lib,"dxguid.lib")


/*---------------------------------------------------------------
	マクロ定義
---------------------------------------------------------------*/

#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }
#define RADIAN( theta ) ((( theta ) * D3DX_PI ) / 180 )	// ラジアン角への変換

// アフィン変換
#define AFFINE_TRANSFORM_X( radiusX, radiusY, theta ) \
(( radiusX ) * cosf( RADIAN( theta )) - ( radiusY ) * sinf( RADIAN( theta )))

#define AFFINE_TRANSFORM_Y( radiusX, radiusY, theta ) \
(( radiusX ) * sinf( RADIAN( theta )) + ( radiusY ) * cosf( RADIAN( theta )))

#define EXPLOSION_SE (1)

// エフェクト構造体
typedef struct{

	D3DXVECTOR3 center;							// 中心座標
	float       radius;							// オブジェクト半径
	D3DXCOLOR   color;							// 色情報
	float       scale;							// 爆発範囲
	float radiusValue;							// 半径の変化量
	float colorValue;							// 色の変化量
	unsigned int life;							// 寿命
	unsigned int number;						// 個数 

}EXPLOSION;


/*---------------------------------------------------------------
	定数定義
---------------------------------------------------------------*/

#define MAX_EXPLOSION ( 100 )

#define EXPLOSION_LIFE ( 100 )

/*----------------------------------------------------------------
	グローバル変数
----------------------------------------------------------------*/

EXPLOSION explosion[ MAX_EXPLOSION ] = {};					// 爆発



// EXPLOSIONの初期化
void InitExplosion( void )
{


	// デバイスの受け取り
	LPDIRECT3DDEVICE9 pDevice = GetDevice( );

	for( int index = 0; index < MAX_EXPLOSION ; index++ ){

		explosion[ index ].life = 0;

	
	}


}

// EXPLOSIONの終了処理
void UninitExplosion( void )
{


}

// EXPLOSIONの更新
void UpdateExplosion( void )
{
	/*
	if( GetKeyboardTrigger( DIK_RETURN ) ){
	
		for( int index = 0; index < MAX_EXPLOSION; index++ ){

			if( !explosion[ index ].life ){
		
				explosion[ index ].life = 30;
				//explosion[ index ].center = D3DXVECTOR2( SCREEN_WIDTH >> 1, SCREEN_HEIGHT >> 1 );
				explosion[ index ].center = D3DXVECTOR2( GetMouseX(), GetMouseY() );
				explosion[ index ].number = 3;
				break;
			}
		}
	}*/

	for( int index = 0; index < MAX_EXPLOSION ; index++ ){
	
		if( explosion[ index ].life ){
		
			for( int inc = 0; inc < explosion[ index ].number; inc++ ){
			
				EmitExplosion( explosion[ index ].center, 5 , D3DXVECTOR3( 2.5f, 2.5f, 2.5f ), D3DXVECTOR3( 0.948f, 0.948f, 0.948f ), D3DXCOLOR( 0.6f, 0.3f, 0.1f, 1.0f ), D3DXCOLOR( 0.01f, 0.01f, 0.01f, 0.01f ), 10, 30 );
			}
		
			// 寿命減少
			explosion[ index ].life--;	
		}
	}

}

// 爆発のセット
void SetExplosion( const LPD3DXVECTOR3 coord )
{

	for( int index = 0; index < MAX_EXPLOSION; index++ ){

		if( !explosion[ index ].life ){
		
			explosion[ index ].life = 30;
			//explosion[ index ].center = D3DXVECTOR2( SCREEN_WIDTH >> 1, SCREEN_HEIGHT >> 1 );
			explosion[ index ].center = *coord;
			explosion[ index ].number = 3;
			break;
		}
	}
	//StopOneShotSoundEffect( EXPLOSION_SE );
	//PlayOneShotSoundEffect( EXPLOSION_SE );


}


