#include "./lib_anime_fairy.dnh"
#include "./Functions2.txt"
function wait(t){loop(t){yield;}}
task Enemy01(x,y,x2,y2,type){
let pig = ObjEnemy_Create(OBJ_ENEMY);
let pigX = 0;
let pigY = 0;
ObjEnemy_Regist(pig);
SetCommonData("E1",true);
ObjMove_SetPosition(pig,x,y);
ObjMove_SetDestAtWeight(pig, x2, y2, 10,4);
Initialize_Fairy(pig,GetCurrentScriptDirectory~"img/fairy_red.png",SMALL);
DrawFairy_Task(pig);
if(type == 1){
Enemy01_Shot(pig,1);
ObjEnemy_SetLife(pig,400);
}
else if(type == 2){
Enemy01_Shot(pig,2);
ObjEnemy_SetLife(pig,400);
}
else{
Enemy01_Shot(pig,3);
ObjEnemy_SetLife(pig,400);
}
while(ObjEnemy_GetInfo(pig, INFO_LIFE) > 0 ){
pigX = ObjMove_GetX(pig);
pigY = ObjMove_GetY(pig);
		ObjEnemy_SetIntersectionCircleToShot(pig, pigX, pigY, 20);
		ObjEnemy_SetIntersectionCircleToPlayer(pig, pigX, pigY, 20);                                  
		yield;

if(pigX == -150 || pigX == GetStgFrameWidth+150||pigY==-170){
Obj_Delete(pig);
}
	}
if(pigX == -150 || pigX == GetStgFrameWidth+150||pigY==-170){
Obj_Delete(pig);
}
else{
Obj_Delete(pig);
if(GetCommonData("E1",true) == true){
boom(pigX,pigY);
SE(GetCurrentScriptDirectory~"sfx/enep.wav");
}
}
}

task Enemy01_Shot(obj,type){
wait(80);
SE(GetCurrentScriptDirectory ~ "sfx/spark.wav");
MasterSpark(obj,[ObjMove_GetX(obj),ObjMove_GetY(obj)],90,0,0,120);
wait(180);
if(type == 1){
ObjMove_SetDestAtWeight(obj, -150, ObjMove_GetY(obj), 10,4);
}
else if(type == 2){
ObjMove_SetDestAtWeight(obj, GetStgFrameWidth+150, ObjMove_GetY(obj), 10,4);
}
else if (type == 3){
ObjMove_SetDestAtWeight(obj, GetStgFrameWidth/2, -170, 10,4);
}
wait(80);
SetCommonData("E1",false);
Obj_Delete(obj);
}
task Enemy02(x,y,x2,y2,type){
let pig = ObjEnemy_Create(OBJ_ENEMY);
let pigX = 0;
let pigY = 0;
ObjEnemy_Regist(pig);
SetCommonData("E2",true);
ObjEnemy_SetLife(pig,600);
ObjEnemy_SetDamageRate(pig,70,0);
ObjMove_SetPosition(pig,x,y);
ObjMove_SetDestAtWeight(pig, x2, y2, 10,4);
Initialize_Fairy(pig,GetCurrentScriptDirectory~"img/fairy_red.png",LARGE);
DrawFairy_Task(pig);
if(type == 1){
Enemy02_Shot(pig,1);
}
else if(type == 2){
//Enemy01_Shot(pig,2);
}
else{
//Enemy01_Shot(pig,3);
}
while(ObjEnemy_GetInfo(pig, INFO_LIFE) > 0 ){
pigX = ObjMove_GetX(pig);
pigY = ObjMove_GetY(pig);
		ObjEnemy_SetIntersectionCircleToShot(pig, pigX, pigY, 20);
		ObjEnemy_SetIntersectionCircleToPlayer(pig, pigX, pigY, 20);                                  
		yield;

if(pigX == -150 || pigX == GetStgFrameWidth+150||pigY==-170){
Obj_Delete(pig);
}
	}
if(pigX == -150 || pigX == GetStgFrameWidth+150||pigY==-170){
Obj_Delete(pig);
}
else{
Obj_Delete(pig);
if(GetCommonData("E2",true)==true){
boom(pigX,pigY);

SE(GetCurrentScriptDirectory~"sfx/enep.wav");
}
}
}

task Enemy02_Shot(obj,type){
wait(80);
let angul = 0;
SE(GetCurrentScriptDirectory ~ "sfx/spark.wav");
MasterSpark(obj,[ObjMove_GetX(obj),ObjMove_GetY(obj)],90,1000*0.8,0,60*42);
MasterSpark(obj,[ObjMove_GetX(obj),ObjMove_GetY(obj)],180,1000*0.8,0,60*42);
MasterSpark(obj,[ObjMove_GetX(obj),ObjMove_GetY(obj)],270,1000*0.8,0,60*42);
MasterSpark(obj,[ObjMove_GetX(obj),ObjMove_GetY(obj)],0,1000*0.8,0,60*42);
wait(180);
loop{
if(ObjEnemy_GetInfo(obj, INFO_LIFE) ==0){break;} 
SE(GetCurrentScriptDirectory ~ "sfx/tan03.wav");
CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),0,rand(0,360),0.1,2,SMALL_RED,10);

angul+= 5;
wait(2);
}
}

task Enemy01_B(x,y,x2,y2,x3,y3,type,angle){
let pig = ObjEnemy_Create(OBJ_ENEMY);
let pigX = 0;
let pigY = 0;
ObjEnemy_Regist(pig);
SetCommonData("E3",true);
if(type == 1){
ObjEnemy_SetLife(pig,500);
}
if(type == 2){
ObjEnemy_SetLife(pig,500);
}
ObjMove_SetPosition(pig,x,y);
ObjMove_SetDestAtWeight(pig, x2, y2, 10,4);
Initialize_Fairy(pig,GetCurrentScriptDirectory~"img/fairy_red.png",SMALL);
DrawFairy_Task(pig);
if(type == 1){
Enemy01B_Shot(pig,1,angle,x3,y3);
}
else if(type == 2){
Enemy01B_Shot(pig,2,angle,x3,y3);
}
else{
//Enemy01_Shot(pig,3);
}
while(ObjEnemy_GetInfo(pig, INFO_LIFE) > 0 ){
pigX = ObjMove_GetX(pig);
pigY = ObjMove_GetY(pig);
		ObjEnemy_SetIntersectionCircleToShot(pig, pigX, pigY, 20);
		ObjEnemy_SetIntersectionCircleToPlayer(pig, pigX, pigY, 20);                                  
		yield;
if(pigX == -150 || pigX == GetStgFrameWidth+150||pigY==-170){
Obj_Delete(pig);
}
	}
Obj_Delete(pig);
if(GetCommonData("E3",true)==true){
boom(pigX,pigY);

SE(GetCurrentScriptDirectory~"sfx/enep.wav");
}
}

task Enemy01B_Shot(obj,type,angle,x3,y3){
wait(80);
if(type==1){
let angul = 0;
SE(GetCurrentScriptDirectory ~ "sfx/spark.wav");
MasterSpark(obj,[ObjMove_GetX(obj),ObjMove_GetY(obj)],angle,0,0,120);
loop(40){
if(ObjEnemy_GetInfo(obj, INFO_LIFE) ==0){break;} 
SE(GetCurrentScriptDirectory ~ "sfx/tan00.wav");
ascent(i in 0..10){
CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,angul+i*(360/10),SMALL_RED,10);
}
angul+= rand(0,360);
wait(12);
}
wait(180);
ObjMove_SetDestAtWeight(obj, x3, y3, 10,4);
wait(80);
SetCommonData("E3",false);
Obj_Delete(obj);
}
if(type==2){
let angul = 0;
MasterSpark(obj,[ObjMove_GetX(obj),ObjMove_GetY(obj)],angle,0,0,120);
loop(40){
if(ObjEnemy_GetInfo(obj, INFO_LIFE) ==0){break;}
SE(GetCurrentScriptDirectory ~ "sfx/tan00.wav"); 
ascent(i in 0..10){
CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,angul+i*(360/10),SMALL_BLUE,10);
}
angul-= rand(0,360);
wait(12);
}
wait(180);
ObjMove_SetDestAtWeight(obj, x3, y3, 10,4);
wait(80);
SetCommonData("E3",false);
Obj_Delete(obj);
}
}