#e
#Title[Oʏ4-Lunatic]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "Oʏ4-Lunatic";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_wriggle.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
    // ʒu
    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 {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
        yield;
    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

    // C^XN
task TMain 
{
	standBy;
	wait(180);
	//spell;
	Trate;
	TMove;
	shot;
}

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




sub standBy//ʒu
{
	SetAction(ACT_MOVE, 60);
	let wIni = 60;
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

sub spell//[V
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(50);
        SetScore(22000000/3);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task TMove// gƈړ
{
	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.8,180,248,243,YELLOW05,1);
wait(120);
starshot(GetX,GetY,2.8,0,248,244,GREEN05,-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..20)
	{
	shotL(x,y,speed-i*0.1,angle-i*15*dir,grf1,grf2,grf3);
	wait(3);
	}
}

    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);
	//CreateLaser01(Obj_GetX(obj),Obj_GetY(obj),4,angle+i*45,200,6,grf3,0);
			CreateShotFromScript( "laser1",Obj_GetX(obj),Obj_GetY(obj),4,angle+i*45,0, 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 Shotlaser(let x,let y,let angle,let grf3)
{
	loop(16)
	{
		CreateShot01(x,y,4,angle,grf3,0);
		wait(3);
	}
}

task laser(let x,let y,let angle,let grf3)
{
	let speed=4;
	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_SetGraphic(obj,grf3);
	ObjShot_SetDelay(obj, 0);
	loop(45)
	{
      		ObjLaser_SetLength(obj, length);
		length+=3;
		yield;

	}
	loop(15)
	{
      		ObjLaser_SetLength(obj, length);
		length+=4;
		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"
}
#include_script ".\..\txt/EnemyShotData.txt"