#TouhouDanmakufu
#Title[Reimu s2]
#Text[Danmaku from another world.
A mythical beast that made the oceans his kingdom.
Try to not cross it's path.
Except if you want to kill it.]

#BackGround[User(.\img\BG.png,0,0)]
#PlayLevel[Normal]
#Player[FREE]
#BGM[.\bgm.mp3]
#ScriptVersion[2]



script_enemy_main{
let csd = GetCurrentScriptDirectory;


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

let Enemy = csd~"img/sprites/whitereimu.png";
let EnemyCutin = csd~"img/cut/ReimuWS.png";

let option = csd~"se/option.wav";
let Charge = csd~"se/Charge.wav";
let time01 = csd~"se/timeout0.wav";
let time02 = csd~"se/timeout1.wav";
let angle=0;
let spawnangle=0;

#include_function ".\shots\MS_Shot_Name.txt"


@Initialize
{
LoadGraphic(Enemy);	//The CutIn function will automatically load and delete the cutin later.

LoadGraphic(SpellBG1);
LoadGraphic(SpellBG2);
LoadSE(option);
LoadSE(time01);
LoadSE(time02);

SetLife(1000);		//Spell cards tend to have low health, but high resistance to damage until a certain amount of time passes.
SetDamageRate(10,5);	//This spell will take 10% damage from shots, and 5% from bombs (to prevent bombing through a card quickly).
SetTimer(45);

SetScore(100000);	//Sets the spell card bonus.


CutIn(YOUMU,"Divine Beast "\""Water Dragon's Sigh"\",EnemyCutin,0,0,256,512);

SetEffectForZeroLife(60,0,0);
	
SetMovePosition02(GetCenterX,GetCenterY-120,60);

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

MainTask;
Vulnerable;
Timer;
CallFam;
}



task CallFam{
Wait(120);
let num=1;
loop(num){ CreateEnemyFromScript("Familiar", GetEnemyX, GetEnemyY, 0,  0, spawnangle); 
spawnangle+=360/num;}		
}



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


task MainTask{
Wait(60);
SetColor(64,155,255);	
Concentration01(120);	//Charges for 2 seconds.
SetColor(255,255,255);	//Sets color back to normal.
PlaySE(Charge);

Wait(120);

}





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

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



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



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

DrawGraphic(GetX,GetY);
}


let bgalpha1 = 0;
let bgalpha2 = 0;

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

SetAlpha(bgalpha1);
SetGraphicScale(2.5,2.5);	//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(SpellBG1);
DrawGraphic(GetCenterX,GetCenterY);

SetAlpha(bgalpha2);
SetGraphicScale(2.5,2.5);	//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);
DeleteGraphic(SpellBG1);
DeleteGraphic(SpellBG2);
}

}





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

#include_function ".\shots\MS_Shot_Name.txt"

let shot5 = GetCurrentScriptDirectory~"se\shot5.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;
 
let shot6 = csd~"se/shot6.wav";
let shot1 = csd~"se/shot1.wav";

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

let angle =0;
let moveangle=GetArgument;
let b=0;
let rx=200;
let ry=200;

@Initialize
{
LoadGraphic(Familiar);
SetLife(1);
LoadUserShotData(GetCurrentScriptDirectory~".\shots\newshots9c.txt");	
FamMove;
FamAttack;
Lasers;
LoadSE(shot1);
LoadSE(shot6);
}


 @MainLoop {

SetCollisionB(GetX,GetY,32);
yield;

 }


task FamMove{
loop{

if(rx>100){rx-=0.3;}
if(ry>100){ry-=0.3;}
SetMovePosition02(GetPlayerX+rx*cos(moveangle),GetPlayerY+ry*sin(moveangle),1);
moveangle+=3.2;
yield;

}

}


task Lasers{
Wait(10);
loop{
CreateLaser01(GetX,GetY,6,moveangle,100,7,BALL_S_BLUE,10);
CreateLaser01(GetX,GetY,6,moveangle+270,100,7,BALL_S_SKY,10);
Wait(1);
	}
}


task FamAttack{
Wait(200);

loop{

loop(10){
let num=9;
loop(num){
CreateShot01(GetX,GetY,0.9,angle,RICE_M_SKY,10);
CreateShot01(GetX,GetY,1,angle+180,BALL_S_BLUE,10);
PlaySE(shot1);
angle+=360/num;}
angle+=3.3;

Wait(45);
}

Wait(120);

loop(120){
CreateShot01(GetX,GetY,8,GetAngleToPlayer-25,RICE_M_BLUE,10);
CreateShot01(GetX,GetY,8,GetAngleToPlayer+25,RICE_M_SKY,10);

CreateShot01(GetEnemyX,GetEnemyY,rand(0.5,2),rand(0,360),rand(RICE_S_BLUE,RICE_S_GREEN),10);
CreateShot01(GetEnemyX,GetEnemyY,rand(0.5,2),rand(0,360),rand(RICE_M_BLUE,RICE_M_GREEN),10);

CreateShot01(GetEnemyX,GetEnemyY,rand(0.5,2),rand(0,360),rand(DOT_BLUE,DOT_GREEN),10);
CreateShot01(GetEnemyX,GetEnemyY,rand(0.5,2),rand(0,360),rand(BALL_S_BLUE,BALL_S_GREEN),10);
CreateShot01(GetEnemyX,GetEnemyY,rand(0.5,2),rand(0,360),rand(BALL_M_BLUE,BALL_M_GREEN),10);
PlaySE(shot6);
Wait(2);
}

Wait(180);



	}//end of loop

} //end of maintask



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



@Finalize
{
}

//end of familiar script
}