script_enemy_main{
    let GCSD=GetCurrentScriptDirectory;
    #include_function ".\..\ShotSheet\shot_replace.dnh"
    #include_function ".\..\functions.txt"
    #include_function ".\alice_functions_doll.txt"

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

    let angle=GetAngleToPlayer;
    let frame=0;
    let maxspeed=4;
    let xv=cos(angle)*4;
    let yv=sin(angle)*4;

    @Initialize {
	SetInvincibility(90);
	SetLife(30+10000);
	SetDamageRate(100,100);
	shotinit;
	MainTask;
    }
    task MainTask{
	loop{
		Wait(300);
		SE("shot1");
		CreateShot01Delay(GetX,GetY,2,GetAngleToPlayer,BLUE01,30,50,14,0);
	}
    }

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

	xv+=cos(GetAngleToPlayer)/90;
	yv+=sin(GetAngleToPlayer)/90;
	if(distance(0,0,xv,yv)>maxspeed*maxspeed){
		angle=atan2(yv,xv);
		xv=cos(angle)*maxspeed;
		yv=sin(angle)*maxspeed;
	}
	maxspeed=upper(maxspeed-0.1,0.5);
	SetX(GetX+xv);
	SetY(GetY+yv);
	yield;

	frame++;
	if(GetLife<10000||GetTimer2<0.2||GetCommonDataDefault("KillDoll",false)){VanishEnemy;}	
    }
    @DrawLoop{
	DrawDoll(GetX,GetY,frame,1);
    }
    @Finalize{
	let color=RainbowArray(rand(240,300),100,155);
	deleteobjects=true;
	yield;
	deleteobjects=false;
	if(GetLife<10000&&GetLife!=0){
		//let numshots=center(50,distance(GetX,GetY,GetPlayerX,GetPlayerY)^0.5,200);
		//numshots/=10; //range 5-20
		//numshots=round(numshots);
		let numshots=5;

		if(OnScreen(GetX,GetY,-5)){
			let k=rand(0,360);
			loop(numshots){
				CreateShot02(GetX,GetY,-0.5,k,2/120,rand(1,2),BLUE21,2);
				CreateShot02(GetX,GetY,-0.5,k,2/120,rand(0.5,1),BLUE21,2);
				k+=360/numshots;
			}
		}

		AddScore(500);
		DamageAlice(40);

		if(GetCommonDataDefault("NoSpawnPoints",0)==0){
			CreateItems(GetX,GetY,0,1,0,0,0);
		}

		SE("enemyexplode");

		CreateExplosion(0,GetX,GetY,1,[color[0]-prand(0,100),color[1]-prand(0,100),color[2]-prand(0,100)],0.2);
		CreateExplosion(0,GetX,GetY,1,[color[0]-prand(0,100),color[1]-prand(0,100),color[2]-prand(0,100)],0.2/2);
		CreateExplosion(0,GetX,GetY,1,[color[0]-prand(0,100),color[1]-prand(0,100),color[2]-prand(0,100)],0.2/4);

	}
	if(GetTimer2<0.5||GetLife==0){
		CreateExplosion(0,GetX,GetY,1,[color[0]-prand(0,100),color[1]-prand(0,100),color[2]-prand(0,100)],0.2);
	}

    }
}

