#搶曽抏枊晽
#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_reimu.png"; 
    let imgFam  = csd ~ "..\img\FlowerShot.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;
	let BGangle=0;
    @Initialize {

       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(94);

        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(94);
	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_reimu.png"; 
    	let xIni    = GetCenterX;
    	let yIni    = GetClipMinY + 128;
	let num = GetArgument;
	let IniX=GetPlayerX;
	let IniY=GetPlayerY;
	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;
	warp;
    }

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

task warp
{
	loop
	{
		SetAction(ACT_MOVE, 240);
		if(GetX<GetClipMinX)
		{
			SetX(GetClipMaxX);
			SetSpeed(speed);
		}
		if(GetX>GetClipMaxX)
		{
			SetX(GetClipMinX);
			SetSpeed(speed);
		}
		if(GetY<GetClipMinY)
		{
			SetY(GetClipMaxY);
			SetSpeed(speed);
		}
		if(GetY>GetClipMaxY)
		{
			SetY(GetClipMinX);
			SetSpeed(speed);
		}
		yield;
	}
}

task move
{
wait(30);
	loop
	{
		let angle=rand_int(0,3)*90+rand(-15,15)+45;
		speed=10;
		SetAngle(angle);
		SetSpeed(speed);
		wait(180);
		SetSpeed(0);
		wait(60);
		speed=4;
		SetAngle(GetAngleToPlayer);
		SetSpeed(speed);
		SetAction(ACT_MOVE, 60);
		wait(60);
		SetSpeed(0);
		wait(60);
	}
}

task shot
{
wait(30);
loop
{
loop(30)
{
let angle=GetAngleToPlayer;
	ascent(let i in 0..1)
	{
		worldshot(GetX,GetY,1,angle+i*90,89,30);
		worldshot(GetX,GetY,1,angle+i*90+120,89,30);
		worldshot(GetX,GetY,1,angle+i*90+240,89,30);
	}
	wait(6);
}
wait(60);
loop(6)
{
let angle=GetAngleToPlayer;
	ascent(let i in 0..12)
	{
		worldshot(GetX,GetY,1,angle+i*30,89,30);
	}
wait(10);
}
wait(60);
}
}

task worldshot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	ObjShot_SetBombResist(obj,true);
	while(!Obj_BeDeleted(obj))
	{

		if(Obj_GetX(obj)<GetClipMinX && count==0)//嵍抂偱偺嫇摦
		{
			Obj_SetX(obj,GetClipMaxX);
			count+=1;
			ObjShot_SetBombResist(obj,false);
        	}
		if(Obj_GetX(obj)>GetClipMaxX && count==0)//塃抂偱偺嫇摦
		{
			Obj_SetX(obj,GetClipMinX);
			count+=1;
			ObjShot_SetBombResist(obj,false);
        	}
		if(Obj_GetY(obj)>GetClipMaxY && count1==0)//壓抂偱偺嫇摦
		{
			Obj_SetY(obj,GetClipMinY);
			count1+=1;
			ObjShot_SetBombResist(obj,false);
        	}
		if(Obj_GetY(obj)<GetClipMinY && count1==0)//壓抂偱偺嫇摦
		{
			Obj_SetY(obj,GetClipMinY);
			count1+=1;
			ObjShot_SetBombResist(obj,false);
        	}
		yield;
    	}

}

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