#TouhouDanmakufu
#Title[SatoriNonSpell H]
#Text[Nonspell]
#BackGround[User(.\img\stage.png,0,-0.5)]
#PlayLevel[Extra]
#Player[FREE]
#BGM[.\yamabiko.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";
let shot1=csd~"se/shot1.wav";
let shot2=csd~"se/shot2.wav";
let shot3=csd~"se/shot3.wav";
let shot4=csd~"se/shot4.wav";
let spell=csd~"se/spellcard.wav";
let laser=csd~"se/lazer.wav";
let charge=csd~"se/charge2.wav";
let explo=csd~"se/explode.wav";

@Initialize
	{
	LoadUserShotData(csd~"Shot.txt");
	LoadGraphic(SatoriSprite);
	LoadGraphic(SpellBG01);
	LoadGraphic(SpellBG02);
	LoadSE(shot1);
	LoadSE(shot2);
	LoadSE(shot3);
	LoadSE(shot4);
	LoadSE(spell);
	LoadSE(laser);
	LoadSE(charge);
	LoadSE(explo);
	SetLife(500);
	SetScore(100);
	SetEnemyMarker(true);
	SetDamageRate(5,0);
	SetTimer(71);
	CutIn(YOUMU,"Unzan's Power -- Cliff Shaker",SatoriCutin,0,0,256,512);
	//let a=0;
	SetEffectForZeroLife(60,0,0);	
	

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

task Vulnerable
{
Wait(600);
SetDamageRate(10,0);
}



task LaserWall(x,y,a,d,t){
	let obj=Obj_Create(OBJ_LASER);
	let obj2=Obj_Create(OBJ_LASER);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetCollisionToPlayer(obj2,false);
	ObjLaser_SetWidth(obj,10);
	ObjLaser_SetLength(obj,500);
	ObjLaser_SetWidth(obj2,10);
	ObjLaser_SetLength(obj2,500);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetX(obj2,x);
	Obj_SetY(obj2,y);
	Obj_SetSpeed(obj,0);
	Obj_SetAngle(obj,a+90);
	Obj_SetSpeed(obj2,0);
	Obj_SetAngle(obj2,a-90);
	ObjShot_SetGraphic(obj,t);
	ObjShot_SetGraphic(obj2,t);
	ObjShot_SetDelay(obj,0);
	let ti=(0)*0.5;
	let u=0;
	let X=GetPlayerX;
	let Y=GetPlayerY;
	while(!Obj_BeDeleted(obj)){
		yield;
		ti=ti+0.5;
		u++;
		Obj_SetX(obj,x+ti*cos(a));
		Obj_SetY(obj,y+ti*sin(a));
		Obj_SetX(obj2,x+ti*cos(a));
		Obj_SetY(obj2,y+ti*sin(a));
		if(u==d-30){Obj_Delete(obj);Obj_Delete(obj2);}
		
	}
}

task Exlaser(x,y,a,n,find,gn,t){
	let obj=Obj_Create(OBJ_LASER);
	ObjLaser_SetSource(obj,false);
	Obj_SetCollisionToPlayer(obj,true);
	ObjLaser_SetWidth(obj,10);
	ObjLaser_SetLength(obj,500);
	Obj_SetX(obj,x+10*cos(a));
	Obj_SetY(obj,y+10*sin(a));
	Obj_SetSpeed(obj,0);
	Obj_SetAngle(obj,a);
	ObjShot_SetGraphic(obj,7);
	ObjShot_SetDelay(obj,30);
	let u=0;
	let X=x;
	let Y=y;
	while(X>24 && X<424 && Y>24 && Y<466){X=X+cos(a);Y=Y+sin(a);}
	while(!Obj_BeDeleted(obj)){
		yield;
		u++;
		if(u==60){ascent(i in 0..n){Shard(X,Y)};
		if(find==0){Gold(X,Y,gn,t);}
		Obj_Delete(obj);}
		
	}
}

task Gold(x,y,gn,t){
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetSpeed(obj,0);
	ObjShot_SetGraphic(obj,207);
	ObjShot_SetDelay(obj,0);
	let u=t;
	let v=0;
	let ph=0;
	let k=1;
	while(!Obj_BeDeleted(obj)){
		yield;
		u++;
		v=v+1/(1+4*sin(u)^2)*sin(u/3.4);
		if(ph==0 && u==600){ph=1; u=0; v=0;}
		if(ph==1){Obj_SetX(obj,k*x+(1-k)*(GetX+60*cos(3*u+360/5*gn)));
				Obj_SetY(obj,k*y+(1-k)*(GetY+60*sin(3*u+360/5*gn)));
				k=0.998*(k)^1.04;
				if(u==300){ph=2;u=0;}
				}
		if(ph==2){Obj_SetX(obj,(1)*(GetX+(60+180*sin(u))*cos(3*v+360/5*gn)));
				Obj_SetY(obj,(1)*(GetY+(60+180*sin(u))*sin(3*v+360/5*gn)));
				if(u%7==0){CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,3*v+360/5*gn,94,5);
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,180+(3*v+360/5*gn),94,5)};
				}
				
	}
}


task Shard(x,y){
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetSpeed(obj,0);
	ObjShot_SetGraphic(obj,82);
	ObjShot_SetDelay(obj,0);
	let u=0;
	let X=rand(-2,2);
	let Y=rand(-2,2);
	while(!Obj_BeDeleted(obj)){
		yield;
		u++;
		Obj_SetX(obj,x+X*u);
		Obj_SetY(obj,y+Y*u+0.02*u*u);
		Obj_SetAngle(obj,X^2+5*u);
	}

}


task Rip(x,y,R,a,s,t){
	let obj=Obj_Create(OBJ_SHOT);
	ObjShot_SetBombResist(obj, true);
	Obj_SetX(obj,x+R*cos(a));
	Obj_SetY(obj,y+R*sin(a));
	Obj_SetSpeed(obj,0);
	ObjShot_SetGraphic(obj,246);
	ObjShot_SetDelay(obj,30);
	Obj_SetAngle(obj,a);
	let u=0;
	let v=0;
	let w=0;
	let ut=0;
	let ph=0;
	let r=R;
	let X=rand(-2,2);
	let Y=rand(-2,2);
	while(!Obj_BeDeleted(obj)){
		yield;
		u++;
		v++;
		w++;
		ut++;
		Obj_SetX(obj,x+r*cos(a));
	Obj_SetY(obj,y+r*sin(a));
		if(ph==0 && u>=200+30*cos(a)){ph=1;u=0;}
		if(ph==1){r=R-R/30*sin(6*u);}
		if(ph==1 && v>=400+30*cos(a-60)){ph=2;v=0;}
		if(ph==2){r=R-R/30*sin(6*u)-R/30*sin(12*(v));}
		if(ph==2 && w>=600+30*cos(a-120)){ph=3;w=0;}
		if(ph==3){r=R-R/30*sin(6*u)-R/30*sin(12*(v))-R/30*sin(18*(w));}
		if(ut==710){r=R-R/30*sin(6*u)-R/30*sin(12*(v))-R/30*sin(18*(w))-R/30*sin(60*w+a);}
		if(ut==740){CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(1,2),a+rand(-10,10),240,10);
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(2,3),180+a+rand(-10,10),240,10);
		Obj_Delete(obj);}
	}

}


task Boom(x,y,let s,a,acc,ms,t,d,R,s2,n2){
let obj=Obj_Create(OBJ_SHOT);
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetSpeed(obj,s);
	ObjShot_SetGraphic(obj,t);
	ObjShot_SetDelay(obj,d);
	Obj_SetAngle(obj,a);
	let u=0;
	while(!Obj_BeDeleted(obj)){
		yield;
		if(s<ms){s+=acc;}
		Obj_SetSpeed(obj,s);
		if((Obj_GetX(obj)-GetX)^2+(Obj_GetY(obj)-GetY)^2 < R*R){
		let ra=rand(0,360);
		ascent(i in 0..n2){CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(0.5,1.5)*s2,rand(0,360),229,15)}
		ascent(i in 0..2*n2){CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(0.5,1.5)*s2*0.8,rand(0,360),202,30)}
		ascent(i in 0..3*n2){CreateShot01(Obj_GetX(obj),Obj_GetY(obj),rand(0.5,1.5)*s2*0.6,rand(0,360),40,30)}
		Obj_Delete(obj);}
		}


}


task MainTask
{
PlaySE(spell);
Wait(120);
let p1=0;
let p2=0;
let p3=0;
let p4=0;
let a=0;
let t=0;
let cj=1;
let d=200;
let w=0;
let v=180;
let r=6;
let R=200;
loop{
	yield;
	ascent(i in 0..80){PlaySE(charge);
	Rip(GetX,GetY,120,360/80*i,0,0);}
	loop(60){yield;}
	Boom(0,GetY,0,0,0.05,4,96,60,140,3,30);
	loop(120){yield;}
	PlaySE(explo);
	loop(80){yield;}
	Boom(GetX-220*cos(60),GetY-220*sin(60),0,60,0.05,4,96,60,140,3,30);
	loop(120){yield;}
	PlaySE(explo);
	loop(80){yield;}
	Boom(GetX-220*cos(120),GetY-220*sin(120),0,120,0.05,4,96,60,140,3,30);
	loop(120){yield;}
	PlaySE(explo);
	loop(80){yield;}
	ascent(i in 0..4){Boom(GetX-220*cos(30+40*i),GetY-220*sin(30+40*i),0,30+40*i,0.05,4,96,60,140,1.5,9);}
	loop(120){yield;}
	PlaySE(explo);
	loop(180){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
	{
	if(GotSpellCardBonus==true){
		
			CreateItem(ITEM_SCORE,GetX(),GetY());
			
		}
	DeleteGraphic(SatoriSprite);
	}

}