#搶曽抏枊晽
#Title[怰敾乽忩噢棡怰敾-柖塉杺棟嵐-Lunatic乿]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "怰敾乽忩噢棡怰敾-柖塉杺棟嵐-Lunatic乿";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_eiki.png"; 
    let imgBoss2 =csd ~ "..\lib/dot_marisa.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
    let imgBG  = csd ~ "..\img\st6bg1.png";
SetRateScoreSystemEnable(false);
    // 弶婜埵抲
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;

	#include_function ".\..\txt\SpellCardBonusDefine.txt"
	let SpellTimer=50;

	let bgy=0;
    @Initialize {

       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\ShotData.txt");
	StartSpellHistory(98);

        SetLife(550);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBoss2);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

    @MainLoop {
      //  SetCollisionA(GetX, GetY, 32);
      //  SetCollisionB(GetX, GetY, 16);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;
    }

    @DrawLoop {
	DrawBossShadow( imgBoss,150,255,0,255);
	DrawBoss( imgBoss );

	DrawSpellHistory;
    }


    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(98);
	loop(50)
	{
		ItemSet(GetCenterX+rand(-100,100),GetCenterY+rand(-50,50),1);
		ItemSet(GetCenterX+rand(-100,100),GetCenterY+rand(-50,50),2);
	}
	loop(50)
	{
		ItemSet(GetCenterX+rand(-100,100),GetCenterY+rand(-50,50),1);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,0,1280,1920+bgy);
		SetGraphicAngle(0,0,0);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
		bgy+=3;
	}

    // 儊僀儞僞僗僋
task TMain 
{
	standBy;
	spell;
	Trate;
	summon;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
        SetDamageRate(25, 25);
}

task summon
{
	CreateEnemyFromScript("Familiar", GetX,GetY,0,0, 1);

	SetAction(ACT_MOVE, 30);
	SetMovePosition02(xIni, GetClipMinY-128, 30);	
}


sub standBy//弶婜埵抲傊
{
	SetAction(ACT_MOVE, wIni);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

sub spell//敪摦儌乕僔儑儞
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(SpellTimer);
        SetScore(SpellBonus);
	SetAction(ACT_SPELL,90);
	wait(90);
}


#include_function ".\..\txt\data.txt"
#include_function ".\..\txt\Spelldata.txt"
#include_function ".\..\lib/lib_anime_Eiki.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\FlowerShot.png";
    let imgBoss2 =csd ~ "..\lib/dot_marisa.png"; 
	let num = GetArgument;
    	let xIni    = GetCenterX;
    	let yIni    = GetClipMinY + 128;
	let speed=10;
    @Initialize {
        SetLife(10000);
	SetDamageRateEx(100,100,100,100);
	InitializeAction();
	TMain;
    }

    @MainLoop {
        yield;
        SetCollisionA(GetX, GetY, 32);
    }

    @DrawLoop {
	DrawBossShadow( imgBoss2,150,255,0,255);
	DrawBoss( imgBoss2 );
    }

    task TMain {
        yield;
	rate;
	shot;
	move;
    }

task rate
{
	wait(1200);
	SetDamageRateEx(200,200,200,200);
	wait(600);
	SetDamageRateEx(300,300,300,300);
}

task move
{
wait(30);
let speed=0;
let dir=rand_int(0,1)*2-1;
loop
{
	SetAngle(90);
	Comet(90);
	loop(180)
	{
		SetSpeed(speed);
		speed+=0.04;
		yield;
	}
	wait(30);
	speed=0;
	if(dir==1)
	{
		SetX(GetClipMinX-30);
		SetY(GetClipMaxY+30);
		SetAngle(atan2(GetClipMinY-GetClipMaxY,GetClipMaxX-GetClipMinX));
	}
	else
	{
		SetX(GetClipMaxX+30);
		SetY(GetClipMaxY+30);
		SetAngle(atan2(GetClipMinY-GetClipMaxY,GetClipMinX-GetClipMaxX));
	}
	wait(60);
	Comet(GetAngle);
	loop(180)
	{
		SetSpeed(speed);
		speed+=0.04;
		yield;
	}
	wait(30);

	speed=0;
	if(dir==-1)
	{
		SetX(GetClipMinX-30);
		SetY(GetClipMaxY+30);
		SetAngle(atan2(GetClipMinY-GetClipMaxY,GetClipMaxX-GetClipMinX));
	}
	else
	{
		SetX(GetClipMaxX+30);
		SetY(GetClipMaxY+30);
		SetAngle(atan2(GetClipMinY-GetClipMaxY,GetClipMinX-GetClipMaxX));
	}
	wait(60);
	Comet(GetAngle);
	loop(180)
	{
		SetSpeed(speed);
		speed+=0.04;
		yield;
	}
	wait(30);
	speed=0;
	SetSpeed(speed);
	SetMovePosition02(xIni, yIni, 60);
	wait(60);
	wait(120);
	dir=dir*-1;
}
}

task shot
{
wait(30);
loop
{
	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	loop(36)
	{
		ascent(let i in 0..7)
		{
			CreateShot01(GetX,GetY,2,angle+360/7*i,121+i,5);
			CreateShot01(GetX,GetY,1,-angle+360/7*i,121+i,5);
		}
		angle+=10*dir;
		wait(5);
	}
	wait(90);
	loop(36)
	{
		ascent(let i in 0..7)
		{
			CreateShot01(GetX,GetY,2,angle+360/7*i,121+i,5);
			CreateShot01(GetX,GetY,1,-angle+360/7*i,121+i,5);
		}
		angle+=10*dir;
		wait(5);
	}
	wait(90);
	loop(60)
	{
		ascent(let i in 0..7)
		{
			CreateShot01(GetX,GetY,2,angle+360/7*i,121+i,5);
			CreateShot01(GetX,GetY,1,-angle+360/7*i,121+i,5);
		}
		angle+=10*dir;
		wait(5);
	}
	wait(90);
}

}

task Comet(angle)
{
		let length=1600;
		let wid=64;
		let angle=angle+180;
		let color=14;
		let alpha=0;
		let obj= Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,GetX-150*cos(angle),GetY-150*sin(angle));
		ObjLaser_SetWidth(obj,wid);
		ObjLaser_SetLength(obj,length);
		ObjLaser_SetSource(obj,false);
        	ObjShot_SetGraphic(obj,color);   
		Obj_SetAngle(obj, angle);
		ObjShot_SetDelay(obj,0);
		Obj_SetAlpha(obj,alpha);
		Obj_SetAutoDelete(obj,false);
		Obj_SetCollisionToPlayer(obj,false);
		loop(180)
		{
			Obj_SetPosition(obj,GetX-150*cos(angle),GetY-150*sin(angle));
			Obj_SetAlpha(obj,alpha);
			alpha+=1.5;
			yield;
		}
		loop(90)
		{
			Obj_SetAlpha(obj,alpha);
			alpha-=8/3;
			yield;
		}
	Obj_Delete(obj);
}


    // 僌儔僼傿僢僋偺愝掕
#include_function ".\..\lib/lib_anime_Marisa.txt"
#include_function ".\..\txt\data.txt"
}
