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

	SpellID=27;

	let i=0;
	let frame=0;

    @Initialize {
	StartFunctions(1,0,0);
	Randomize;
        SetLife(2500);
        SetTimer2(35);
	SetDamageRate(100,100);
	SetBG(2);
	MagicCircle(false);
	SetEnemyMarker(true);
	EmpeghInit;
	EmpeghPushbackEffect;

	shotinit;

	CutIn2(1,"Noise [Echo Bolt]");
	SpellCircle2(3,1,4,250);

	MainTask;
    }


function Wait(frames){loop(frames){yield;}}
let colors=[RED56,ORANGE56,YELLOW56,GREEN56,AQUA56,BLUE56,PURPLE56];

task MainTask{
	SetMovePosition03(GetCenterX,200,10,5);
	DelayBombTask;
	Wait(60);
	let a=-90;
	let color=0;
	let i=0;
	loop{
		SE("shot3");
		Sound(GetX,GetY,2.5,a,20,40,5,RED56+color%7,4,0);
		a+=prand(15,17);
		color++;
		Wait(7);
	}
}
task Sound(x,y,v,a,l,w,s,g,d,d2){
	let widthadd=(w/s);
	loop(s){
		MainShot(x,y,v,a,l,w,g,d2);
		w-=widthadd;
		Wait(d);
	}
}

    let speed=0.8;

    @MainLoop {
        SetCollisionA(GetX, GetY, 40);
	SetCollisionB(GetX, GetY, 20);

	SetPlayerX(GetPlayerX+cos(GetAngleToPlayer)*speed);
	SetPlayerY(GetPlayerY+sin(GetAngleToPlayer)*speed);


	EmpeghDrawLogic;
	yield;
}
    @DrawLoop {
	EmpeghDrawLoop;
}

    @Finalize {
	EmpeghFinalize;
	EndingFunc(2);
	PointItems(GetX,GetY,2,1);
    }


task MainShot(x,y,v,a,l,w,g,d){
    Wait(d);

    let obj = Obj_Create(OBJ_LASER);
    let frame=0;
    let timer=0;
    let bounces=0;

    // initial settings
    Obj_SetPosition   (obj, x,y);
    Obj_SetSpeed      (obj, v);
    ObjShot_SetGraphic(obj, g);
    ObjShot_SetDelay  (obj, 10);
    Obj_SetAngle(obj, a);
    ObjLaser_SetSource(obj,false);
    ObjLaser_SetWidth(obj,w);
    ObjLaser_SetLength(obj,l);
    ObjShot_SetBombResist(obj,false);

    while(! Obj_BeDeleted(obj)) {
	x+=cos(a)*v;
	y+=sin(a)*v;

	if((x<GetClipMinX||x>GetClipMaxX)&&timer==0&&bounces<1){
		a=180-a;
		Obj_SetAngle(obj,a);
		bounces++;
	}
	if((y<GetClipMinY)&&timer==0&&bounces<1){
		a=360-a;
		Obj_SetAngle(obj,a);
		bounces++;
	}
	if(timer>0){timer--;}
	frame++;

	Obj_SetPosition(obj,x,y);
        yield;
    }

    Obj_Delete(obj);

}
}