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

        SetLife(800);
        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(121);
	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);

	}

    // メインタスク
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..18)
	{
	ascent(let i in 0..way)
	{
	//	CreateShot01(GetX,GetY,0.2+j*0.25,GetAngleToPlayer+i*360/way,98,15);
		CreateShot01ToItem(GetX,GetY,0.1+j*0.20,GetAngleToPlayer+i*360/way,98,15);
	}
	wait(5);
	}
}

task Shot
{
let angle=rand(0,360);
ascent(let i in -0..46)
{
	snake2(GetCenterX+135*sin(angle),GetClipMaxY-i*10,90,0);
	angle+=6;
}
loop
{
	snake2(GetCenterX+135*sin(angle),GetClipMinY-14,90,1);
	angle+=6;
	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);
			CreateShot01ToItem(Obj_GetX(obj),Obj_GetY(obj),10,0,color,10);
			CreateShot01ToItem(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"
}
