#東方弾幕風
#Title[審判「浄玻璃審判-博麗霊夢」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "審判「浄玻璃審判-博麗霊夢」";
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(92);

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

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


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

	DrawSpellHistory;
    }
    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(92);
	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);	

	}

    // メインタスク
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 {
	GetBossShadowPosition;
        yield;
        SetCollisionA(GetX, GetY, 48);
    }

    @DrawLoop {

	DrawBossShadow( imgBoss2,150,255,0,255);
	DrawBoss( imgBoss2 );
    }

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

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 pshot
{
loop
{
	if(GetTimeOfPlayerInvincibility>0)
	{
		while(GetTimeOfPlayerInvincibility>0)
		{
			yield;
		}
		loop(10)
		{
			ascent(let i in 0..12)
			{
				worldshot(GetX,GetY,1,GetAngleToPlayer+i*30,89,30);
			}
			wait(5);
		}
	}
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);
	}
	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 itemx=x;
	let itemy=y;
	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);
	loop(delay)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	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);
        	}
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
    	}
	CreateShotChengeToItem(itemx,itemy);
}

    // グラフィックの設定
#include_function ".\..\lib/lib_anime_Reimu.txt"
#include_function ".\..\txt\data.txt"
}
}
