script_enemy_main {
	#include_function ".\..\ShotSheet\shot_replace.dnh"
	#include_function ".\..\functions.txt"
	#include_function ".\e_functions.txt"

	SpellID=12;

	let frame = 0;
	let shottimer=1;
	let x=0;
	let y=0;
	let i=0;
	let i2=0;
	let i3=0;
	let angle=0;
	let attacks=1;
	let xshift=0;
	let yshift=0;
	let side=130;
	let vside=90;

	let BGscrollx=0;
	let BGscrolly=0;
	let BGscrollx2=0;
	let BGscrolly2=0;
	let BGscrollx3=0;
	let BGscrolly3=0;
	let bgrot=0;

    @Initialize {
	StartFunctions(1,1,0);
	Randomize;
        SetLife(3500);
        SetTimer2(30);
//        SetScore(50000);
	SetInvincibility(50);
	SetDamageRate(180,100);
	MagicCircle(false);
	SetEnemyMarker(true);

	EnderInit;
	LoadUserShotData(GCSD~"bullets.txt");
	shotinit;

	MainTask;
    }

function Wait(frames){loop(frames){yield;}}

task MainTask{
	SetMovePositionNew(GetCenterX,GetClipMinY+120,60);
	Wait(60);
	DelayBombTask;

	MainTask2;
	loop{
		MainShot(GetClipMinX-50,GetY,20,0,RED31,10);
		Wait(72);
		MainShot(GetClipMaxX+50,GetY,-20,180,RED31,10);
		Wait(72);
	}
}
task MainTask2{
	let i=0;
	let v1;
	let angle;
	let colors=[0,1,7];
	loop{
		SetMovePositionNew(center(GetX-40,GetPlayerX,GetX+40),GetClipMinY+120,50);
		NewChargeShrink(70,6,0.3,255,150,150);
		NewChargeShrink(80,7,0.3,255,255,255);
		Wait(80);
		i=0;
		loop(4){
			CreateExplosionFlatEX(3,GetX,GetY,0.1,[150,150,150],0.05+i/10,30);
			i++;
		}
		loop(7){
			v1=rand(4,4.5);
			angle=GetAngleToPlayer+rand(-2,2);
			CreateShot01(GetX,GetY,v1,angle,WHITE53,0);
			loop(4){
				FlameShot;
			}
			DiscardedShell;
			SE("shot2");
			Wait(14);
		}
		Wait(40);
		
	}
}

    @MainLoop {
	EnderDrawLogic;
        SetCollisionA(GetX, GetY, 35);
	SetCollisionB(GetX, GetY, 25);

	yield;
}


	let EnderFrame=0;

	let aurarot=0;
	let aurascale=0;
	let scaler=prand(1.7,1.9);

    @DrawLoop {
	EnderDrawLoop;
}


    @Finalize {
	EndingFunc(1);
	EnderFinalize;
	PointItems(GetX,GetY,1,0);
    }

	let cshot=[WHITE32,YELLOW32];

task MainShot(x,y,v,a,g,d){
    let obj = Obj_Create(OBJ_LASER);
    let stimer=0;
    let state=0;
    let shots=rand_int(0,3);
    let offset=300;
    let sound=0;

    // initial settings
    Obj_SetPosition   (obj, x-cos(a)*offset, y-sin(a)*offset);
    Obj_SetSpeed      (obj, 0);
    ObjShot_SetGraphic(obj, PURPLE56);
    ObjShot_SetDelay  (obj, 0);
    Obj_SetAngle(obj, a);
    ObjShot_SetBombResist(obj,true);
    Obj_SetAutoDelete(obj,false);
    ObjLaser_SetSource(obj,false);
    ObjLaser_SetWidth(obj,80);
    ObjLaser_SetLength(obj,130);


    while(! Obj_BeDeleted(obj)&&shots<100) {
	Obj_SetPosition(obj,Obj_GetX(obj)+v,y);
	if(Obj_GetX(obj)>GetClipMinX&&Obj_GetX(obj)<GetClipMaxX&&shots%2==0){
		SE("shot1");
//		sound=1;
	}
	loop(1){
		FadeShot(Obj_GetX(obj)+v,y,3,prand(0,360),0);
	}
	if(shots%2==0){
		CreateShot01(Obj_GetX(obj)+v,Obj_GetY(obj),(shots/2%2)/2+1.5,a+90,cshot[shots/2%2],d);
		CreateShot01(Obj_GetX(obj)+v,Obj_GetY(obj),(shots/2%2)/2+1.5,a-90,cshot[shots/2%2],d);
	}
	shots++;
        yield;
    }
    Obj_Delete(obj);

}

let cshot2=[WHITE50,RED50,ORANGE50,YELLOW50];

task FadeShot(x,y,v,a,d){
    let obj = Obj_Create(OBJ_SHOT);

    v=v*(absolute(cos(a)));

    // initial settings
    Obj_SetPosition   (obj, x,y);
    Obj_SetSpeed      (obj, v);
    ObjShot_SetGraphic(obj, cshot2[prand_int(0,3)]);
    ObjShot_SetDelay  (obj, d);
    Obj_SetAngle(obj, a);
    ObjShot_SetBombResist(obj,true);
    Obj_SetAutoDelete(obj,false);
    ObjShot_FadeDelete(obj);
}
}