
#Title[光雨「フラッシュレイン」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "光雨「フラッシュレイン」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/patchouli_dot.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
    @Initialize {
        LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(1600);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // メインタスク
task TMain 
{
	yield;
	standBy;
	spell;
	Trate;
	shot;
	SubShot;
}

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




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 SubShot
{
loop
{
	shotL(GetX,GetY,rand(0.5,3),rand(0,60),232,229,230);
	shotL(GetX,GetY,rand(0.5,3),rand(60,120),232,229,230);
	shotL(GetX,GetY,rand(0.5,3),rand(120,180),232,229,230);
	wait(120);
}
}

task shot
{
loop
{
CreateShot01(rand(GetClipMinX,GetClipMaxX),GetClipMinY,rand(2.5,3),rand(88,92),45,10);
wait(2);
}
}


    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);
 
        let obj2 = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj2, grf1);
        Obj_SetCollisionToPlayer(obj2, false);
        Obj_SetAngle(obj2, angle);
        Obj_SetSpeed(obj2, speed);
        Obj_SetPosition(obj2, x, y);

       SetShotColor(0, 180, 255);

        let objE = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(objE, grf2);
        Obj_SetAngle(objE, angle);
        Obj_SetSpeed(objE, speed);
        Obj_SetPosition(objE, x, y);

       SetShotColor(0, 0, 255);

        let objE2 = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(objE2, grf3);
        Obj_SetAngle(objE2, angle);
        Obj_SetSpeed(objE2, speed);
        Obj_SetPosition(objE2, x, y);

       SetShotColor(255, 255, 255);

        let frame = 0;
        while(Obj_BeDeleted(obj) == false) {
            if(frame % 12 == 0) {
                ObjShot_SetDelay(objE, 26);
            } else if(frame % 12 == 6) {
                ObjShot_SetDelay(objE2, 26);
            }
            Obj_SetPosition(objE, Obj_GetX(obj) + speed * cos(angle),
                                  Obj_GetY(obj) + speed * sin(angle));
            Obj_SetPosition(objE2, Obj_GetX(obj) + speed * cos(angle),
                                   Obj_GetY(obj) + speed * sin(angle));
            frame ++;
	if(frame>=60)
	{
		ascent(let i in 0..8)
		{
			laser(Obj_GetX(obj),Obj_GetY(obj),158,angle+i*45,25,20,angle+i*45);
		}
      		Obj_Delete(obj);
	}
            yield;
        }

        ObjShot_SetDelay(objE, 0);
        Obj_SetSpeed(objE, speed);
        Obj_SetAngle(objE, angle);
        ObjShot_SetDelay(objE2, 0);
        Obj_SetSpeed(objE2, speed);
        Obj_SetAngle(objE2, angle);
        Obj_Delete(obj2);
        Obj_Delete(objE);
        Obj_Delete(objE2);
    }

task laser(let x,let y,let color,let angle,let length,let count,let baseangle)
{

        let obj = Obj_Create(OBJ_LASER);
        ObjLaser_SetSource(obj, false);
        Obj_SetPosition(obj, x, y);
        ObjLaser_SetLength(obj, length);
        ObjLaser_SetWidth(obj, 3);
        Obj_SetAngle(obj,angle);
        ObjShot_SetBombResist(obj, true);
        ObjShot_SetGraphic(obj, color);
	Obj_SetAutoDelete(obj,false);
        Obj_SetCollisionToPlayer(obj, false);
	let d=length/5;
	ascent(let i in 0..5)
	{
		lasershot(x+d*i*cos(angle),y+d*i*sin(angle),5,2);
	}

	wait(1);
	let angle2=angle+rand(-20,20);
	if(atan2(Obj_GetY(obj)-GetY,Obj_GetX(obj)-GetX)>=baseangle+15)
	{
		angle2=baseangle+rand(0,-20);
	}
	if(atan2(Obj_GetY(obj)-GetY,Obj_GetX(obj)-GetX)<=baseangle-15)
	{
		angle2=baseangle+rand(0,20);
	}
	if(count>0)
	{
		laser(Obj_GetX(obj)+(length-2)*cos(angle),Obj_GetY(obj)+(length-2)*sin(angle),color,angle2,length,count-1,baseangle);
	}
	wait(60);
	ascent(let i in 0..5)
	{
		lasershot(x+d*i*cos(angle),y+d*i*sin(angle),245,5);
	}
	ObjLaser_SetWidth(obj, 24);
        Obj_SetCollisionToPlayer(obj, true);
	wait(30);
	ascent(let i in 0..5)
	{
		lasershot(x+d*i*cos(angle),y+d*i*sin(angle),5,2);
	}
        Obj_Delete(obj);
}

task lasershot(let x,let y,let graphic,let delay)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, 0);
	ObjShot_SetGraphic(obj, graphic);
	Obj_SetAlpha(obj, 0);
	ObjShot_SetDelay(obj, delay);
        Obj_SetCollisionToPlayer(obj, false);
	wait(1);
	Obj_Delete(obj);
}

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