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 x=GetX;
    let y=GetY;
    let xv=cos(GetAngle)*GetSpeed;
    let yv=sin(GetAngle)*GetSpeed;
    let maxxv=rand(-1,1);
    let maxyv=GetSpeed;
    let frame=0;

    @Initialize {
	SetInvincibility(30);
	SetLife(75+10000);
	SetDamageRate(100,100);
	shotinit;
	MainTask;
	SetSpeed(0);
	SetAngle(0);
    }
    task MainTask{
	let graphics=[RED56,RED21];
	let delays=[0,4];
	let colors=[[0,7],[7,0]];
	let a=0;
	let k=0;
	if(GetArgument==trunc(GetArgument)){
		loop(20){
			a=atan2(yv,xv);
			k=0;
			loop(2){
				CreateShot01Delay(GetX,GetY,2.2,a+90,graphics[k]+colors[k][GetArgument],delays[k],40,16,10);
				CreateShot01Delay(GetX,GetY,2.2,a-90,graphics[k]+colors[k][GetArgument],delays[k],40,16,10);
					k++;
			}
			FireShot(0);
			Wait(10);
		}
	}
    }

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

	yield;
	x+=xv;
	y+=yv;
	if(absolute(xv-maxxv)<1){
		yv+=0.01;
	}
	if(yv>maxyv){yv=maxyv;}
	xv+=(maxxv-xv)/120;
	SetX(x);
	SetY(y);

	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(0,30),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.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);
	}

    }
}

