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

	SpellID=47;

	let i=0;
	let frame=0;

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

	shotinit;

	MainTask;
	HandleShots(30);
    }


function Wait(frames){loop(frames){yield;}}
//let colors=[YELLOW50,YELLOW50,BLUE50,BLUE50];

	let armangle=0;

let colors=[7,6,7,1];

task MainTask{
	LoadGraphic(imgEnemy);
	SetMovePosition03(GetCenterX,GetCenterY-100,10,5);
	DelayBombTask;
	Wait(100);
	let color=0;
	let i=0;
	let i2=0;
	let length=0;
	let color=0;
	let dir=1;
	loop{
		SE("shot4");
		i=GetClipMinX;
		loop(9){
			LightningLaserTempest(i+rand(-20,20),GetClipMinY,90,RandDir*20, 100,15,3, colors[color%4],rand(19,34),-15);
			color++;
			i+=(GetClipMaxX-GetClipMinX)/8;
			Wait(12);
		}
		dir=-dir;
		i2++;
	}
}
task LightningLaserTempest(x,y,angle,slope,l,w,seg,g,d,offset){
	let a=[angle+slope,angle-slope];
	let current=0;
	let angleshot=0;
	while(OffScreen(x,y,5)==0){
		angleshot=90*RandDir+rand(-10,10);
		SE("shot1");
		DelayNew(x,y,angleshot,30,16,RED21+g,d,0);
		LightningLaserPart(x,y,a[current%2],l*(lower(current+1,2)/2),w,seg,RED52+g,d);
		Wait(d);
		CreateShot02(x,y,0,angleshot,1.2/120,rand(1.5,2),RED21+g,0);
		x+=cos(a[current%2])*l*(lower(current+1,2)/2);
		x+=cos((a[0]+a[1])/2)*offset;
		y+=sin(a[current%2])*l*(lower(current+1,2)/2);
		y+=sin((a[0]+a[1])/2)*offset;
		current++;
	}
}
    let speed=1.8;
    let framef=0;

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

	OverloadDrawLogic;
	yield;
}
    @DrawLoop {
	OverloadDrawLoop;
}

    @Finalize {
	OverFinalize;
	EndingFunc(2);
	PointItems(GetX,GetY,2,0);
    }
}