//////////////////////////////////////////////////////////////////////
//	プレイヤースクリプト
//////////////////////////////////////////////////////////////////////

let SakuyaB_RStar = 24;
let SakuyaB_sangle = 0;
let SakuyaB_angleStar = 0;
let SakuyaB_xLStar = SakuyaB_RStar;
let SakuyaB_yLStar = 0;
let SakuyaB_xRStar = SakuyaB_RStar;
let SakuyaB_yRStar = 0;

//スクリプト初期化
function onInitialize06() {
}

//メインタスク
task MainTask06() {
	let myPlayerIndex = 6;
	TStarMove();
	TSlowMove();
	TMainShot();
	TSubShot();
	TSubSubShot();

	task TMainShot() {
		let limit = 30;
		let gap = 6;
		let shotPowerFastMaxBase = 2.2;
		let shotPowerFastMax = shotPowerFastMaxBase;
		//let shotPowerFastMaxAry = [ 1.2, 1.2, 1.4, 1.4, 1.4, 1.4, 1.4, 1.4, 1.6 ];
		let shotPowerSlowMaxBase = 2.7;
		let shotPowerSlowMax = shotPowerSlowMaxBase;
		//let shotPowerSlowMaxAry = [ 1.8, 1.8, 2.0, 2.0, 2.2, 2.2, 2.4, 2.4, 2.5 ];
		let wFast = 4;
		let wFastAry = [ 4, 4, 4, 4, 4, 4, 4, 4, 4 ];
		let wSlow = 4;
		let wSlowAry = [ 4, 4, 4, 4, 4, 4, 4, 4, 4 ];
		let v = 13.5;
		let yGap = 8;
		
		loop {
			if ( m_nPlayerIndex != myPlayerIndex ) {
				return;
			}
			while ( OnEvent() == true ) {
				if ( m_nPlayerIndex != myPlayerIndex ) { return; }
				yield;
			}
			
			if( m_bIsSlowMove == true ) {	//低速移動時の自弾
				shotPowerSlowMax = shotPowerSlowMaxBase;
				//shotPowerSlowMax = updatePower( shotPowerSlowMaxAry );
				wSlow = updatePower( wSlowAry );
				if ( OnBomb() == true ) {
					shotPowerSlowMax /= 2;
				}
				if ( m_bIsShooting == true
					 || ( 0 < m_nShotKeyPassedTime && m_nShotKeyPassedTime <= limit ) ) {
					let num = 0;
					let xAry = [];
					let shotAngle = 270;
					let shotAngleAry = [];
					if ( m_nPower >= 32 ) {
						num = 3;
						xAry = [ GetPlayerX() - 3 * gap,
								 GetPlayerX(),
								 GetPlayerX() + 3 * gap ];
						shotAngleAry = [ shotAngle, shotAngle, shotAngle ];
					}
					else if ( m_nPower >= 8 ) {
						num = 2;
						xAry = [ GetPlayerX() - gap, GetPlayerX() + gap ];
						shotAngleAry = [ shotAngle, shotAngle ];
					}
					else {
						num = 1;
						xAry = [ GetPlayerX() ];
						shotAngleAry = [ shotAngle ];
					}
					ascent ( let i in 0..num ) {
						CreatePlayerShot01( xAry[ i ],
											GetPlayerY() - yGap,
											v, shotAngleAry[ i ], shotPowerSlowMax,
											1, 1 );
					}
				}
				loop ( wSlow ) { yield; }
			}
			else {	//高速移動時の自弾
				wFast = updatePower( wFastAry );
				shotPowerFastMax = shotPowerFastMaxBase;
				//shotPowerFastMax = updatePower( shotPowerFastMaxAry );
				if ( OnBomb() == true ) {
					shotPowerFastMax /= 2;
				}
				if ( m_bIsShooting == true
					 || ( 0 < m_nShotKeyPassedTime && m_nShotKeyPassedTime <= limit ) ) {
					let num = 0;
					let xAry = [];
					let shotAngle = 270 - SakuyaB_sangle;
					let shotAngleAry = [];
					if ( m_nPower >= 128 ) {
						num = 5;
						xAry = [ GetPlayerX() - 2 / 3 * gap,
								 GetPlayerX(),
								 GetPlayerX() + 2 / 3 * gap,
								 GetPlayerX(), GetPlayerX() ];
						shotAngleAry = [ shotAngle, shotAngle, shotAngle,
										 shotAngle - 20, shotAngle + 20 ];
					}
					else if ( m_nPower >= 32 ) {
						num = 3;
						xAry = [ GetPlayerX() - 2 / 3 * gap,
								 GetPlayerX(),
								 GetPlayerX() + 2 / 3 * gap ];
						shotAngleAry = [ shotAngle, shotAngle, shotAngle ];
					}
					else if ( m_nPower >= 8 ) {
						num = 2;
						xAry = [ GetPlayerX() - gap, GetPlayerX() + gap ];
						shotAngleAry = [ shotAngle, shotAngle ];
					}
					else {
						num = 1;
						xAry = [ GetPlayerX() ];
						shotAngleAry = [ shotAngle ];
					}
					ascent ( let i in 0..num ) {
						CreatePlayerShot01( xAry[ i ],
											GetPlayerY() - yGap,
											v, shotAngleAry[ i ], shotPowerFastMax,
											1, 1 );
					}
				}
				loop ( wFast ) { yield; }
			}
		}
	}

	task TSubShot() {
		let limit = 30;
		let gap = 6;
		let shotPowerFastMaxBase = 2.4;
		let shotPowerFastMax = shotPowerFastMaxBase;
		//let shotPowerFastMaxAry = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.2 ];
		let shotPowerSlowMaxBase = 2.9;
		let shotPowerSlowMax = shotPowerSlowMaxBase;
		//let shotPowerSlowMaxAry = [ 1.6, 1.6, 1.7, 1.7, 1.7, 1.7, 1.8, 1.8, 1.9 ];
		let wFast = 30;
		let wSlow = 10;
		let wFastAry = [ 8, 8, 4, 4, 4, 4, 4, 4, 3 ];
		let wSlowAry = [ 10, 10, 5, 5, 5, 5, 5, 5, 4 ];
		let vFast = 13.5;
		let vSlow = 22.5;
		let shotTimingSlow = 1;
		let shotTimingFast = 1;
		let shotCountFast96 = 0;
		
		loop {
			if ( m_nPlayerIndex != myPlayerIndex ) {
				return;
			}
			while ( OnEvent() == true ) {
				if ( m_nPlayerIndex != myPlayerIndex ) { return; }
				yield;
			}
			
			let xLStar = GetPlayerX() - SakuyaB_xLStar;
			let yLStar = GetPlayerY() - SakuyaB_yLStar;
			let xRStar = GetPlayerX() + SakuyaB_xRStar;
			let yRStar = GetPlayerY() - SakuyaB_yRStar;
			
			if( m_bIsSlowMove == true ) {	//低速移動時のサブ弾
				wSlow = updatePower( wSlowAry );
				shotPowerSlowMax = shotPowerSlowMaxBase;
				//shotPowerSlowMax = updatePower( shotPowerSlowMaxAry );
				if ( OnBomb() == true ) {
					shotPowerSlowMax /= 2;
				}
				if ( m_bIsShooting == true
					 || ( 0 < m_nShotKeyPassedTime && m_nShotKeyPassedTime <= limit ) ) {
					let num = 0;
					let xAry = [];
					let yAry = [];
					let shotAngle = 270 - SakuyaB_sangle;
					let shotAngleAry = [];
					
					if ( m_nPower >= 128 ) {
						num = 4;
						xAry =  [ xLStar - gap, xLStar - 3 * gap,
								  xRStar + gap, xRStar + 3 * gap ];
						yAry = [ yLStar, yLStar,  yRStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle,
										 shotAngle, shotAngle ];
					}
					else if ( m_nPower >= 96 ) {
						num = 6;
						xAry =  [ xLStar - gap, xLStar - 3 * gap, xLStar,
								  xRStar + gap, xRStar + 3 * gap, xRStar ];
						yAry = [ yLStar, yLStar, yLStar, yRStar, yRStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle, shotAngle - 10,
										 shotAngle, shotAngle, shotAngle + 10 ];
					}
					else if ( m_nPower >= 80 ) {
						num = 4;
						xAry =  [ xLStar - gap, xLStar,
								  xRStar + 3 * gap, xRStar ];
						yAry = [ yLStar, yLStar, yRStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle - 10,
										 shotAngle, shotAngle + 10 ];
					}
					else if ( m_nPower >= 64 ) {
						if ( shotTimingSlow > 0 ) {
							num = 6;
							xAry =  [ xLStar - 3 * gap, xLStar - gap, xLStar,
									  xRStar + gap, xRStar + 3 * gap, xRStar ];
							yAry = [ yLStar, yLStar, yLStar, yRStar, yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle, shotAngle - 10,
											 shotAngle, shotAngle, shotAngle + 10 ];
						}
						else {
							num = 4;
							xAry =  [ xLStar - gap, xLStar,
									  xRStar + 3 * gap, xRStar ];
							yAry = [ yLStar, yLStar, yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle - 10,
											 shotAngle, shotAngle + 10 ];
						}
					}
					else if ( m_nPower >= 16 ) {
						if ( shotTimingSlow > 0 ) {
							num = 4;
							xAry =  [ xLStar - 3 * gap, xLStar - gap,
									  xRStar + gap, xRStar + 3 * gap ];
							yAry = [ yLStar, yLStar, yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle, shotAngle, shotAngle ];
						}
						else {
							num = 2;
							xAry =  [ xLStar - gap, xRStar + 3 * gap ];
							yAry = [ yLStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle ];
						}
					}
					else {
						num = 2;
						xAry = [ xLStar, xRStar ];
						yAry = [ yLStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle ];
					}
					ascent ( let i in 0..num ) {
						CreatePlayerShot01( xAry[ i ],
											yAry[ i ],
											vSlow, shotAngleAry[ i ], shotPowerSlowMax, 1, 2 );
					}
				}
				shotTimingSlow *= -1;
				loop ( wSlow ) { yield; }
			}
			else {	//高速移動時のサブ弾
				wFast = updatePower( wFastAry );
				shotPowerFastMax = shotPowerFastMaxBase;
				//shotPowerFastMax = updatePower( shotPowerFastMaxAry );
				if ( OnBomb() == true ) {
					shotPowerFastMax /= 2;
				}
				if ( m_bIsShooting == true
					 || ( 0 < m_nShotKeyPassedTime && m_nShotKeyPassedTime <= limit ) ) {
					let num = 0;
					let xAry = [];
					let yAry = [];
					let shotAngleAry = [];
					let shotAngle = 270 - SakuyaB_sangle;
					if ( m_nPower >= 128 ) {
						num = 4;
						xAry = [ xLStar + gap, xLStar - gap - 4,
								 xRStar - gap, xRStar + gap + 4 ];
						yAry = [ yLStar, yRStar, yRStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle, shotAngle, shotAngle ];
						if ( shotCountFast96 == 0 ) {
							num += 2;
							xAry = xAry ~ [ xLStar, xRStar ];
							yAry = yAry ~ [ yLStar, yRStar ];
							shotAngleAry = shotAngleAry ~ [ shotAngle - 20, shotAngle + 20 ];
						}
						shotCountFast96 = [ shotCountFast96 + 1, 0 ][ shotCountFast96 == 2 ];
					}
					else if ( m_nPower >= 96 ) {
						num = 4;
						xAry = [ xLStar + gap, xLStar - gap - 4,
								 xRStar - gap, xRStar + gap + 4 ];
						yAry = [ yLStar, yRStar, yRStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle, shotAngle, shotAngle ];
						if ( shotCountFast96 == 0 ) {
							num += 2;
							xAry = xAry ~ [ xLStar, xRStar ];
							yAry = yAry ~ [ yLStar, yRStar ];
							shotAngleAry = shotAngleAry ~ [ shotAngle - 20, shotAngle + 20 ];
						}
						shotCountFast96 = [ shotCountFast96 + 1, 0 ][ shotCountFast96 == 2 ];
					}
					else if ( m_nPower >= 80 ) {
						if ( shotTimingFast > 0 ) {
							num = 4;
							xAry = [ xLStar,
									 xRStar - gap, xRStar + gap + 4, xRStar ];
							yAry = [ yLStar, yRStar, yRStar, yRStar ];
							shotAngleAry = [ shotAngle - 20,
											 shotAngle, shotAngle, shotAngle + 20 ];
						}
						else {
							num = 2;
							xAry = [ xRStar - gap, xRStar + gap + 4 ];
							yAry = [ yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle ];
						}
						
					}
					else if ( m_nPower >= 48 ) {
						if ( shotTimingFast > 0 ) {
							num = 6;
							xAry = [ xLStar - gap - 4, xLStar + gap, xLStar,
									 xRStar - gap, xRStar + gap + 4, xRStar ];
							yAry = [ yLStar, yLStar, yLStar, yRStar, yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle, shotAngle - 20,
											 shotAngle, shotAngle, shotAngle + 20 ];
						}
						else {
							num = 2;
							xAry = [ xRStar - gap, xRStar + gap + 4 ];
							yAry = [ yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle ];
						}
					}
					else if ( m_nPower >= 32 ) {
						if ( shotTimingFast > 0 ) {
							num = 6;
							xAry = [ xLStar - gap - 4, xLStar + gap, xLStar,
									 xRStar - gap, xRStar + gap + 4, xRStar ];
							yAry = [ yLStar, yLStar, yLStar, yRStar, yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle, shotAngle - 10,
											 shotAngle, shotAngle, shotAngle + 10 ];
						}
						else {
							num = 2;
							xAry = [ xRStar - gap, xRStar + gap + 4 ];
							yAry = [ yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle ];
						}
					}
					else if ( m_nPower >= 16 ) {
						if ( shotTimingFast > 0 ) {
							num = 4;
							xAry = [ xLStar - gap - 4, xLStar + gap,
									 xRStar - gap, xRStar + gap + 4 ];
							yAry = [ yLStar, yLStar, yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle, shotAngle, shotAngle ];
						}
						else {
							num = 2;
							xAry = [ xRStar - gap, xRStar + gap + 4 ];
							yAry = [ yRStar, yRStar ];
							shotAngleAry = [ shotAngle, shotAngle ];
						}
					}
					else {
						num = 2;
						xAry = [ xLStar, xRStar ];
						yAry = [ yLStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle ];
					}
					ascent ( let i in 0..num ) {
						CreatePlayerShot01( xAry[ i ],
											yAry[ i ],
											vFast, shotAngleAry[ i ], shotPowerFastMax, 1, 2 );
					}
				}
				shotTimingFast *= -1;
				loop ( wFast ) { yield; }
			}
		}
	}

	task TSubSubShot() {
		let limit = 30;
		let gap = 6;
		let shotPowerFastMaxBase = 2.4;
		let shotPowerFastMax = shotPowerFastMaxBase;
		//let shotPowerFastMaxAry = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.2 ];
		let shotPowerSlowMaxBase = 2.9;
		let shotPowerSlowMax = shotPowerSlowMaxBase;
		//let shotPowerSlowMaxAry = [ 1.6, 1.6, 1.7, 1.7, 1.7, 1.7, 1.8, 1.8, 1.9 ];
		let wFast = 30;
		let wSlow = 10;
		let wFastAry = [ 8, 8, 4, 4, 4, 4, 5, 5, 5 ];
		let wSlowAry = [ 16, 16, 8, 8, 8, 8, 6, 6, 6 ];
		let vFast = 13.5;
		let vSlow = 22.5;
		let shotTimingSlow = 1;
		let shotTimingFast = 1;
		
		loop {
			if ( m_nPlayerIndex != myPlayerIndex ) {
				return;
			}
			while ( OnEvent() == true ) {
				if ( m_nPlayerIndex != myPlayerIndex ) { return; }
				yield;
			}
			
			let xLStar = GetPlayerX() - SakuyaB_xLStar;
			let yLStar = GetPlayerY() - SakuyaB_yLStar;
			let xRStar = GetPlayerX() + SakuyaB_xRStar;
			let yRStar = GetPlayerY() - SakuyaB_yRStar;
			
			if( m_bIsSlowMove == true ) {	//低速移動時のサブサブ弾
				wSlow = updatePower( wSlowAry );
				shotPowerSlowMax = shotPowerSlowMaxBase;
				//shotPowerSlowMax = updatePower( shotPowerSlowMaxAry );
				if ( OnBomb() == true ) {
					shotPowerSlowMax /= 2;
				}
				if ( m_bIsShooting == true
					 || ( 0 < m_nShotKeyPassedTime && m_nShotKeyPassedTime <= limit ) ) {
					let num = 0;
					let xAry = [];
					let yAry = [];
					let shotAngle = 270 - SakuyaB_sangle;
					let shotAngleAry = [];
					
					if ( m_nPower >= 128 ) {
						num = 2;
						xAry =  [ xLStar, xRStar ];
						yAry = [ yLStar, yRStar ];
						shotAngleAry = [ shotAngle - 10, shotAngle + 10 ];
					}
					else if ( m_nPower >= 80 && m_nPower < 96 ) {
						num = 2;
						xAry =  [ xLStar - 3 * gap, xRStar + gap ];
						yAry = [ yLStar, yRStar ];
						shotAngleAry = [ shotAngle, shotAngle ];
					}
					ascent ( let i in 0..num ) {
						CreatePlayerShot01( xAry[ i ],
											yAry[ i ],
											vSlow, shotAngleAry[ i ], shotPowerSlowMax, 1, 2 );
					}
				}
				shotTimingSlow *= -1;
				loop ( wSlow ) { yield; }
			}
			else {	//高速移動時のサブサブ弾
				wFast = updatePower( wFastAry );
				shotPowerFastMax = shotPowerFastMaxBase;
				//shotPowerFastMax = updatePower( shotPowerFastMaxAry );
				if ( OnBomb() == true ) {
					shotPowerFastMax /= 2;
				}
				if ( m_bIsShooting == true
					 || ( 0 < m_nShotKeyPassedTime && m_nShotKeyPassedTime <= limit ) ) {
					let num = 0;
					let xAry = [];
					let yAry = [];
					let shotAngleAry = [];
					let shotAngle = 270 - SakuyaB_sangle;
					
					if ( m_nPower >= 80 && m_nPower < 96 ) {
						num = 2;
						xAry = [ xLStar - gap - 4, xLStar + gap ];
						yAry = [ yLStar, yLStar ];
						shotAngleAry = [ shotAngle, shotAngle ];
					}
					ascent ( let i in 0..num ) {
						CreatePlayerShot01( xAry[ i ],
											yAry[ i ],
											vFast, shotAngleAry[ i ], shotPowerFastMax, 1, 2 );
					}
				}
				shotTimingFast *= -1;
				loop ( wFast ) { yield; }
			}
		}
	}

	task TStarMove {
		let angleStep = 11.25;
		let angleGap = angleStep * 3;
		let num = 3;
		let angleInc = angleStep / num;
		loop {
			if ( m_nPlayerIndex != myPlayerIndex ) {
				return;
			}
			if ( m_bIsShooting == true ) {
				if( m_bIsSlowMove == false ) {
					if ( m_bIsMoveLeft == true ) {
						if ( SakuyaB_sangle < angleGap ) {
							loop ( num ) {
								SakuyaB_sangle += angleInc;
								yield;
							}
						}
						else {
							yield;
						}
					}
					else if ( m_bIsMoveRight == true ) {
						if ( SakuyaB_sangle > -angleGap ) {
							loop ( num ) {
								SakuyaB_sangle -= angleInc;
								yield;
							}
						}
						else {
							yield;
						}
					}
					else {
						if ( SakuyaB_sangle < 0 ) {
							loop ( num ) {
								SakuyaB_sangle += angleInc;
								yield;
							}
						}
						else if ( SakuyaB_sangle > 0 ) {
							loop ( num ) {
								SakuyaB_sangle -= angleInc;
								yield;
							}
						}
						else {
							yield;
						}
					}
				}
				else {
					yield;
				}
			}
			else {
				yield;
			}
		}
	}


	task TSlowMove {
		loop {
			if ( m_nPlayerIndex != myPlayerIndex ) {
				return;
			}
			if ( m_bIsSlowMove == true ) {
				if ( SakuyaB_angleStar < 75 ) {
					SakuyaB_angleStar += 9.375;
				}
				SakuyaB_xRStar = SakuyaB_RStar * cos( SakuyaB_angleStar + SakuyaB_sangle );
				SakuyaB_yRStar = SakuyaB_RStar * sin( SakuyaB_angleStar + SakuyaB_sangle );
				SakuyaB_xLStar = SakuyaB_RStar * cos( SakuyaB_angleStar - SakuyaB_sangle );
				SakuyaB_yLStar = SakuyaB_RStar * sin( SakuyaB_angleStar - SakuyaB_sangle );
			}
			else {
				if ( SakuyaB_angleStar > 0 ) {
					SakuyaB_angleStar -= 9.375;
				}
				SakuyaB_xRStar = SakuyaB_RStar * cos( SakuyaB_angleStar + SakuyaB_sangle );
				SakuyaB_yRStar = SakuyaB_RStar * sin( SakuyaB_angleStar + SakuyaB_sangle );
				SakuyaB_xLStar = SakuyaB_RStar * cos( SakuyaB_angleStar - SakuyaB_sangle );
				SakuyaB_yLStar = SakuyaB_RStar * sin( SakuyaB_angleStar - SakuyaB_sangle );
			}
			yield;
		}
	}
}

//平常時ループ
function onMainLoop06() {
}

//ミス時ループ
function onMissedLoop06() {
}

//スペカ宣言時
function onSpellCard06() {
	let imgSakuyaCutIn = players ~ "SakuyaB\img\cutin_sakuya.png";
	//カットイン
	if ( m_bIsSlowMove == true ) {
		CutIn( YOUMU,"時符「プライベートスクウェア」", imgSakuyaCutIn );
		UseSpellCard( "PrivateSquare", NULL );
	}
	else {
		CutIn( YOUMU,"時符「パーフェクトスクウェア」", imgSakuyaCutIn );
		UseSpellCard( "PerfectSquare", NULL );
	}
}

//描画ループ
function onDrawLoop06() {
	let imgSakuya = players ~ "SakuyaB\img\player_sakuya.png";
	SetColor( 255, 255, 255 );
	SetRenderState( ALPHA );
	SetAlpha( 255 );
	SetTexture( imgSakuya );
	if ( m_bIsMoveLeft == true ) {
		SetGraphicRect( 0, 48, 47, 95 );
	}
	else if( m_bIsMoveRight == true ) {
		SetGraphicRect( 0, 96, 47, 143 );
	}
	else if ( m_bIsMoveStraight == true ) {
		SetGraphicRect( 0, 0, 47, 47 );
	}
	DrawGraphic( GetPlayerX(), GetPlayerY() );
	
	SetGraphicRect( 0, 160, 19, 179 );
	DrawGraphic( GetPlayerX() - SakuyaB_xLStar, GetPlayerY() - SakuyaB_yLStar );
	SetGraphicRect( 0, 180, 19, 199 );
	DrawGraphic( GetPlayerX() + SakuyaB_xRStar, GetPlayerY() - SakuyaB_yRStar );
}

//スクリプト終了
function onFinalize06() {
}

