#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main{
	#include_function ".\lib\lib_anime_Sunnymilk.txt"

	let imgBoss=GetCurrentScriptDirectory~"img\Boss\dot_sunnymilk.png";
        #include_function ".\lib\lib_Bosscommon.txt"
        #include_function ".\lib\lib_SpellBouns.txt"
	let bounus=3500000;		//スペル基本得点

    	@Initialize
        {
	  SetLife(500);
	  SetDamageRate(0,0);
	  SetCountDown;
	  SetMovePosition03( cx + 100 * cos(0), cy - 60 +  40 * sin(0), 10, 5);
          Tmain;
	}
	
	@MainLoop
	{  
		if(OnEvent()==true){break;}
                yield;
                SetCollisionA(GetX(),GetY(),50);
		SetCollisionB(GetX(),GetY(),16);
		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;
        } 
	
	@Finalize
	{       
		let Power=int(GetCommonData("Power")/100);
		loop(20){
			CreateShotFromScript("I_Item",GetX+rand(-70,70),GetY+rand(-70,70),0,0,0,1);
		}
		if(Power>=5){
			loop(10){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}
		else if(Power>=3){
			loop(10){
				CreateShotFromScript("P_Item" ,GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
			loop(4){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}
		else{
			loop(20){
				CreateShotFromScript("P_Item" ,GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
			loop(2){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}

		SetCommonData("SpellCade",false);
		if(GetMissCountInThisSpell == 0 && GetBombCountInThisSpell == 0 && IsTimeOut == false){//スペル取得した時
			PlaySE("seGetSpellCardBonus.wav");			//効果音
			SetCommonData("GetSpell",true);				//スペルを取得したかどうか
		}
	}

	@DrawLoop
	{//描画

	}

        task Tmain
        {
		yield;
		SpellCutName(256,0,bounus);		//カード名
		SetInvincibility(60);
		SetTimer(51);
	 	SetDamageRate(15,1);
		loop(60){yield;}
		Move;
		alternative(Level)
		case(1){//hard
			loop{
				let X = cmx;
				loop(2){
					loop(40){
						Shot01(X,7);
						X += 20;
					}
					X = cmx+10;
					loop(GetLife / 10 + 10){yield;}
				}
			}
		}
		case(0){//easy
			loop{
				let X = cmx;
				loop(2){
					loop(40){
						Shot01(X,4);
						X += 20;
					}
					X = cmx+10;
					loop(GetLife / 10 + 40){yield;}
				}
			}
		}

	}


	task Shot01( X,Max_speed){
		let SESwitch = true;
		let Speed = rand( 5, Max_speed);
		let obj = Obj_Create(OBJ_SHOT); 
		Obj_SetX(obj, X);
		Obj_SetY(obj, cmy-24);
		Obj_SetSpeed(obj, Speed);
		Obj_SetAngle(obj,90);
		ObjShot_SetGraphic(obj,26);
		ObjShot_SetDelay(obj, 5);
		Obj_SetAlpha(obj,250);
		ObjShot_SetBombResist(obj,true);
		while( !Obj_BeDeleted(obj) ){//レーザーがサニーに当たるまで直進
			let L = Length( Obj_GetX(obj), Obj_GetY(obj), GetX ,GetY);
			if( L <= 65){//色を変えて自機狙いへ
				if(SESwitch == true){
					PlaySE(warp02);
					SESwitch = false;
				}
				effectshot( Obj_GetX(obj), Obj_GetY(obj), 10, 2);
				ObjShot_SetGraphic(obj,82);
				Obj_SetAngle(obj,atan2( GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj) ) );
				Obj_SetSpeed(obj, 5);
			}
			yield;
		}
	}

	function Length( X1, Y1 ,X2, Y2){
		let X = (X2 - X1) ^ 2;
		let Y = (Y2 - Y1) ^ 2;
		return (X + Y) ^ 0.5;
	}

        task Move{
		let frame = 0;
        	loop{
			SetX( cx + 100 * cos(frame) );
			SetY( cy - 60 +  40 * sin(frame*2) );
			frame+=1;
			yield;
		}         
        }

        task effectshot(X,Y,delay,col){
                  CreateShotA(1,X,Y,delay);
                  SetShotDataA(1,0,0,0,0,0,0,col);
                  SetShotKillTime(1,0);
                  FireShot(1);
        }

	

}
#include_script".\Item01.txt"
#include_script".\Item02.txt"
#include_script".\Item04.txt"

