#TouhouDanmakufu
#Title[SatoriNonSpell H]
#Text[Nonspell]
#BackGround[User(.\img\stage.png,0,-0.5)]
#PlayLevel[Extra]
#Player[FREE]
#BGM[.\HeartfeltFancy.mp3]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\Library.dnh"

let SatoriSprite = csd~"img/Satori/SatoriSprite.png";
let SatoriCutin = csd~"img/Satori/SatoriCutin.png";
let SpellBG01 = csd~"img/Satori/SpellBG01.png";
let SpellBG02 = csd~"img/Satori/SpellBG02.png";

@Initialize
	{
	LoadUserShotData(csd~"Shot.txt");
	LoadGraphic(SatoriSprite);
	LoadGraphic(SpellBG01);
	LoadGraphic(SpellBG02);
	SetLife(2000);
	SetEnemyMarker(true);
	SetDamageRate(5,5);
	SetTimer(71);
	CutIn(YOUMU,"Vague Recollection -- Icicle Fall",SatoriCutin,0,0,256,512);
	//let a=0;
	SetEffectForZeroLife(60,0,0);	
	

MainTask;
Vulnerable;
Timer;
IdleSatori;
//MoveAbout;
SetMovePosition03(GetCenterX, GetCenterY - 130, 30,10);
}

task Vulnerable
{
Wait(600);
SetDamageRate(50,50);
}

task Icicle(s,a,k){
let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	Obj_SetSpeed(obj,s);
	Obj_SetAngle(obj,a);
	ObjShot_SetGraphic(obj,94);
	ObjShot_SetDelay(obj,0);
	let ti=30;
	let u=-1;
	let X=GetPlayerX;
	let Y=GetPlayerY;
	while(!Obj_BeDeleted(obj)){
		
		yield;
		ti--;
		u--;
		if(ti==0){Obj_SetSpeed(obj,0);
				Obj_SetAngle(obj,a+90*k);}
		if(ti==-120){Obj_SetSpeed(obj,s)};
	}
}

task Icicle2(s,a,k){
let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,GetX);
	Obj_SetY(obj,GetY);
	Obj_SetSpeed(obj,s);
	Obj_SetAngle(obj,a);
	ObjShot_SetGraphic(obj,94);
	ObjShot_SetDelay(obj,0);
	let ti=30;
	let u=-1;
	let X=GetPlayerX;
	let Y=GetPlayerY;
	while(!Obj_BeDeleted(obj)){
		
		yield;
		ti--;
		u--;
		if(ti==0){Obj_SetSpeed(obj,0);
				Obj_SetAngle(obj,a+90*k);}
		if(ti==-120){Obj_SetSpeed(obj,s)};
		if(ti==floor(-150+30*sin(a))){Obj_SetAngle(obj,a+180*k)};
	}
}


task IcicleFall(s){
let a=-40;
loop{
	loop(24){
		loop(10){yield};
		ascent(i in 6..12){Icicle(s*i/2,a,1);Icicle(s*i/2,180-a,-1);}
		a+=5;}
	a=-40;
	loop(120){yield;}
	
	loop(30){
		loop(10){yield};
		ascent(i in 6..12){Icicle2(s*i/2,a,1);Icicle2(s*i/2,180-a,-1);}
		a+=5;}
	a=-40;
	loop(120){yield;}
	}
}


task MainTask
{
Wait(120);
IcicleFall(1);

loop
	{
	yield;
	
	}
}

task MoveAbout
{
SetMovePosition02(GetCenterX,GetCenterY-120,60);
MoveSatori;
loop
	{
	Wait(250);
	SetMovePositionRandom01(64,64,1,GetClipMinX+64,GetClipMinY+64,GetClipMaxX-64,GetClipMinY+128);
	MoveSatori;
	Wait(150);
	}
}

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



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

	let bgalpha = 0;
let bgangle = 0;
let bgscroll = 0;

@BackGround
	{
	if (bgalpha < 255){bgalpha += 5;}
	bgangle += 0.3;
	bgscroll += 1;

	SetAlpha(bgalpha);
	SetGraphicScale(1,1);
	SetColor(255,255,255);

	SetTexture(SpellBG01);
SetGraphicRect(0,0,512+bgscroll,512);

	DrawGraphic(GetCenterX,GetCenterY);

	SetTexture(SpellBG02);
	SetGraphicRect(0,0,256,256);
	SetGraphicAngle(0,0,bgangle);
	DrawGraphic(GetCenterX,GetCenterY);
	}
	
@Finalize
	{
	DeleteGraphic(SatoriSprite);
	}

}