#TouhouDanmakufu
#Title[utsuho]
#Text[utsuho]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Hard]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\system\Effects.txt";
#include_function ".\cutin.txt";
#include_function ".\drawall.txt";
#include_function ".\maple.txt" 
#include_function ".\hitbox.txt";
#include_function".\SnowFunc.txt";
let ImgBoss = GetCurrentScriptDirectory~"system\enm5m.png";
let imgExRumiaBack=GetCurrentScriptDirectory~"img\ExRumiaBack.png";
let CSD = GetCurrentScriptDirectory;
let ci = CSD ~ "system\NMM.png";
let cx=GetCenterX();
let frame = 0;
let framedelay = 0;
let gp;
let x;
let switch = 1;
let Cut = GetCurrentScriptDirectory~"img\Toziko.png";
let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";
let l = CSD ~ "system\extras.png";
let test = CSD ~ "system\Nuclear.png";

@Initialize
{
drawcircle(GetX,GetY+120,0,0);
CreateHitbox;
SetLife(900);
SetDamageRate(20,10);
SetTimer(60);
mainTask;

SetInvincibility(300);
SetMovePosition03(GetCenterX, GetCenterY-150, 0.1, 1.5);
//ConcentrationEx0(120,255,0,0,true);
//PlaySE(GetCurrentScriptDirectory~"stE4Boss2.wav");
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
LoadGraphic(ImgBoss);
LoadUserShotData(ThisShot);
LoadGraphic(Cut);
LoadGraphic(ci);
LoadGraphic(l);
LoadGraphic(test);
SetScore(500000);
cutin("NAZRIN", "Mononobe Scrolls 'Mystic Lightning Ball'", Cut, 0, 0, 288, 511);
SetTexture(ImgBoss);
SetGraphicRect(0, 0, 64, 64);
MagicCircle(true);
Aura;
//Border2(255,0,0);

}

//---------------------------------------------------------------

@MainLoop 
{

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);


frame++;

// Start Attack

yield;

// End Attack


// Start Boss Move


// End Boss Move



}

//---------------------------------------------------------------

@DrawLoop
{
SetTexture(ImgBoss);
SetRenderState(ALPHA);
SetAlpha(255);
SetGraphicScale(1.1, 1.1);
drawboss;
DrawHitbox;


}
//---------------------------------------------------------------

@BackGround
{
	drawbg;
}	

//---------------------------------------------------------------

@Finalize
{
DeleteGraphic(ImgBoss);
}

// main task
task mainTask{
	wait(90);
	PlayDelaySE(CSD~"sound\charge2.wav",0);
	LocateEnemy;
	StartMapleConcentrate;
	wait(60);
	fire;
	wait(240);
	bossmove;
	yield;
}

task fire{
	wait(10);
	PlayDelaySE(CSD~"sound\stars.wav",0);
	Explosion01(GetCenterX,GetCenterY,3,0.8,120);
	Explosion01(GetCenterX,GetCenterY,3,0.1,120);
	Bullet(GetCenterX,GetCenterY,0,90);
	wait(140);
	PlayDelaySE(CSD~"sound\charge2.wav",0);
	LocateEnemy;
	StartMapleConcentrate;
	wait(340);
	PlayDelaySE(CSD~"sound\charge2.wav",0);
	LocateEnemy;
	StartMapleConcentrate;
	wait(460);
	PlayDelaySE(CSD~"sound\charge2.wav",0);
	LocateEnemy;
	StartMapleConcentrate;
	}

task bossmove{
	loop{
	SetMovePositionRandom01(rand(20,50),0,2,GetClipMinX+150,rand(80,80),GetClipMaxX-150,rand(100,150));
	wait(240);
	}
	}

task Bullet(x,y,v,dir)
	{
    	 let e = Obj_Create(OBJ_EFFECT);
	 let c = 0;
	 let change = 0;
	 let blueangle= 0;
    	 Obj_SetPosition   (e, x, y);
    	 Obj_SetSpeed      (e, v);
    	 Obj_SetAngle      (e, dir);
	 ObjEffect_SetTexture(e,test);
	ObjEffect_SetScale(e,0,0);
	 ObjEffect_SetRenderState(e,ADD);
	 ObjEffect_SetPrimitiveType(e,PRIMITIVE_TRIANGLESTRIP);
	 ObjEffect_CreateVertex(e, 4);
	ObjEffect_SetVertexXY(e,0,-128,-128);
	ObjEffect_SetVertexXY(e,1,128,-128);
	ObjEffect_SetVertexXY(e,2,-128,128);
	ObjEffect_SetVertexXY(e,3,128,128);
	ObjEffect_SetVertexUV(e,0,256,256);
	ObjEffect_SetVertexUV(e,1,512,256);
	ObjEffect_SetVertexUV(e,2,256,512);
	ObjEffect_SetVertexUV(e,3,512,512);
	Obj_SetCollisionToPlayer(e,true);
	scale;
	task scale{
	if(change==0){
	loop(100){
	c+= 0.01;
	wait(1);
	}
	change++;
	}
	loop(120){
	c-= 0.001;
	wait(1);
	}
	loop(120){
	c+= 0.001;
	wait(1);
	}
	scale;
	}
		 while(! Obj_BeDeleted(e)) 
		{
		change++;
		SetCollisionB(Obj_GetX(e),Obj_GetY(e),c*120);
		ObjEffect_SetScale(e,c,c);
		if(change%40==0 && change>=180){
		blueangle = rand_int(0,19);
		PlayDelaySE(CSD~"sound\bulletwave.wav",0);
		ascent(i in 0..18){
		CreateShotA(0,Obj_GetX(e)+(c*120)*cos(i*20+blueangle),Obj_GetY(e)+(c*120)*sin(i*20+blueangle),10);
		SetShotDataA(0,0,0.5,i*20+blueangle,0.5*switch,0.01,2,240);
		SetShotDataA(0,90,NULL,NULL,0,0,0,240);
		FireShot(0);
		}
		switch = -switch;
		}
		if(change%4==0 && change>=540){
		//PlayDelaySE(CSD~"sound\bulletwave.wav",0);
		ascent(i in 0..2){
		CreateShotA(0,Obj_GetX(e)+(c*120)*cos(i*180+change*1.5),Obj_GetY(e)+(c*120)*sin(i*180+change*1.5),10);
		SetShotDataA(0,0,0.5,i*180+change*1.5+rand(-1,1),0,0,0,161);
		FireShot(0);
		}
		}
		if(change%40==20 && change>=980){
		PlayDelaySE(CSD~"sound\bulletwave.wav",0);
		ascent(i in 0..10){
		CreateShotA(0,Obj_GetX(e)+(c*120)*cos(i*36+blueangle),Obj_GetY(e)+(c*120)*sin(i*36+blueangle),10);
		SetShotDataA(0,0,1,i*36+blueangle,0,0.01,1,152);
		SetShotDataA(0,90,NULL,NULL,0,0,0,152);
		FireShot(0);
		}
		}
		 yield;
		}
	}


	function Obj_GetAngleToPlayer(obj) {
	return atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj));
	}
	function Obj_GetAngleToEnemy(obj) {
	return atan2(GetY - Obj_GetY(obj), GetX - Obj_GetX(obj));
	}

task PlayDelaySE(se,delay){
        loop(delay){yield;}
        PlaySE(se);
}
	function wait(w){
		loop(w){yield;}
			}

}