#TouhouDanmakufu
#Title[Reimu sfinal]
#Text[Danmaku from another world.
This fire snake can be tamed only with enough willpower and a true desire of understanding this destructive creature.
However,no one ever succeded.]

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



script_enemy_main{
let csd = GetCurrentScriptDirectory;

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 bgangle=0;

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 s=0;
let x=0;

#include_function ".\shots\MS_Shot_Name.txt"


@Initialize{

LoadGraphic(SpellBG1);
LoadGraphic(SpellBG2);

LoadGraphic(Enemy);	//The CutIn function will automatically load and delete the cutin later.
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(45);

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


CutIn(YOUMU,"Forgotten Snake King "\""Fire Basilic"\",EnemyCutin,0,0,256,512);

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

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

MainTask;
Vulnerable;
Timer;
}

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


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

Wait(120);


		let a = 80;
		let b = 120;
		let c = 12.4;
		loop {

		loop(360){
		CreateShotA(0,GetX+150*cos(a+b),GetY+80*sin(a-b),0);
		SetShotDataA(0,0,0,a+c,0,0,0,BALL_M_RED);
		SetShotDataA(0,1,0,NULL,0,0,0,BALL_S_RED);
		SetShotDataA(0,60,0,rand(0,360),0,0.05,rand(1,3),BALL_R_RED);
		FireShot(0);

		CreateShotA(1,GetX+150*cos(b+a+120),GetY+80*sin(b-a+120),0);
		SetShotDataA(1,0,0,a+c,0,0,0,BALL_M_ORANGE);
		SetShotDataA(1,1,0,NULL,0,0,0,BALL_S_ORANGE);
		SetShotDataA(1,60,0,rand(0,360),0,0.05,rand(1,3),BALL_R_ORANGE);
		FireShot(1);

		CreateShotA(2,GetX+150*cos(a+b+240),GetY+80*sin(a+b+240),0);
		SetShotDataA(2,0,0,a+c,0,0,0,BALL_M_YELLOW);
		SetShotDataA(2,1,0,NULL,0,0,0,BALL_S_YELLOW);
		SetShotDataA(2,60,0,rand(0,360),0,0.05,rand(1,3),BALL_R_YELLOW);
		FireShot(2);


		a+=0.9;
		b+=2.2;
		c+=2.9;
			PlaySE(shot6);
			Wait(1);

			}
			Wait(180);

		loop(10){
		let num=7;
		loop(num){CreateShot01(GetX,GetY,2.5,angle,BALL_L_YELLOW,10);
		CreateShot01(GetX,GetY,2.5,-angle+180,BALL_L_RED,10);
		angle+=360/num;}
		angle+=7.7;
		PlaySE(shot4);
		Wait(20);}


		Wait(180);

		loop(50){
		let num=7;
		loop(num){
		CreateShot01(GetX+60*cos(angle+x),GetY+60*sin(angle),3,angle,RICE_M_RED,10);
		CreateShot01(GetX+60*cos(angle+x),GetY+60*sin(angle),3,angle,RICE_M_ORANGE,20);
		CreateShot01(GetX+60*cos(angle+x),GetY+60*sin(angle),3,angle,RICE_M_YELLOW,30);
		angle+=360/num;}
		angle+=5.6;
		PlaySE(shot6);
		x+=7.7;
		Wait(5);}

		Wait(1);

		loop(50){
		let num=7;
		loop(num){
		CreateShot01(GetX+60*cos(-angle+180-x),GetY+60*sin(-angle+180),3,-angle+180,RICE_M_RED,10);
		CreateShot01(GetX+60*cos(-angle+180-x),GetY+60*sin(-angle+180),3,-angle+180,RICE_M_ORANGE,20);
		CreateShot01(GetX+60*cos(-angle+180-x),GetY+60*sin(-angle+180),3,-angle+180,RICE_M_YELLOW,30);
		angle+=360/num;}
		angle+=5.6;
		PlaySE(shot6);
		x+=7.7;
		Wait(5);}


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

}