#東方弾幕風
#Title[チルノ通常2Lunatic]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "チルノ通常2Lunatic";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_cirno.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetTimer(40);
        SetLife(3000);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // メインタスク
task TMain 
{
	wait(180);
	standBy;
	Trate;
	TMove;
	shot;
	subshot;
}


task Trate
{
	wait(120);
        SetDamageRate(100, 100);
}

task TMove
{
	loop
	{
	wait(120);
	moveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	wait(30);
	}
}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

task shot
{
wait(60);
loop
{
	playershot;
	wait(150);
}
}

task playershot
{
let angle=GetAngleToPlayer;
ascent(let j in 1..12)
{
	ascent(let i in 0..j)
	{
	CreateShot01(GetX,GetY,5,angle+i*4,54,10);
	}
wait(5);
angle-=2;
}
}

task subshot
{
loop
{
	ice;
	wait(150);
}
}

task ice
{
	ascent(let j in 0..18)
	{
	let angle=GetAngleToPlayer-70;
	ascent(let i in 0..8)
	{
		CreateShot01(GetX,GetY,0.4+j*0.4,angle+i*20,BLUE02,10);
	}
	wait(5);
	}
}

task iceshot(let x, let y, let speed,let angle, let graphic, let delay, let count)
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(obj))
	{
		if(Obj_GetX(obj)<GetClipMinX)//左端での挙動
		{
			Obj_Delete(obj);
			ascent(let i in 0..30)
			{
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,i*12,54,10);
			}
        	}
		if(Obj_GetX(obj)>GetClipMaxX)//右端での挙動
		{
			Obj_Delete(obj);
			ascent(let i in 0..30)
			{
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,i*12,54,10);
			}
        	}
		if(Obj_GetY(obj)<GetClipMinY)//上端での挙動
		{
			Obj_Delete(obj);
			ascent(let i in 0..30)
			{
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,i*12,54,10);
			}
        	}
		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 ".\..\lib/lib_anime_Patchouli.txt"
}
