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(90);
	SetLife(85+10000);
	SetDamageRate(100,100);
	shotinit;
	if(GetSpeed==2){
		MainTask;
	}else{
		MainTask2;
	}
    }
    task MainTask{
	loop{
		SE("shot1");
		Wait(15);
		CreateShot01Delay(GetX,GetY,rand(1,2),GetAngleToPlayer,RED21,30,50,14,0);
		CreateShot01Delay(GetX,GetY,rand(1,2),GetAngleToPlayer+45,RED21,30,50,14,0);
		CreateShot01Delay(GetX,GetY,rand(1,2),GetAngleToPlayer-45,RED21,30,50,14,0);
		if(frame>60){
			CreateShot01Delay(GetX,GetY,1.5,GetAngle,RED01,30,50,14,0);
		}
	}
    }
    task MainTask2{
	loop{
		Wait(15);
		if(frame>=45){
			CreateShot01Delay(GetX,GetY,1.5,GetAngle+45,ORANGE01,30,50,14,0);
			CreateShot01Delay(GetX,GetY,1.5,GetAngle-45,ORANGE01,30,50,14,0);
		}
	}
    }

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

	yield;

	if(frame<230&&frame>60){
		SetAngle(GetAngle+GetArgument);
	}
	frame++;
	if(GetLife<10000||GetTimer2<0.2||GetCommonDataDefault("KillDoll",false)){VanishEnemy;}	
    }
    @DrawLoop{
	DrawDoll(GetX,GetY,frame,1);
    }
    @Finalize{
	let color=RainbowArray(rand(0,60),100,155);
	deleteobjects=true;
	yield;
	deleteobjects=false;
	if(GetLife<10000&&GetLife!=0){
		AddScore(500);
		DamageAlice(20);

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

    }
}
