#東方弾幕風
#Title[幽明「六道の辻-Extra」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "幽明「六道の辻-Extra」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_komachi.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st5bg1.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 bgx=0;
	let bgy=0;
    @Initialize {

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

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

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

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

    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(120);
	loop(30)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
	ItemSet(GetX,GetY,4);
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,0,1280+bgx,960+bgy);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);

	}
    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	Shot;
}

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




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);
}


task Shot
{
let dir=rand_int(0,1)*2-1;
let w=540;
let rangle;
let color=[];
color=[48,46,43,44,41,189];
	loop
	{
		rangle=rand(0,360);
		ascent(let i in 0..6)
		{
			laser((GetPlayerX*2+GetX)/3,(GetPlayerY*2+GetY)/3,0,i*60+rangle,158,0,color[i]);
		}
		wait(60);
		rangle=rand(0,360);
		ascent(let i in 0..6)
		{
			laser((GetPlayerX*2+GetX)/3,(GetPlayerY*2+GetY)/3,0,i*60+rangle,158,0,color[i]);
		}
		wait(60);
		rangle=rand(0,360);
		ascent(let i in 0..6)
		{
			laser((GetPlayerX*2+GetX)/3,(GetPlayerY*2+GetY)/3,0,i*60+rangle,158,0,color[i]);
		}
		wait(w);
	}
}

task laser(x,y,speed,angle,grf,delay,color)
{
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, grf);
	ObjShot_SetDelay(obj, delay);
	ObjLaser_SetLength(obj, 540);
	ObjLaser_SetWidth(obj, 9);
	ObjLaser_SetSource(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	wait(60);
	RoundShot(x,y,angle,540,color);
	wait(120);
	Obj_Delete(obj);
}

task RoundShot(x,y,angle,r,color)
{
let rangle;
let pangle=rand(0,360);
loop(27)
{
rangle=rand(0,360);
	ascent(let i in 0..6)
	{
	/*	CreateShotA(0,x+r*cos(angle),y+r*sin(angle),10);
		SetShotDataA(0,0,2,i*60+pangle,6,0,0,color);
		SetShotDataA(0,60,0,NULL,0,0,0,color);
		SetShotDataA(0,90,1,NULL,0,0,0,color);
		FireShot(0);
	*/	ShotRiku(x+r*cos(angle),y+r*sin(angle),2,1,i*60+pangle,10,color);
	}
pangle+=10;
r-=20;
wait(3);
}
}	



task ShotRiku(let x,let y,let Pspeed,let Sspeed,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(60)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		Obj_SetAngle(obj, angle);
		angle+=6;
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, 0);
	loop(30)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	Obj_SetSpeed(obj, Sspeed);
	while(!Obj_BeDeleted(obj))
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}


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