#TouhouDanmakufu
#Title["Taboo 'Kagome Kagome 2'"]
#Text[spell3H]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Hard]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\system\Effects.txt";
#include_function ".\cutin.txt";
#include_function ".\draweverything.txt";
let ImgBoss = GetCurrentScriptDirectory~"img\Flandre_Main.png";
let imgExRumiaBack=GetCurrentScriptDirectory~"img\ExRumiaBack.png";
let CSD = GetCurrentScriptDirectory;
let ci = CSD ~ "system\NMM.png";
let bg1 = CSD ~ "system\bg8.png";
let bg2 = CSD ~ "system\bg3.png";
let cx=GetCenterX();
let frame = 0;
let framedelay = 0;
let angle = 0;
let switch = 1;
let Cut = GetCurrentScriptDirectory~"img\cut5.png";
let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";

@Initialize
{
drawcc(GetX,GetY+120,0,0);
SetLife(800);
SetDamageRate(20,10);
SetTimer(60);
mainTask;

SetInvincibility(300);
SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
LoadGraphic(ImgBoss);
LoadUserShotData(ThisShot);
LoadGraphic(Cut);
LoadGraphic(ci);
LoadGraphic(bg1);
LoadGraphic(bg2);
SetTexture(ImgBoss);
SetGraphicRect(0, 0, 64, 64);
MagicCircle(true);
Aura;
//Border2(255,0,0);
}

//---------------------------------------------------------------

@MainLoop 
{

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);

frame++;

// Start Attack

yield;

// End Attack


// Start Boss Move


// End Boss Move



}

//---------------------------------------------------------------

@DrawLoop
{
drawall;
}
//---------------------------------------------------------------

@BackGround
{
	draw2;
}	

//---------------------------------------------------------------

@Finalize
{
DeleteGraphic(ImgBoss);
}

// main task
task mainTask{
	checkmove;
	wait(90);
	PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
	SetScore(500000);
	cutin("NAZRIN", "Taboo 'Kagome Kagome 2'", Cut, 0, 0, 325, 488);
	spellcardattack;
	wait(110);
	fire;
	bossmove;
}


task fire{
		attack;
		wait(24);
		PlaySE(CSD~"sound\shot2.wav");
		ascent(i in 0..15){
		Bullet(GetX,GetY,3,i*24,154,10);
		}
		stopattack;
		wait(516);
		fire2;
		yield;
		
	   }

task fire2{
	loop{
		attack;
		wait(24);
		ascent(i in 0..15){
		Bullet(GetX,GetY,3.5,i*24*switch,154,10);
		PlaySE(CSD~"sound\shot2.wav");
		wait(15);
		}
		stopattack;
		switch = -switch;
		wait(276);
		yield;
	     }
	   }
		
task bossmove{
		wait(120);
		loop{
		 SetMovePositionRandom01(rand(50,100),0,10,GetClipMinX+100,rand(100,150),GetClipMaxX-100,rand(100,150));
		checkmove;
		 wait(180);
		 yield;
		    }
	     }

task PlayDelaySE(se,delay){
        loop(delay){yield;}
        PlaySE(se);
}



task Bullet(x, y, v, dir, graphic, delay) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let acc = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
		 while(! Obj_BeDeleted(obj)) 
		{
		 if((Obj_GetX(obj)>=GetClipMaxX)||(Obj_GetX(obj)<=GetClipMinX))
		 {
			PlaySE(CSD~"sound\shot5.wav");
			CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),10);
			SetShotDataA(0,0,3,180-dir,rand(-0.15,0.15),0,0,31);
			ascent(i in 0..36){
			CreateShotA(1,0,0,15);
			SetShotDataA(1,0,0,0,0,0,0,35);
			SetShotDataA(1,210,0,-i*360/36,0,0.015,0.8,35);
			PlayDelaySE(CSD~"sound\shot3.wav",i*8);
			if(i%2==0)
			{PlayDelaySE(CSD~"sound\BulletWave.wav",210+i*8);}
			AddShot(i*5,0,1,0);
			}
			FireShot(0);
			Obj_Delete(obj);
		 }
		 if((Obj_GetY(obj)>=GetClipMaxY)||(Obj_GetY(obj)<=GetClipMinY))
		 {
			PlaySE(CSD~"sound\shot5.wav");
			CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),10);
			SetShotDataA(0,0,3,-dir,rand(-0.15,0.15),0,0,31);
			ascent(i in 0..36){
			CreateShotA(1,0,0,15);
			SetShotDataA(1,0,0,0,0,0,0,35);
			SetShotDataA(1,210,0,i*360/36,0,0.015,0.8,35);
			AddShot(i*5,0,1,0);
			}
			FireShot(0);
			Obj_Delete(obj);
		 }
		 yield;
		}
	}

	function wait(w){
		loop(w){yield;}
			}

sub spawn{
	PlaySE(CSD~"sound\fam.wav");
	//CreateEnemyFromScript("starFam",GetX,GetY,0,0,0);
	//CreateEnemyFromScript("starFam",GetX,GetY,0,0,180);
	  }
}
