#東方弾幕風
#Title[幽明「六道の辻-Lunatic」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "幽明「六道の辻-Lunatic」";
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(62);

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

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

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

    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(62);
	loop(30)
	{
		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+bgx,960+bgy);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);
		bgx+=3;
		bgy+=3;
	}
    // メインタスク
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*3+GetX)/4,(GetPlayerY*3+GetY)/4,0,i*60+rangle,158,0,color[i]);
		}
		wait(60);
		rangle=rand(0,360);
		ascent(let i in 0..6)
		{
			laser((GetPlayerX*3+GetX)/4,(GetPlayerY*3+GetY)/4,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);
	}
pangle+=10;
r-=20;
wait(3);
}
}	


function iceshot(x,y,delay)
{
		CreateShotA(0,x,y,delay);
		SetShotDataA(0,0,3,rand(0,360),0,-0.2,rand(0.8,1.2),BLUE01);
		FireShot(0);
}


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