東方弾幕風[Single]
#ScriptVersion[2]
#Title[黒百合通常1]

script_enemy_main{
	
	//オプションXY座標
	let option1x = -64;
	let option1y =   0;
	let option2x =  64;
	let option2y =   0;
	
	@Initialize{
		//データ初期化
		InitializeData();
		InitializeAction();
		
		//ライフ設定
		SetLife( 2000 );
		//初期位置設定
		//Warp( CenterX, MinY + 130, 40 );
		//ダメージレート設定
		SetDamageRate( 100, 100 );
		//当たり判定設定
		SetCollisionEx( 32, 16, false, 60 );
		//エネミーマーカー
		SetEnemyMarker( true );
		
		//メインタスク開始
		TMain();
	}
	
	@MainLoop{
		//yieldループ
		yield;
	}
	
	@DrawLoop{
		//ボス画像描画
		SetGraphicScale( xscale, yscale );
		DrawBoss( imgBoss );
	}
	
	@Finalize{
		//最終処理
		FinalizeData();
	}
	
	/**
	 * メインタスク
	 */
	task TMain(){
		//オプション展開
		OptionControl();
		
		//60F(1秒)待つ
		FWait( 60 );
		
		//制限時間設定
		SetTimer( 36 );
		
		//攻撃分岐
		alternative( difficult )
			case( "Easy" ){
				Atack_Easy();
			}
			case( "Normal" ){
				Atack_Normal();
			}
			case( "Panic" ){
				Atack_Panic();
			}
	}
	
	/**
	 * Easy 攻撃メインタスク
	 */
	task Atack_Easy(){
	}
	
	/**
	 * Normal 攻撃メインタスク
	 */
	task Atack_Normal(){
	}
	
	/**
	 * Panic 攻撃メインタスク
	 */
	task Atack_Panic(){
		loop{
			Atack1();
			Atack2();
			
			FWait( 200 );
			
			ascent( i in 0..16 ){
				Shot1( GetX()           , GetY()           , 3.6, i * 360 / 16, PURPLE23, 20,    0, 65, 36 );
				Shot1( GetX() + option1x, GetY() + option1y, 3.6, i * 360 / 16, PURPLE23, 20,  2.8, 65, 36 );
				Shot1( GetX() + option2x, GetY() + option2y, 3.6, i * 360 / 16, PURPLE23, 20, -2.8, 65, 36 );
			}
			
			FWait( 90 );
			
			Warp( rand( MinX + 64, MaxX - 64 ), MinY + 100 + rand( -20, 20 ), 40 );
			
			FWait( 60 );
		}
	}
	
	task Atack1(){
		loop( 6 ){
			ShotGun( GetX(), GetY(), 7, GetAngleToPlayer(), PURPLE23, 12, 5, 1, 4.2, 2 );
			FWait( 40 );
		}
	}
	
	task Atack2(){
		let way = 16;
		let sway = 7;
		let span = 1.6;
		let speed = 2.8;
		let graph = 0;
		let angle = rand( 0, 360 );
		let sangle = 0;
		let wtime = 26;
		let turn = 1;
		let x = 0;
		let y = 0;
		
		loop( 12 ){
			if( turn == 1 ){
				x = GetX() + option1x;
				y = GetY() + option1y;
				graph = US_BALL_F_RED;
			}else{
				x = GetX() + option2x;
				y = GetY() + option2y;
				graph = US_BALL_F_BLUE;
			}
			
			angle += 360 / 8;
			if ( isDrawEffect ) {
				Explosion01( x, y, 12, 0.22, 90 );
			}
			ascent( i in 0..way ){
				ascent( j in 0..sway ){
					sangle = angle + i * 360 / way + ( ( -sway + 1 ) / 2 + j ) * span;
					CreateShot01( x, y, speed, sangle, graph, 0 );
				}
			}
			
			turn *= -1;
			wtime -= 2;
			speed *= 1.1;
			FWait( wtime );
		}
	}
	
	function ShotGun( x, y, speed, angle, graph, delay, num, way, span, grp ){
		let ang = 0;
		let spd = speed;
		let cspd = -speed / ( num * grp );
		
		loop( num ){
			ang = angle - ( way - 1 ) / 2 * span;
			ascent( i in 0..way ){
				CreateShot01( x, y, speed, ang, graph, delay );
				ang += span;
			}
			way += 1;
			speed += cspd;
		}
	}
	
	task Shot1( x, y, speed, angle, graph, delay, roll, wtime, way ){
		let count = 0;
		
		let obj = CreateObjShot( x, y, speed, angle, graph, delay );
		
		while( !Obj_BeDeleted( obj ) ){
			count += 1;
			if( count > wtime ){
				x = Obj_GetX( obj );
				y = Obj_GetY( obj );
				angle = GetGapAngle( x, y, GetPlayerX(), GetPlayerY() );
				
				ascent( i in 0..way ){
					CreateShot01( x, y, speed * 0.8, angle + i * 360 / way, graph, delay );
				}
				Obj_Delete( obj );
			}
			angle += roll;
			Obj_SetAngle( obj, angle );
			yield;
		}
	}
	
	/**
	 * オプションの制御
	 */
	task OptionControl(){
		loop{
			GrowEffect( GetX() + option1x, GetY() + option1y, PURPLE01, 24, 23 );
			GrowEffect( GetX() + option2x, GetY() + option2y, PURPLE01, 24, 23 );
			
			yield;
		}
	}
	
	//スクリプトのインクルード
	#include_function ".\initialize.txt"
	#include_function ".\..\..\..\Library\lib_effect.txt"
}