#東方弾幕風
#Title[小町通常2-Extra]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "小町通常2-Extra";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_komachi.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(2500);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

    @MainLoop {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
        yield;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // メインタスク
task TMain 
{
	standBy;
	Trate;
	TMove;
	shot;
}


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

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

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

task shot
{
loop
{
loop(8)
{
Pashot(GetX,GetY,2,rand(120,420));
}
wait(60);
}
}

task Pashot(let x, let y, let speed, let angle) 
{
	let itemx=x;
	let itemy=y;
	let expangle=rand(0,360);
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, 31);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        Obj_SetPosition(obj,x, y);
	loop(60)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	if(Obj_BeDeleted(obj)==false)
	{
		ascent(let i in 0..8)
		{
			exp1(Obj_GetX(obj),Obj_GetY(obj),1.5,rand(0,360));
		}
	}
        Obj_Delete(obj);
}

task exp1(let x,let y, let speed, let angle)
{
	let itemx=x;
	let itemy=y;
	let expangle=rand(0,360);
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, 15);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        Obj_SetPosition(obj,x, y);
	loop(60)
	{
		itemx=Obj_GetX(obj);
		itemy=Obj_GetY(obj);
		if(Obj_BeDeleted(obj))
		{
			CreateShotChengeToItem(itemx,itemy);
			return;
		}
		yield;
	}
	if(Obj_BeDeleted(obj)==false)
	{
		ascent(let i in 0..8)
		{
		//	CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,rand(0,360),7,0);
			CreateShot01ToItem(Obj_GetX(obj),Obj_GetY(obj),1,rand(0,360),7,0);
		}
	}
        Obj_Delete(obj);
}


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_Komachi.txt"
}
