#東方弾幕風
#Title[死符「死鎌と止まぬ雨」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "死符「死鎌と止まぬ雨」";
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 {
	SetShotAutoDeleteClip(48,48,48,48);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(72);

        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(72);
	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;
	wait(60);
	Trate;
	Shot;
	SubShot;
	SubShot2;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
        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;
loop
{
	snake2(dir);
	wait(300);
	dir=dir*-1;
}
}

task SubShot
{
	loop
	{
		CreateShot01(rand(GetClipMinX,GetClipMaxX),GetClipMinY,rand(1,2),rand(85,95),45,20);
		wait(3);
	}
}

task SubShot2
{
	loop
	{
		loop(5)
		{
			SetShotDirectionType(PLAYER);
			CreateShot01(rand(GetClipMinX,GetClipMaxX),GetClipMinY,3,0,46,20);
			SetShotDirectionType(ABSOLUTE);
		}
		wait(60);
	}
}

task snake2(let dir)
{
	let angle=90-90*dir;
	let distance=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	let distance1=distance+15;
	let distance2=distance-15;

	let objl= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objl,GetX,GetY);
	ObjLaser_SetWidth(objl,8);
	ObjLaser_SetLength(objl,distance);
	ObjLaser_SetSource(objl,false);
        ObjShot_SetGraphic(objl,WHITE01);
	Obj_SetAngle(objl, angle);
	ObjShot_SetDelay(objl,0);
	Obj_SetCollisionToPlayer(objl,false);
	Obj_SetAlpha(objl,100);

	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, 156);
	ObjShot_SetDelay(obj, 0);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	Obj_SetPosition(obj, GetX+distance*cos(angle), GetY+distance*sin(angle));
	Obj_SetAlpha(obj,0);

	let objs= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objs,GetX+distance1*cos(angle), GetY+distance1*sin(angle));
	ObjLaser_SetWidth(objs,40);
	ObjLaser_SetLength(objs,240);
	ObjLaser_SetSource(objs,false);
        ObjShot_SetGraphic(objs,PURPLE01);   
	Obj_SetAngle(objs, angle+90*dir);
	ObjShot_SetDelay(objs,0);
	Obj_SetAutoDelete(objs,false);

	let objs2= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objs2,GetX+distance2*cos(angle), GetY+distance2*sin(angle));
	ObjLaser_SetWidth(objs2,40);
	ObjLaser_SetLength(objs2,240);
	ObjLaser_SetSource(objs2,false);
        ObjShot_SetGraphic(objs2,PURPLE01);   
	Obj_SetAngle(objs2, angle+90*dir);
	ObjShot_SetDelay(objs2,0);
	Obj_SetAutoDelete(objs2,false);

	let objs3= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objs3,GetX+distance*cos(angle), GetY+distance*sin(angle));
	ObjLaser_SetWidth(objs3,40);
	ObjLaser_SetLength(objs3,240);
	ObjLaser_SetSource(objs3,false);
        ObjShot_SetGraphic(objs3,PURPLE01);   
	Obj_SetAngle(objs3, angle+90*dir);
	ObjShot_SetDelay(objs3,0);
	Obj_SetAutoDelete(objs3,false);

	EffectOrbit(distance);

	wait(30);
	loop(30)
	{
		Obj_SetPosition(obj, GetX+distance*cos(angle), GetY+distance*sin(angle));
		CreateShadow(obj);
		angle+=6*dir;
		Obj_SetPosition(objs,GetX+distance1*cos(angle), GetY+distance1*sin(angle));
		Obj_SetAngle(objs, angle+90*dir);
		Obj_SetPosition(objs2,GetX+distance2*cos(angle), GetY+distance2*sin(angle));
		Obj_SetAngle(objs2, angle+90*dir);
		Obj_SetPosition(objs3,GetX+distance*cos(angle), GetY+distance*sin(angle));
		Obj_SetAngle(objs3, angle+90*dir);
		Obj_SetAngle(objl, angle);
		yield;
	}
	Obj_Delete(obj);
	Obj_Delete(objl);
	Obj_Delete(objs);
	Obj_Delete(objs2);
	Obj_Delete(objs3);
}

task EffectOrbit(let distance)
{
ascent(i in 0..180)
{
	Orbit(GetX+distance*cos(i*1),GetY+distance*sin(i*1));
}
}

task Orbit(let x,let y)
{
	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, PURPLE03);
	ObjShot_SetDelay(obj, 3);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	Obj_SetPosition(obj, x, y);
	Obj_SetAlpha(obj,0);
	loop(30)
	{
		ObjShot_SetDelay(obj, 3);
		yield;
	}
	Obj_Delete(obj);
}

task CreateShadow(let obj)
{
		CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),60);
		SetShotDataA(0,0,0,0,0,0,0,PURPLE03);
		SetShotKillTime(0,0);
		FireShot(0);
}

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"
}
