#TouhouDanmakufu
#Title[Reimu's Danmaku Sandwich]
#Text[Nonspell]
#BackGround[]
#PlayLevel[Normal]
#Player[FREE]
#ScriptVersion[2]



script_enemy_main
{
let csd = GetCurrentScriptDirectory;
#include_function ".\Boss.dnh"
let ReimuSprite = csd~"img/ReimuSprite.png";
let ReimuCutin = csd~"img/ReimuCutin.png";
let BG = csd~".\bg.png";
let Shot2 = csd~"se/Shot1.wav";
let Laser1 = csd~"se/Laser1.wav";
let Charge = csd~"se/Charge.wav";
let time01 = csd~"se\timeout01.wav";
let time02 = csd~"se\timeout02.wav";


@Initialize
{
LoadGraphic(ReimuSprite);
LoadGraphic(BG);
LoadSE(Shot2);
LoadSE(Charge);
LoadSE(time01);
LoadSE(time02);

SetLife(2000);
SetDamageRate(10,5);
SetTimer(60);

//SetScore(100000);

//CutIn(YOUMU,"Nonspell Homing Amulets",ReimuCutin,0,0,256,512);
SetEffectForZeroLife(60,0,0);	
SetMovePosition02(GetCenterX,GetCenterY-120,60);
LoadUserShotData(GetCurrentScriptDirectory~"Shot.txt");

MainTask;

Vulnerable(10,5,120,100,15);

}



task Heaven{let a=0;
loop{yield;
if(OnBomb){SetInvincibility(360);break;}
}
loop{yield;
loop(10){CreateShot01(GetX,GetY,rand(5,7),rand(0,360),rand_int(95,97),20);}}
}

task Hell{loop{yield;
if(OnPlayerMissed){loop(75){yield;};SetLife(0);}
}}
task MainTask{
let a = 0;
Heaven;
Hell;
Wait(60);
SetColor(255,64,64);
Concentration01(120);
SetColor(255,255,255);
PlaySE(Charge);

loop{	loop(3){
		//ascent(i in 0..60){CreateShot01(GetX+120*cos(360/60*i),GetY+120*sin(360/60*i),2,180+atan2(GetY+120*sin(360/60*i)-GetPlayerY,GetX+120*cos(360/60*i)-GetPlayerX),95,30);}
		ascent(i in 0..60){CreateShot01(GetX+160*cos(360/60*i),GetY+160*sin(360/60*i),4,180+atan2(GetY+160*sin(360/60*i)-GetPlayerY,GetX+160*cos(360/60*i)-GetPlayerX),96,30);}
		ascent(i in 0..60){CreateShot02(GetX,GetY,5+(-1)^i,6*i,-0.1,3,95,0)}
		loop(60){yield};
		}
		//ascent(i in 0..30){CreateShot01(GetX+80*cos(360/30*i),GetY+80*sin(360/30*i),2/3,180+atan2(GetY+80*sin(360/30*i)-GetPlayerY,GetX+80*cos(360/30*i)-GetPlayerX),107,30);}
		PlaySE(Shot2);
		ascent(j in 0..3){ascent(i in 0..60){CreateShot02(GetX,GetY,5-(-1)^i,6*i+j,-0.1,3,97,3*j)}}}
	
	
	
		
		PlaySE(Shot2);
		yield;
		

	
	
	PlaySE(Shot2);
	
	
	
	
	
}



task MoveAbout{
loop
	{
	SetMovePositionRandom01(64,64,4,GetClipMinX+128,GetClipMinY+64,GetClipMaxX-128,GetClipMinY+128);
	
	Wait(90);
	}
}





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



let BR = [0,0,64,80];
let bossflip = 0;
let ani = 0;

task MoveAnimation
{
ani++;
let currentani = ani;

if (GetSpeedX > 0)
	{
	bossflip = 0;
	loop(8){if(currentani==ani){BR = [0,80,64,160]; yield;}}
	loop(8){if(currentani==ani){BR = [64,80,128,160]; yield;}}
	loop(8){if(currentani==ani){BR = [128,80,192,160]; yield;}}
	while(GetSpeed>0 && currentani==ani){BR = [192,80,256,160]; yield;}
	}
else{if (GetSpeedX < 0)
	{
	bossflip = 1;
	loop(8){if(currentani==ani){BR = [0,80,64,160]; yield;}}
	loop(8){if(currentani==ani){BR = [64,80,128,160]; yield;}}
	loop(8){if(currentani==ani){BR = [128,80,192,160]; yield;}}
	while(GetSpeed>0 && currentani==ani){BR = [192,80,256,160]; yield;}
	}}
if(currentani==ani){BR = [0,0,64,80];}
}

@DrawLoop
{
SetAlpha(255);
if (bossflip==0){SetGraphicScale(1,1);}
if (bossflip==1){SetGraphicScale(-1,1);}
SetColor(255,255,255);
SetGraphicAngle(0,0,0);
SetTexture(ReimuSprite);
SetGraphicRect(BR[0],BR[1],BR[2],BR[3]);
DrawGraphic(GetX,GetY);
}

let bgalpha = 0;
let bgangle = 0;

@BackGround
{

}


@Finalize
{
DeleteGraphic(ReimuSprite);

}

}