#TouhouDanmakufu
#Title[Youmu s2]
#Text[A warrior spell.Clearing all senses to focus on the enemy.However,since she didn't use it recenly and didn't meditate about this spell,it's power is greatly reduced.]
#BackGround[]
#PlayLevel[Normal]
#Player[FREE]
#BGM[]
#ScriptVersion[2]


script_enemy_main{


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

let SpellBG1 = csd~"img/sprites/BG1.png";
let SpellBG2 = csd~"img/sprites/BG2.png";
let bgangle=0;

let shot5 = GetCurrentScriptDirectory~"se\shot5.wav";

let explode = GetCurrentScriptDirectory~"se\explode.wav";
let time1 = GetCurrentScriptDirectory~"se\timeout0.wav";
let time2 = GetCurrentScriptDirectory~"se\timeout1.wav";

let angle=0;
let turn=0;
let acc=0;
@Initialize{

LoadSE(explode);

LoadSE(shot5);
LoadGraphic(Enemy);

LoadGraphic(SpellBG1);
LoadGraphic(SpellBG2);

SetTimer(90);
SetMovePosition02(GetCenterX,GetCenterY-60,60);
LoadUserShotData(GetCurrentScriptDirectory~".\shots\newshots9c.txt");	//Loads the shot definition file, allowing us to use many more types of bullets.


SetLife(1000);		
SetDamageRate(10,5);
SetScore(100000);
CutIn(YOUMU,"Empty Perception "\""6-root Cleansing"\",EnemyCutin,0,0,256,512);
SetEffectForZeroLife(60,0,0);
Move;
MainTask;
Timer;
Vulnerable;
CallMyon;
}


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


task CallMyon{
Wait(180);

CreateEnemyFromScript("Myon", GetX, GetY, 0,  0, 0); 
}



task Vulnerable
 {
Wait(1200);
SetDamageRate(50,50);	//Becomes more vulnerable after 20 seconds.
}



task Move{
loop{
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);

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

loop{
let x=rand(-50,50);
let y=rand(-50,50);
let num=6;
loop(num){
ascent(i in 0..21){
CreateShot01(GetX+x,GetY+y,1+i/8,angle+i*6,39,10);
CreateShot01(GetX+x,GetY+y,1+i/8,angle-i*6,39,10);


}
angle+=360/num;}
angle+=14.7;
PlaySE(shot5);
Wait(600);



		}


}//end of maintask



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

}



let bgalpha1 = 0;
let bgalpha2 = 0;

@BackGround{
bgangle-=0.4;
if (bgalpha1 < 255){bgalpha1 += 5;}
if (bgalpha2 < 255){bgalpha2 += 5;}

SetAlpha(bgalpha1);
SetGraphicScale(2.2,2.2);	//The background is scaled up so it can fill the whole screen.
SetColor(255,255,255);
SetGraphicRect(0,0,256,256);
SetTexture(SpellBG1);
DrawGraphic(GetCenterX,GetCenterY);

SetAlpha(bgalpha2);
SetGraphicScale(2.2,2.2);	//The background is scaled up so it can fill the whole screen.
SetColor(255,255,255);
SetGraphicRect(0,0,256,256);
SetGraphicAngle(0,0,bgangle);
SetTexture(SpellBG2);
DrawGraphic(GetCenterX,GetCenterY);


//Remember to set everything back to default before drawing something else 
}


@Finalize{
DeleteGraphic(Enemy);
PlaySE(explode);
}

//end of boss script
}





///////////MYON//////////////////
script_enemy Myon {

let csd = GetCurrentScriptDirectory;	//This is just so I don't have to type this every single time.

let shot6 = GetCurrentScriptDirectory~"se\shot6.wav";

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

let angle2 =0;
let moveangle=0;
let acc=0;
let rx=0;
let ry=0;

@Initialize
{
SetLife(1);
LoadUserShotData(GetCurrentScriptDirectory~".\shots\newshots9c.txt");

LoadSE(shot6);

MyonTask;
MyonMove;
MyonAura;

}


 @MainLoop {

SetCollisionB(GetX,GetY,32);
yield;

 }


task MyonMove{
loop{


if(rx<100){rx+=0.2;}
if(ry<100){ry+=0.2;}
SetMovePosition02(GetEnemyX+rx*cos(moveangle),GetEnemyY+ry*sin(moveangle),1);
moveangle+=2.7;
Wait(1);}



}

task MyonAura{


loop{

		CreateShotA(1,GetX+rand(-10,10),GetY+rand(-10,10),rand(20,40));	
		SetShotDataA(1,0,0,rand(0,360),0,0,0,5);			
		SetShotKillTime(1,0);
		FireShot(1);

Wait(1);
	}

} //end of maintask




task MyonTask{


loop{


		loop(30){CreateShot01(GetX,GetY,rand(0.5,2),rand(0,360),5,0);}
		loop(20){CreateShot01(GetX,GetY,rand(1,2.5),rand(0,360),14,0);}
PlaySE(shot6);

Wait(60);



	}

} //end of maintask



@DrawLoop
{


}



@Finalize
{
}


}