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

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

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

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

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




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

sub spell//発動モーション
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(50);
        SetScore(22000000/3);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task TMove// 浮揚と移動
{
	let angle = 0;
	let count=0;
	let y=yIni;
	loop
	{
	wait(210);
	moveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	wait(90);
	}
}

task shot
{
loop
{
starshot(GetX,GetY,2,210,248,243,YELLOW01,1);
wait(120);
starshot(GetX,GetY,2,-30,248,244,GREEN01,-1);
wait(180);
}
}

task starshot(let x, let y, let speed, let angle, let grf1,let grf2,let grf3,let dir)
{
	ascent(let i in 0..6)
	{
	shotL(x,y,speed-i*0.1,angle-i*30*dir,grf1,grf2,grf3);
	wait(5);
	}
}

    task shotL(let x, let y, let speed, let angle, let grf1,let grf2,let grf3) 
{
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, grf1);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        Obj_SetPosition(obj,x, y);
	ObjShot_SetBombResist(obj,true);
 
        let objE = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(objE, grf2);
        Obj_SetAngle(objE, angle);
        Obj_SetSpeed(objE, speed);
        Obj_SetPosition(objE, x, y);
       Obj_SetCollisionToPlayer(objE, false);
	Obj_SetAlpha(objE,0);
	ObjShot_SetBombResist(objE,true);

	wait(60);
        Obj_SetSpeed(obj, 0);
        Obj_SetSpeed(objE, 0);
	ascent(let i in 0..8)
	{
	laser(Obj_GetX(obj),Obj_GetY(obj),angle+i*45,grf3);
	}
        loop(45)
	{
	ObjShot_SetDelay(objE,30);
            Obj_SetPosition(objE, Obj_GetX(obj) + speed * cos(angle),
                                  Obj_GetY(obj) + speed * sin(angle));
            yield;
        }
        Obj_Delete(objE);
        Obj_Delete(obj);
    }


task laser(let x,let y,let angle,let grf3)
{
	let speed=5;
	let length=0;
        let obj = Obj_Create(OBJ_LASER);
	ObjLaser_SetSource(obj, false);
        Obj_SetPosition(obj, x, y);
        ObjLaser_SetLength(obj, length);
        ObjLaser_SetWidth(obj, 6);
        Obj_SetAngle(obj,angle);
        ObjShot_SetBombResist(obj, true);
        ObjShot_SetGraphic(obj,grf3);
	ObjShot_SetDelay(obj, 0);
	loop(45)
	{
      		ObjLaser_SetLength(obj, length);
		length+=3;
		yield;

	}
	loop(15)
	{
      		ObjLaser_SetLength(obj, length);
		length+=5;
		yield;

	}
	while(!Obj_BeDeleted(obj))
	{
       		Obj_SetPosition(obj, Obj_GetX(obj)+speed*cos(angle), Obj_GetY(obj)+speed*sin(angle));
	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"
}
