#東方弾幕風
#Title[凍符「アイススネーク」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "凍符「アイススネーク」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_cirno.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st1bg2.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 BGangle=0;

    @Initialize {

	SetShotAutoDeleteClip(32,32,32,32);
	StartSpellHistory(4);

        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;
		BGangle+=0.2;
    }

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

    @Finalize {
		DeleteGraphic(imgBoss);
	EndSpellHistory(4);
	loop(10)
	{
		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,896,636);
		SetGraphicAngle(0,0,BGangle);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
	}

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

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
{
	loop
	{
		snake(GetAngleToPlayer);
		wait(100);
	}
}

task snake(Pangle)
{
			let d=15;
			let ad=300;
			let px=GetPlayerX+ad*cos(Pangle);
			let py=GetPlayerY+ad*sin(Pangle);
			let x=GetX;
			let y=GetY;
			let angle=Pangle+rand(-45,45);
			loop(8)
			{
				loop(5)
				{
					iceshot(x,y,60);
					x+=d*cos(angle);
					y+=d*sin(angle);
					wait(1);
				}
			angle=atan2(py-y,px-x)+rand(-45,45);	
			}
}

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

task ShotSnake(let x,let y,let Pspeed,let angle,let delay,let dispeed,let stopspeed,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)
	{
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}

	while(!Obj_BeDeleted(obj))
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(stopspeed<Obj_GetSpeed(obj))
		{
			Pspeed+=dispeed;
			Obj_SetSpeed(obj, Pspeed);
		}
		yield;
	}
	CreateShotChengeToItem(itemx,itemy);
}

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