#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non Spellcard 1"]
#Text["..."]
#System[".\system\Default_System.txt"]

#include"./lib/AllStarShot_Const.dnh"
#include"./lib/Functions.txt"
#include"./BGTask.txt"
#include"./Animation_lib.txt"
let Enemy = ID_INVALID;
let EnemyX = 0;
let EnemyY = 0;
let yuyuX = 0;
let yuyuY = 0;

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){SetScriptResult(1100);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
//case(EV_REQUEST_SPELL_SCORE){SetScriptResult(90000);}
}

@Initialize{
	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
ObjEnemy_SetDamageRate(Enemy,0,0);
//ObjMove_SetPosition(Enemy,-120,0);

DrawTimer03(2);//0=transition Spell-NonSpell,1=Transition NS-S,2= Spawn NS
InitializeAction(Enemy,GetCurrentScriptDirectory ~"img/dot_angel.png");
DrawBoss_Task(Enemy);
SetAutoDeleteObject(true);
name("Angel",0,30);
	BossActions;
}



@MainLoop{
	yield;
}

task BossActions{
ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 100, 20,6);
SetAction(Enemy,ACT_MOVE_R,100);
wait(120);
	ShootBullets;
//Texto;
	while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 0){
		EnemyX = ObjMove_GetX(Enemy);
		EnemyY = ObjMove_GetY(Enemy);
		ObjEnemy_SetIntersectionCircleToShot(Enemy, EnemyX, EnemyY, 20);
		ObjEnemy_SetIntersectionCircleToPlayer(Enemy, EnemyX, EnemyY, 20);
                                          
		yield;
	}
DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(Enemy);
	//loop(60){yield;}
	CloseScript(GetOwnScriptID);
}
function wait(t){loop(t){yield;}}

task ShootBullets{
//Preparation
MagicCircleEx2(Enemy,true); //Magic Circle, true means opening enabled
LifeCircleBar_A(Enemy,0.5,0.5,true);//Active Lifebar part(enemy,usable part,unusable part(empity),opening)
LifeCircleBar_B(Enemy,0.5,0.0,true);//Inactive LB part
LifeCircleBar_Marker(Enemy,0.5);//Marker
Aura1(Enemy,8,128,128,128);	//Aura(enemy,spawn rate,r,g,b)			
wait(60);		
SE(CSD~"sfx/charge00.wav");
//Concentration06(Enemy,60,255,255,255);  (enemy,time,r,g,b);
nTestCharge(EnemyX,EnemyY,90,255,255,255);
//All shot things here
let angle = 0;
let angle2 = 0;
wait(60);
let radius = 80;
//Shoot_Sub;
ObjEnemy_SetDamageRate(Enemy,40,10);
Enemies;
SE(CSD~"sfx/tan04.wav");
loop{
//SE(CSD~"sfx/tan00.wav");
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
 
 angle+= 8;
 angle2+= 10.123;
wait(2);
}
}

task Enemies{
let eimg = CSD~"img/magiccircle.png";
let e1 = CreateEnemyA1(EnemyX,EnemyY,0);
ObjPrim_SetTexture(e1,eimg);
	ObjSprite2D_SetSourceRect(e1, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(e1);
Move(e1,3.957,0);
let e2 = CreateEnemyA1(EnemyX,EnemyY,0);
ObjPrim_SetTexture(e2,eimg);
	ObjSprite2D_SetSourceRect(e2, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(e2);
Move(e2,3.957,180);
let angol = 0+ (3.957*30);
let angol2 = 180+ (3.957*30);
wait(30);
loop{
SE(CSD~"sfx/tan00.wav");
 CreateShotFA1(ObjMove_GetX(e1),ObjMove_GetY(e1),2.5,angol,PELLET_RED,1,true);
 CreateShotFA1(ObjMove_GetX(e2),ObjMove_GetY(e2),2.5,angol2,PELLET_RED,1,true);
 CreateShotFA1(ObjMove_GetX(e1),ObjMove_GetY(e1),2.5,-angol,PELLET_BLUE,1,true);
 CreateShotFA1(ObjMove_GetX(e2),ObjMove_GetY(e2),2.5,-angol2,PELLET_BLUE,1,true);
 angol+= 5;
 angol2+=5;
 wait(3);
 }
}

task Move(obj,speed,angle){
let rad = 0;
loop(30){
ObjMove_SetPosition(obj,EnemyX+rad*cos(angle),EnemyY+rad*sin(angle));
rad+=2;
angle+=speed;
wait(1);
}
loop{
 ObjMove_SetPosition(obj,EnemyX+rad*cos(angle),EnemyY+rad*sin(angle));
 angle+=speed;
 wait(1);
 }
}