#東方弾幕風
#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 {
	SetShotAutoDeleteClip(16,16,16,16);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(66);

        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(66);
	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;
	SubShot;
	move;
}

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

task move
{
wait(420);
	loop
	{
	moveToPlayer(rand(30, 40), rand(-30,30), 30,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	wait(300);
	}
}


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 SubShot
{
wait(180);
loop
{
	KasokuShot;
	wait(300);
}
}

task KasokuShot
{
let way=30;
	ascent(let j in 0..16)
	{
	ascent(let i in 0..way)
	{
		CreateShot01(GetX,GetY,0.2+j*0.25,GetAngleToPlayer+i*360/way,98,15);
	}
	wait(5);
	}
}

task Shot
{
let angle=rand(0,360);
ascent(let i in -0..46)
{
	snake2(GetCenterX+115*sin(angle),GetClipMaxY-i*10,90,0);
	angle+=5;
}
loop
{
	snake2(GetCenterX+115*sin(angle),GetClipMinY-14,90,1);
	angle+=5;
	wait(5);
}
}

task snake2(let Central,let y,let angle,let judg)
{
	let color=6;
	let distance=55;
	let speed=2;

        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, color);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        Obj_SetPosition(obj,Central+distance, y);
	ObjShot_SetDelay(obj,90);
	ObjShot_SetBombResist(obj,true);

        let obj2 = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj2, color);
        Obj_SetAngle(obj2, angle);
        Obj_SetSpeed(obj2, speed);
        Obj_SetPosition(obj2,Central-distance, y);
	ObjShot_SetDelay(obj2,90);
	ObjShot_SetBombResist(obj2,true);


	if(judg==0)
	{
		Effect(Central,y);
	}
	wait(90);
		while(!Obj_BeDeleted(obj))
		{
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),10,0,color,10);
			CreateShot01(Obj_GetX(obj2),Obj_GetY(obj2),10,180,color,10);
			wait(5);
		}
}

task Effect(let Central,let y)
{
loop(90)
{
	EfShot(Central,y);
	EfShot2(Central,y);
	wait(1);
}
}

task EfShot(let Central,let y)
{
	let color=6;
	let distance=50;
	let Efspeed=20;

	let obj3 = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj3, color);
        Obj_SetAngle(obj3, 0);
        Obj_SetSpeed(obj3, Efspeed);
        Obj_SetPosition(obj3,Central+distance, y);
	ObjShot_SetDelay(obj3,10);
	while(!Obj_BeDeleted(obj3))
	{
       		Obj_SetPosition(obj3,Central+distance+Efspeed, y);
		ObjShot_SetDelay(obj3,10);
		Efspeed+=20;
		y+=2;
		yield;
	}
}

task EfShot2(let Central,let y)
{
	let color=6;
	let distance=50;
	let Efspeed=20;

	let obj3 = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj3, color);
        Obj_SetAngle(obj3, 0);
        Obj_SetSpeed(obj3, Efspeed);
        Obj_SetPosition(obj3,Central-distance, y);
	ObjShot_SetDelay(obj3,10);
	while(!Obj_BeDeleted(obj3))
	{
       		Obj_SetPosition(obj3,Central-distance-Efspeed, y);
		ObjShot_SetDelay(obj3,10);
		Efspeed+=20;
		y+=2;
		yield;
	}
}

function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition02(x, y, frame);
	SetAction(ACT_MOVE,60);
}

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