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 {
	SetDamageRate(100,100);
	shotinit;
	if(GetArgument==0){
		MainTask0;
	}else{
		MainTask1;
	}
    }
    task MainTask0{
	SetInvincibility(30);
	SetLife(40+10000);
	let decel=GetSpeed/120;
	loop(120){
		SetSpeed(GetSpeed-decel);
		yield;
	}
	let color=0;
	loop(7){
		SE("shot2");
		CreateShot01Delay(GetX,GetY,1.5,GetAngle+30,RED11+color,10,40,10,9);
		CreateShot01Delay(GetX,GetY,1.5,GetAngle-30,RED11+color,-10,40,10,9);
		CreateShot01Delay(GetX,GetY,1.5,GetAngle+110,RED11+color,10,40,10,9);
		CreateShot01Delay(GetX,GetY,1.5,GetAngle-110,RED11+color,-10,40,10,9);
		color++;
		Wait(9);
	}
	Wait(60);
	loop(120){
		SetSpeed(GetSpeed-decel);
		yield;
	}
	VanishEnemy;
    }
    task MainTask1{
	SetInvincibility(100);
	SetLife(150+10000);

	let decel=GetSpeed/120;
	loop(120){
		SetSpeed(GetSpeed-decel);
		yield;
	}
	let color=GetArgument-1;
	let angle=79;
	let k=0;
	loop(30){
		SE("shot1");
		CreateShot01(GetX,GetY,2.5,90+angle,RED12+color,0);
		CreateShot01(GetX,GetY,2.5,90-angle,RED12+color,0);
//		CreateShot01(GetX,GetY,1.5,90+angle,RED12+color,0);
//		CreateShot01(GetX,GetY,1.5,90-angle,RED12+color,0);

		if(k%2==0){
			CreateShot01(GetX,GetY,1.5,10+angle,RED12+color,0);
			CreateShot01(GetX,GetY,1.5,170-angle,RED12+color,0);
		}

		k++;
		angle-=(80/30);
		Wait(8);
	}
	Wait(60);
	loop(120){
		SetSpeed(GetSpeed-decel);
		yield;
	}
	VanishEnemy;
    }



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

	yield;

	frame++;
	if(GetLife<10000||GetTimer2<0.2||GetY>GetClipMaxY+20||GetCommonDataDefault("KillDoll",false)){VanishEnemy;}
    }
    @DrawLoop{
	DrawDoll(GetX,GetY,frame,1);
    }
    @Finalize{
	DollFinalize;
	let color=RainbowArray(rand(300,360),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);
		}

		CreateShot02(GetX,GetY,0,GetAngleToPlayer,2/120,2,RED31,0);
		CreateShot02(GetX,GetY,0,GetAngleToPlayer,2/90,2,RED31,0);
		CreateShot02(GetX,GetY,0,GetAngleToPlayer,2/60,2,RED31,0);

		SE("enemyexplode");

		DamageAlice([6,12][GetArgument]);

		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);
	}

    }
}

