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 frame=0;

    @Initialize {
	SetInvincibility(30);
	SetLife(100+10000);
	SetDamageRate(100,100);
	shotinit;
	MainTask;
    }
    task MainTask{
	let v=GetSpeed;
	let vadd=v/120;
	loop(120){
		v-=vadd;
		SetSpeed(v);
		yield;
	}
	SetAngle(GetAngleToPlayer+rand(-5,5));
	WarningLaser(GetX,GetY,GetAngle,600,20,RED60,40,1,60);
	ShootTask;
	let shotv=0;
	v=lower(vadd*120,3.5);
	vadd=v/120;
	v=0;
	loop(120){
		v+=vadd;
		SetSpeed(v);
		yield;
	}
    }
task ShootTask{
	let angle=0;
	let x;
	let y;
	loop{
		x=GetX;
		y=GetY;
		DelayNew(x,y,0,40,16,YELLOW01,28,30);

		Wait(24);
		if(!deleteobjects){
			CreateShotA(0,x,y,0);
			SetShotDataA(0,0,0,GetAngle+rand(-5,5),0,0,0,YELLOW01-GetArgument);
			SetShotDataA(0,310,0,NULL,0,0,0,ORANGE56+GetArgument);
			AddShotDelay(0,310,ORANGE01+GetArgument,10);
			SetShotDataA(0,330,0,NULL,0,2/120,2,NULL);
			FireShot(0);
		}
	}
}

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

	yield;

	frame++;
	if(GetLife<10000||GetTimer2<0.2||!OnScreen(GetX,GetY,60)||GetCommonDataDefault("KillDoll",false)){VanishEnemy;}
    }
    @DrawLoop{
	DrawDoll(GetX,GetY,frame,1);
    }

    @Finalize{
	DollFinalize;
	let color=RainbowArray(rand(60,90),100,155);
	deleteobjects=true;
	yield;
	deleteobjects=false;
	if(GetLife<10000&&GetLife!=0){

		AddScore(500);

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

		SE("enemyexplode");

		DamageAlice(10);

		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.2||GetLife==0){
		CreateExplosion(0,GetX,GetY,1,[color[0]-prand(0,100),color[1]-prand(0,100),color[2]-prand(0,100)],0.2);
	}

    }
}

