#TouhouDanmakufu
#Title[Reimu s5]
#Text[Danmaku from another world.
A mystical performance where one's spiritual power is used.
However,it also causes strange events.Such as feeling another presence,while you're alone...]
#BackGround[User(.\img\BG.png,0,0)]
#PlayLevel[Normal]
#Player[FREE]
#BGM[.\bgm.mp3]
#ScriptVersion[2]



script_enemy_main{
let csd = GetCurrentScriptDirectory;

let bgangle=0;

let Enemy = csd~"img/sprites/whitereimu.png";
let EnemyCutin = csd~"img/cut/ReimuWS.png";
let SpellBG1 = csd~"img/sprites/BG1.png";
let SpellBG2 = csd~"img/sprites/BG2.png";
let shot6 = csd~"se/shot6.wav";
let shot4 = csd~"se/shot4.wav";
let Charge = csd~"se/Charge.wav";
let time01 = csd~"se/timeout0.wav";
let time02 = csd~"se/timeout1.wav";
let angle=0;
let acc=0;
let x=0;
let y=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(shot6);
LoadSE(shot4);
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(60);

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


CutIn(YOUMU,"Spiritual Presence "\""Undenfined Presence"\",EnemyCutin,0,0,256,512);

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

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

MainTask;
Vulnerable;
Timer;
}


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




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


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

loop{

loop(30){
let num=13;
loop(num){
CreateShotA(1,GetEnemyX,GetEnemyY,20);
SetShotDataA(1,0,0,angle,0,0.02,3,BALL_L_PURPLE);
FireShot(1);

CreateShotA(2,GetEnemyX,GetEnemyY,20);
SetShotDataA(2,0,0,-angle+180,0,0.02,3,BALL_L_WHITE);
FireShot(2);

angle+=360/num;}
angle=angle+acc;
acc+=0.6;
PlaySE(shot6);
Wait(20);}

Wait(180);
Move;
Wait(60);

loop(14){
x=rand(-50,50);
y=rand(-50,50);
let num=30;
loop(num){
CreateShotA(1,GetEnemyX+x,GetEnemyY+y,20);
SetShotDataA(1,0,8,angle,0,-0.3,1.5,DOT_GREEN);
FireShot(1);
angle+=360/num;}
angle=angle+14.7;
PlaySE(shot4);
Wait(10);}

Wait(90);
Move;

loop(60){
let num=5;
loop(num){
CreateShotA(1,GetEnemyX,GetEnemyY,20);
SetShotDataA(1,0,0,angle,0,0.02,rand(1,3),CARD_PURPLE);
FireShot(1);

CreateShotA(2,GetEnemyX,GetEnemyY,20);
SetShotDataA(2,0,0,angle+180,0,0.02,rand(1,3),CARD_WHITE);
FireShot(2);

angle+=360/num;}
angle+=2.7;
PlaySE(shot6);
Wait(1);}

Wait(90);
Move;

Wait(90);

loop(14){
x=rand(-50,50);
y=rand(-50,50);
let num=20;
loop(num){
CreateShotA(1,GetEnemyX+x,GetEnemyY+y,20);
SetShotDataA(1,0,8,angle,0,-0.3,2,RICE_M_WHITE);
FireShot(1);

CreateShotA(2,GetEnemyX-x,GetEnemyY-y,20);
SetShotDataA(2,0,8,angle,0,-0.3,1.5,RICE_M_PURPLE);
FireShot(2);
angle+=360/num;}
angle=angle+14.7;
PlaySE(shot4);
Wait(10);}


SetMovePosition02(GetCenterX,GetCenterY-120,60);
Wait(180);


	}
}





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);
}

}

