#搶曽抏枊晽
#Title[壴姤乽悧媏梿慁-Lunatic乿]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "壴姤乽悧媏梿慁-Lunatic乿";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_yuka.png"; 
    let imgFam  = csd ~ "..\img\FlowerShot.png";
    let imgBG  = csd ~ "..\img\st4bg1.png";
    let imgBG2  = csd ~ "..\img\st4bg2.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(46);

        SetLife(750);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        LoadGraphic(imgBG);
        LoadGraphic(imgBG2);
	InitializeAction();
        TMain;
    }

    @MainLoop {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;
		bgy+=2;
		BGangle+=0.2;
    }

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

    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(46);
	loop(25)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,0,1280,1920+bgy);
		SetGraphicAngle(0,0,0);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
		SetTexture(imgBG2);
		SetGraphicRect(0,0,640,640);
		SetGraphicAngle(0,0,BGangle);
		SetColor(150,150,150);
		SetAlpha(50);
		DrawGraphic(224, 240);	

	}

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

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

task summon
{
let rangle=rand(0,360);
loop
{
	let dir=rand_int(0,1)*2-1;
	rangle=rand(0,360);
	ascent(let i in 0..8)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,2,i*45+rangle, dir);
	}
	wait(30);
	ascent(let i in 0..8)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,2,i*45+rangle, -dir);
	}
	wait(30);
	ascent(let i in 0..8)
	{
		CreateEnemyFromScript("Familiar", GetX,GetY,2,i*45+rangle, dir);
	}
	wait(180);
}
}


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_Yuka.txt"
}

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\FlowerShot.png";
	let num = GetArgument;
	let angle=GetAngle;
	let IniX=GetX;
	let IniY=GetY;

    @Initialize {
        SetLife(1100);
	SetDamageRateEx(100,100,50,1);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
        yield;
	if(GetLife>1000)
	{
	SetCollisionA(GetX(),GetY(),32);
        SetCollisionB(GetX(),GetY(),4);
	}
    }

    @DrawLoop {
	if(GetLife>1000)
	{
        DrawGraphic(GetX, GetY);
	SetGraphicAngle(0,0,angle);
	SetGraphicScale(0.8,0.8)
	}
    }

    task TMain {
        yield;
	shot;
	move;
	Explode(4);
    }

task move
{
let r=0;
loop(500)
{
	SetX(IniX+r*cos(angle));
	SetY(IniY+r*sin(angle));
	yield;
	r+=2;
	angle+=1*num;
}
VanishEnemy;
}

task shot
{
wait(10);
loop
{
	loop(4)
	{
	if(GetLife<=1000)
	{
		break;
	}
/*	CreateShotA(0,GetX,GetY,5);
	SetShotDataA(0,0,0,angle,0,0,0,47);
	SetShotDataA(0,30,0,angle,0,0.01,8,47);
	FireShot(0);
	CreateShotFromScript( "shot2",GetX, GetY,0, angle, 5, 47);
*/	ShotHina(GetX,GetY,0,0,0.01,angle,5,47);
	wait(2);
	}
	wait(5);
}
}

task ShotHina(let x,let y,let Pspeed,let speed,let aspeed,let angle,let delay,let graphic)
{
	let itemx=x;
	let itemy=y;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, Pspeed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);

	loop(delay)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	loop(30)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	while(!Obj_BeDeleted(obj))
	{
		speed+=aspeed;
		Obj_SetSpeed(obj, speed);
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

    // 僌儔僼傿僢僋偺愝掕
sub setGraphic{ SetGraphicRect( 0, 0, 64, 64); }

#include_function ".\..\txt/StageEnemydata.txt"
}

#include_script ".\..\txt/EnemyShotData.txt"