#TouhouDanmakufu
#Title[Mima n4]
#Text[Mima]
#BackGround[]
#PlayLevel[Normal]
#Player[FREE]
#BGM[]
#ScriptVersion[2]


script_enemy_main{

#include_function ".\shots\MS_Shot_Name.txt"

let csd = GetCurrentScriptDirectory;	//This is just so I don't have to type this every single time.
let  Enemy = csd~"img\sprites\mima.png";

let option = GetCurrentScriptDirectory~"se\option.wav";
let time1 = GetCurrentScriptDirectory~"se\timeout0.wav";
let time2 = GetCurrentScriptDirectory~"se\timeout1.wav";
let wave=0;
let angle=90;
let r=0;
let x=0;
let spawnangle=0;

@Initialize{


LoadUserShotData(GetCurrentScriptDirectory~".\shots\newshots9c.txt");

LoadSE(option);
LoadGraphic(Enemy);
SetTimer(45);
SetMovePosition02(GetCenterX,GetCenterY-60,60);
SetLife(3000);		
SetEffectForZeroLife(60,0,0);

Move;
MainTask;
Timer;
CallFam;
}


task CallFam{
Wait(120);
PlaySE(option);
let num=3;
loop(num){ CreateEnemyFromScript("Familiar", GetX, GetY, 0,  0, spawnangle); 
spawnangle+=360/num;}		
}


function Wait(t){loop(t){yield;}}

task Move{
Wait(360);
SetMovePosition02(GetCenterX+rand(-50,50),GetCenterY-rand(80,130),60);
	
}



task Timer{
loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time1);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time2);}
	Wait(60);
	}
}








@MainLoop{
SetCollisionA(GetX,GetY,32);
SetCollisionB(GetX,GetY,32);
yield;
}





task MainTask{

SetInvincibility(180);  //Can't be hit during her charge effect.

Wait(60);

SetColor(255,64,255);	
Concentration01(120);

Wait(120);

SetColor(255,255,255);	//Sets color back to normal.

}



@DrawLoop{
SetGraphicRect(44,34,87,95);
SetAlpha(255);
SetGraphicScale(1,1);
SetColor(255,255,255);
SetGraphicAngle(0,0,0);
SetTexture(Enemy);
DrawGraphic(GetX,GetY);

}

@Finalize{
DeleteGraphic(Enemy);
}

//end of boss script
}





/////////////////FAMILIAR//////////////////
script_enemy Familiar {

#include_function ".\shots\MS_Shot_Name.txt"

let shot5 = GetCurrentScriptDirectory~"se\shot5.wav";
let shot4 = GetCurrentScriptDirectory~"se\shot4.wav";
let csd = GetCurrentScriptDirectory;	//This is just so I don't have to type this every single time.
let  Familiar = csd~"img\sprites\familiar.png";
let famangle=0;

function Wait(t){loop(t){yield;}}

let angle =0;
let moveangle=GetArgument;
let acc=0;
let rx=0;
let ry=0;
@Initialize
{
LoadGraphic(Familiar);
SetLife(1);
LoadUserShotData(GetCurrentScriptDirectory~".\shots\newshots9c.txt");	
FamMove;
FamAttack;
LoadSE(shot5);
LoadSE(shot4);
}


 @MainLoop {

SetCollisionB(GetX,GetY,32);
yield;

 }


task FamMove{
loop{

if(rx<70){rx+=1.5;}
if(ry<60){ry++;}
SetMovePosition02(GetEnemyX+rx*cos(moveangle),GetEnemyY+ry*sin(moveangle),1);
moveangle+=3.6;




yield;

}

}



task FamAttack{

Wait(100);
loop{


		loop(90){
		acc+=7.8;
		CreateShotA(1,GetX,GetY,10);
		SetShotDataA(1,0,1,moveangle+acc,0,0,1,STAR_S_PURPLE);
		SetShotDataA(1,60,0,NULL,0,-0.05,-2,NULL);
		FireShot(1);
		PlaySE(shot5);

		Wait(2);}





Wait(60);
Explosion01(GetEnemyX,GetEnemyY,5,0.1,120);
PlaySE(shot4);

let num=25;
loop(num){
		CreateShotA(1,GetEnemyX,GetEnemyY,10);
		SetShotDataA(1,0,3,angle,4,-0.01,0,BALL_M_PURPLE);
		SetShotDataA(1,60,0,NULL,0,0.05,2,NULL);
		FireShot(1);

		CreateShotA(2,GetEnemyX,GetEnemyY,10);
		SetShotDataA(2,0,3,-angle+180,-4,-0.01,0,BALL_M_PURPLE);
		SetShotDataA(2,60,0,NULL,0,0.05,2,NULL);
		FireShot(2);

angle+=360/num;}


Wait(240);

	}//end of loop

} //end of maintask



@DrawLoop
{
famangle++;
SetGraphicRect(64, 64, 128, 128);
SetAlpha(255);
SetGraphicScale(1,1);
SetColor(255,255,255);
SetGraphicAngle(0,0,famangle*3);
SetTexture(Familiar);
DrawGraphic(GetX,GetY);
}



@Finalize
{
}

//end of familiar script
}