#TouhouDanmakufu
#Title[nonspell2]
#Text[nonspell2]
#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 bg1 = CSD ~ "system\bg8.png";
let bg2 = CSD ~ "system\bg3.png";
let cx=GetCenterX();
let frame = 0;
let framedelay = 0;
let gp;
let x;
let switch = 1;
let Cut = GetCurrentScriptDirectory~"img\daiyousei11.png";
let ThisShot = GetCurrentScriptDirectory~"ZUN's shotdata.txt";
let l = CSD ~ "system\extras.png";

@Initialize
{
drawcircle(GetX,GetY+120,0,0);
CreateHitbox;
SetLife(2000);
SetDamageRate(50,50);
SetTimer(60);
mainTask;

SetInvincibility(120);
SetMovePosition03(GetCenterX, GetCenterY-120, 5, 3);
//ConcentrationEx0(120,255,0,0,true);
//PlaySE(GetCurrentScriptDirectory~"stE4Boss2.wav");
//PlayMusic(CSD~"music\thC08.mp3");
LoadGraphic(ImgBoss);
LoadUserShotData(ThisShot);
LoadGraphic(Cut);
LoadGraphic(ci);
LoadGraphic(bg1);
LoadGraphic(bg2);
LoadGraphic(l);
SetTexture(ImgBoss);
SetGraphicRect(0, 0, 64, 64);
MagicCircle(true);
Aura;

}

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

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

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

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


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

@BackGround
{

}	

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

@Finalize
{
DeleteGraphic(ImgBoss);
}

task mainTask{
	wait(60);
	fire2;
	yield;
}

task fire{
	if(switch==1){
	ascent(n in 0..20){
	Bullet(GetX, GetY, 0, n*9, 88, 10,0);
	wait(2);
	}
	}
	else if(switch==-1){
	descent(n in 0..20){
	Bullet(GetX, GetY, 0, n*9, 88, 10,0);
	wait(2);
	}
	}
	wait(180);
	loopfire;
	}

task fire2{
	LocateEnemy;
	StartMapleConcentrate;
	PlayDelaySE(CSD~"sound\charge2.wav",0);
	SetMovePositionRandom01(rand(20,50),0,2,GetClipMinX+100,rand(150,160),GetClipMaxX-100,rand(100,150));
	wait(60);
	ascent(n in 0..40)
	{
	PlayDelaySE(CSD~"sound\shot1.wav",0);
	ascent(a in 0..2){
	ascent(i in 0..3){
	CreateShotA(0,GetX-10+a*20,GetY-14,10);
	SetShotDataA(0,0,rand(3,4),360*sin(n+i+a)*2*switch,sin(n+i+a)*switch,-0.04,0,131);
	SetShotDataA(0,150,NULL,NULL,0,rand(0.01,0.015),4,132);
	FireShot(0);
	}
	}
	if(n==20){fire;}
	wait(2);
	}
	}

task loopfire{
	SetMovePositionRandom01(rand(50,50),0,1,GetClipMinX+100,rand(150,160),GetClipMaxX-100,rand(100,150));
	descent(n in 10..30){
	PlayDelaySE(CSD~"sound\shot1.wav",0);
	PlayDelaySE(CSD~"sound\Bulletwave.wav",120);
	ascent(i in 0..9){
	CreateShotA(0,GetX+(n*2)*cos(i*40+n*20),GetY+(n*2)*sin(i*40+n*20),10);
	SetShotDataA(0,0,4,i*40+n*20+n*1.5*switch,0.5*switch,-0.07,0,76);
	SetShotDataA(0,120,0,SetShotDirectionType(PLAYER),0,0.05,5,76);
	FireShot(0);
	SetShotDirectionType(ABSOLUTE);
	}
	wait(4);
	}
	wait(120);
	fire2;
	switch = -switch;
	}

task fireend{
	ascent(a in 0..10){
	ascent(i in 0..24){
	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,1.5,i+a*36,0,0,0,63);
	FireShot(0);
	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,1,i+a*36+18,0,0,0,63);
	FireShot(0);
	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,0.5,i+a*36,0,0,0,63);
	FireShot(0);
	}
	}
	wait(120);
	}

task Bullet(x, y, v, dir, graphic, delay,check) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let c = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
		 while(! Obj_BeDeleted(obj)) 
		{
		c++;
		if(Obj_GetSpeed(obj)<5){
		Obj_SetSpeed      (obj, Obj_GetSpeed(obj)+0.08);
		}
		if(c%7==0 && c>30){
		CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),0);
		SetShotDataA(0,0,0,Obj_GetAngle(obj),0,0,0,75);
		SetShotDataA(0,270,0,NULL,0,0.02,2,75);
		FireShot(0);
		}
		yield;
		}
	}


task light(x,y,v,dir,delay)
	{
    	 let e = Obj_Create(OBJ_EFFECT);
	 let c = rand_int(0,5);
	 let change = 0;
    	 Obj_SetPosition   (e, x, y);
	CreateShotA(0,x,y,delay);
	SetShotDataA(0,0,0,0,0,0,0,107);
	SetShotKillTime(0,0);
	FireShot(0);
	loop(delay){yield;}
	 Obj_SetCollisionToPlayer(e,true);
	 Obj_SetSpeed      (e, v);
    	 Obj_SetAngle      (e, dir);
	 ObjEffect_SetTexture(e,l);
	 ObjEffect_SetScale(e,0,0);
	 ObjEffect_SetRenderState(e,ADD);
	 ObjEffect_SetPrimitiveType(e,PRIMITIVE_TRIANGLESTRIP);
	 ObjEffect_CreateVertex(e, 4);
	ObjEffect_SetVertexXY(e,0,-16,-16);
	ObjEffect_SetVertexXY(e,1,16,-16);
	ObjEffect_SetVertexXY(e,2,-16,16);
	ObjEffect_SetVertexXY(e,3,16,16);
	fakebullet(Obj_GetX(e), Obj_GetY(e), 0, 0, 24, delay);
	task fakebullet(x, y, v, dir, graphic, delay) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let c = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
	 Obj_SetAlpha(obj,0);
		 while(! Obj_BeDeleted(obj)) 
		{
		Obj_SetPosition   (obj, Obj_GetX(e), Obj_GetY(e));
		yield;
		}
	      
	}
		 while(! Obj_BeDeleted(e)) 
		{
		SetCollisionB(Obj_GetX(e),Obj_GetY(e),10);
		c++;
		change+= 0.5;
		if(change<=1){
		ObjEffect_SetScale(e,change,change);
		}
		if(c>=0 && c<2){
			ObjEffect_SetVertexUV(e,0,0,56);
			ObjEffect_SetVertexUV(e,1,32,56);
			ObjEffect_SetVertexUV(e,2,0,88);
			ObjEffect_SetVertexUV(e,3,32,88);
			}
		else if(c>=2 && c<4){
			ObjEffect_SetVertexUV(e,0,32,56);
			ObjEffect_SetVertexUV(e,1,64,56);
			ObjEffect_SetVertexUV(e,2,32,88);
			ObjEffect_SetVertexUV(e,3,64,88);
			}
		else if(c>=4 && c<6){
			ObjEffect_SetVertexUV(e,0,64,56);
			ObjEffect_SetVertexUV(e,1,96,56);
			ObjEffect_SetVertexUV(e,2,64,88);
			ObjEffect_SetVertexUV(e,3,96,88);
			}
		else if (c>=6){c=0;}
		 yield;
		}
	}

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

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

}