#TouhouDanmakufu
#Title[Forbidden Arts]
#Text[Forbidden Arts]
#BackGround[User(.\system\bg0.png, 0, 0)]
#Player[FREE]
#ScriptVersion[2]
//#Image[.\system\image.jpg]

script_enemy_main{
		
		#include_function".\function_cutin.txt";
		#include_function".\Halo.txt";
		
	let CSD = GetCurrentScriptDirectory;

	let imgBoss = CSD ~ "system\kaguyasprite.png";
	let cut = GetCurrentScriptDirectory ~ "system\kaguyacutin.png";
	let bg1 = CSD ~ "system\bg1.png";
	let bg2 = CSD ~ "system\bg2.png";
	let f = 0;
	let f2 = 0;
	let f3 = 0;
	let slide = 0;
	let hover = 0;
	let hovertrue = 0;
	let trans = 255;
	let bgm = CSD ~ "bgm\lunaticprincess2.mp3";
	let L1F1 = CSD ~ "familiars\L1F1.txt";
	let L1F2 = CSD ~ "familiars\L1F2.txt";
	let L1F3 = CSD ~ "familiars\L1F3.txt";
	let L1F4 = CSD ~ "familiars\L1F4.txt";
	let L1F5 = CSD ~ "familiars\L1F5.txt";
	let L1F6 = CSD ~ "familiars\L1F6.txt";
	let L1F7 = CSD ~ "familiars\L1F7.txt";
	let L1F8 = CSD ~ "familiars\L1F8.txt";
	let L1F9 = CSD ~ "familiars\L1F9.txt";
	let L1F10 = CSD ~ "familiars\L1F10.txt";	
	let L2F1 = CSD ~ "familiars\L2F1.txt";
	let L2F2 = CSD ~ "familiars\L2F2.txt";
	let L2F3 = CSD ~ "familiars\L2F3.txt";
	let L2F4 = CSD ~ "familiars\L2F4.txt";
	let L2F5 = CSD ~ "familiars\L2F5.txt";
	let L2F6 = CSD ~ "familiars\L2F6.txt";
	let L2F7 = CSD ~ "familiars\L2F7.txt";
	let L2F8 = CSD ~ "familiars\L2F8.txt";
	let L2F9 = CSD ~ "familiars\L2F9.txt";
	let L2F10 = CSD ~ "familiars\L2F10.txt";
	
	let fam1 = CSD ~ "SC6Familiar1.txt";
	let fam2 = CSD ~ "SC6Familiar2.txt";
	let fam3 = CSD ~ "SC6Familiar3.txt";
	let fam4 = CSD ~ "SC6Familiar4.txt";
	let fam5 = CSD ~ "SC6Familiar5.txt";
			
	@Initialize{
		SetLife(5000);		
		SetDamageRate(100,0);
		SetTimer(120);		
		SetInvincibility(240);		
		LoadGraphic(imgBoss);
		LoadGraphic(cut);
		LoadGraphic(bg1);
		LoadGraphic(bg2);
		LoadMusic(bgm);
		ForbidBomb(false);
		CreateAura03("ROSE",0,0,1.3,1.3,1.3);
		LoadUserShotData(CSD ~ "ZUN's shotdata.txt");	
		
		mainTask;

	}

	// ***Takes approximately 113 seconds to destroy all familiars with ReimuB***
	
	@MainLoop{
		if(OnBomb == false){
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY,32);
		trans=255;
		}
		if(OnBomb == true){trans=50;}
		yield;
	}

	@DrawLoop{
		
		SetTexture(imgBoss);
		SetRenderState(ALPHA);
		SetAlpha(trans);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);		
		
		if(int(GetSpeedX())==0){
			if(f<3){SetGraphicRect(0,0,80,80);}
			f2=0;
			hovertrue=1;
		}
		
		if(GetSpeedX()>0){
			if(f2<3){SetGraphicRect(0,80,80,160);}
			if(f2>=3 && f2<6){SetGraphicRect(80,80,160,160);}
			if(f2>=6){SetGraphicRect(160,80,240,160);}
			f2++;		
			hovertrue=0;
		}
		if(GetSpeedX()<0){
			SetGraphicAngle(180,0,0);
			if(f2<3){SetGraphicRect(0,80,80,160);}
			if(f2>=3 && f2<6){SetGraphicRect(80,80,160,160);}
			if(f2>=6){SetGraphicRect(160,80,240,160);}
			f2++;		
			hovertrue=0;
		}
		if(hovertrue==1){hover++;}
		if(hovertrue==0){hover=0;}
		DrawGraphic(GetX,GetY+(8*sin(hover*3)));
	}

	@BackGround{
		SetTexture(bg2);
		SetGraphicRect(0,0,256,10000+slide);
		SetGraphicScale(1.75,1.75);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY-(slide*2));
		
		slide+=0.5;
		SetTexture(bg1);
		SetGraphicRect(0,0,384,448);
		SetGraphicScale(1.5,1.01);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY);
		
		
	}

	@Finalize{
		DeleteGraphic(imgBoss);
		DeleteGraphic(cut);
		DeleteGraphic(bg1);
		DeleteGraphic(bg2);
		FadeOutMusic(bgm,40);
		PlaySE(CSD ~ "sfx\se_enep01.wav");
		Explosion01(GetCenterX,GetCenterY-150,5,2,90);
		Explosion01(GetCenterX,GetCenterY-150,5,2,90);
		Explosion01(GetCenterX,GetCenterY-150,5,2,90);
	}


	task mainTask{
		//SetPlayerInvincibility(100000);
		SetMovePosition03(GetCenterX,GetCenterY-110,10,2.5);
		wait(120);
		PlaySE(CSD ~ "sfx\charge.wav");
		Concentration01(90);
		wait(90);
		SetScore(10000000);
		PlaySE(CSD ~ "sfx\se_cat00.wav");
		cutin("NAZRIN","Forbidden Arts",cut,0,5,600,439);
		PlayMusic(bgm);
		wait(120);
		PlaySE(CSD ~ "sfx\se_boon01.wav");
		CreateEnemyFromFile(L1F1,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F2,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F3,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F4,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F5,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F6,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F7,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F8,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F9,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L1F10,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F1,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F2,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F3,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F4,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F5,GetCenterX-220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F6,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F7,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F8,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F9,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		CreateEnemyFromFile(L2F10,GetCenterX+220,GetCenterY-rand(0,200),0,0,0);
		yield;
		wait(120);
		PlaySE(CSD ~ "sfx\se_ch02.wav");
		Concentration01(60);
		wait(60);		
		rings;
		fire;
		wait(9690);
		loop(6){PlaySE(CSD ~ "sfx\se_timeout.wav");
		wait(60);}
		loop(5){PlaySE(CSD ~ "sfx\se_timeout2.wav");
		wait(60);}
	}

	task rings{
		let x = 0;
		let dir =0;
		loop{
		if(GetPlayerX<GetEnemyX+120 && GetPlayerX>GetEnemyX-120 && GetPlayerY>GetEnemyY-120 && GetPlayerY<GetEnemyY+120 && GetTimeOfPlayerInvincibility==0){
		while(x<40){
		PlaySE(CSD ~ "sfx\se_tan00_2.wav");
		CreateShotA(1,GetEnemyX,GetEnemyY,10);
		// (id,time,speed,dir,dir-velocity,accel,maxspeed,graphic)
		SetShotDataA(1,0,1,dir,0,-1,1,100);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,1);
                                SetShotDataA(1,0,1,dir,0,-1,1,175);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,2);
                                SetShotDataA(1,0,1,dir,0,-1,1,100);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,17);
                                SetShotDataA(1,0,1,dir,0,-1,1,175);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,19);
                                SetShotDataA(1,0,1,dir,0,-1,1,100);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,25);
                                SetShotDataA(1,0,1,dir,0,-1,1,175);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,25);
		FireShot(1);
		
		CreateShotA(1,GetEnemyX,GetEnemyY,10);
		// (id,time,speed,dir,dir-velocity,accel,maxspeed,graphic)
		SetShotDataA(1,0,1,dir,0,-1,1,100);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,25);
                                SetShotDataA(1,0,1,dir,0,-0,1,175);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,45);
                                SetShotDataA(1,0,1,dir,0,-0,1,100);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,5);
                                SetShotDataA(1,0,1,dir,0,-0,1,275);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,55);
                                SetShotDataA(1,0,1,dir,0,-0,1,100);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,15);
                                SetShotDataA(1,0,1,dir,0,-0,1,175);
		SetShotDataA(1,90,NULL,NULL,0,-0,1,35);
		FireShot(1);
		
		x++;
		dir+=360/9;
		}
		x=0;
		dir=rand(0,360);}
		wait(20);}
		yield;
	}
	
	//Familiar 1 goes down toward the player
	//Familiar 2 goes down randomly
	//Familiars 3 and 4 go down diagonally and shoots bullets
	//Familiar 5 goes horizontally near the player
	
	task fire{
		let random = 0;
		loop(60){
		random = rand_int(1,6);
		PlaySE(CSD ~ "sfx\se_boon00_2.wav");
		if(random==1){CreateEnemyFromFile(fam1,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==2){CreateEnemyFromFile(fam2,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==3){CreateEnemyFromFile(fam3,GetCenterX-190,GetCenterY-rand(0,200),0,0,0);}
		if(random==4){CreateEnemyFromFile(fam4,GetCenterX+190,GetCenterY-rand(0,200),0,0,0);}
		if(random==5){CreateEnemyFromFile(fam5,GetCenterX+190,GetCenterY+rand(0,200),0,0,0);}
		if(random==6){CreateEnemyFromFile(fam5,GetCenterX-190,GetCenterY+rand(0,200),0,0,0);}
		wait(30);
		}
		
		loop(72){
		random = rand_int(1,6);
		PlaySE(CSD ~ "sfx\se_boon00_2.wav");
		if(random==1){CreateEnemyFromFile(fam1,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==2){CreateEnemyFromFile(fam2,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==3){CreateEnemyFromFile(fam3,GetCenterX-190,GetCenterY-rand(0,200),0,0,0);}
		if(random==4){CreateEnemyFromFile(fam4,GetCenterX+190,GetCenterY-rand(0,200),0,0,0);}
		if(random==5){CreateEnemyFromFile(fam5,GetCenterX+190,GetCenterY+rand(0,200),0,0,0);}
		if(random==6){CreateEnemyFromFile(fam5,GetCenterX-190,GetCenterY+rand(0,200),0,0,0);}
		wait(25);
		}
		
		loop(90){
		random = rand_int(1,6);
		PlaySE(CSD ~ "sfx\se_boon00_2.wav");
		if(random==1){CreateEnemyFromFile(fam1,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==2){CreateEnemyFromFile(fam2,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==3){CreateEnemyFromFile(fam3,GetCenterX-190,GetCenterY-rand(0,200),0,0,0);}
		if(random==4){CreateEnemyFromFile(fam4,GetCenterX+190,GetCenterY-rand(0,200),0,0,0);}
		if(random==5){CreateEnemyFromFile(fam5,GetCenterX+190,GetCenterY+rand(0,200),0,0,0);}
		if(random==6){CreateEnemyFromFile(fam5,GetCenterX-190,GetCenterY+rand(0,200),0,0,0);}
		wait(20);
		}
		
		loop{
		random = rand_int(1,6);
		PlaySE(CSD ~ "sfx\se_boon00_2.wav");
		if(random==1){CreateEnemyFromFile(fam1,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==2){CreateEnemyFromFile(fam2,GetCenterX+rand(-200,200),GetCenterY-200,0,0,0);}
		if(random==3){CreateEnemyFromFile(fam3,GetCenterX-190,GetCenterY-rand(0,200),0,0,0);}
		if(random==4){CreateEnemyFromFile(fam4,GetCenterX+190,GetCenterY-rand(0,200),0,0,0);}
		if(random==5){CreateEnemyFromFile(fam5,GetCenterX+190,GetCenterY+rand(0,200),0,0,0);}
		if(random==6){CreateEnemyFromFile(fam5,GetCenterX-190,GetCenterY+rand(0,200),0,0,0);}
		wait(15);
		}
				
		yield;
	}		
	
	//object bullet task
	task invincible(x,y,v,dir,graphic,delay){
			let obj = Obj_Create(OBJ_SHOT);
			
			Obj_SetPosition(obj,x,y);
			Obj_SetSpeed(obj,v);
			Obj_SetAngle(obj,dir);
			ObjShot_SetGraphic(obj,graphic);
			ObjShot_SetDelay(obj,delay);
			ObjShot_SetBombResist(obj,true);
			
			yield;			
	}
	
	function wait(w){
		loop(w){yield;}
	}
}