#e
#Title[uIN^XCT[v]
#Text[]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "uIN^XCT[v";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "lib/patchouli_dot.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
    @Initialize {
	SetShotAutoDeleteClip(100,100,100,100);
        SetLife(1300);
        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);
    }

    // C^XN
task TMain 
{
	yield;
	standBy;
	spell;
	Trate;
	TMove;
	Shot;
}

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




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
	{
		SetY(y + 4 * sin(angle));
		yield;
		angle += 3;
	if(count>=140)
	{
	moveToPlayer(rand(40, 60), rand(-30, 30), 30,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	
	wait(30);
	y=GetY;
	count=0;
	angle = 0;
	}
	count++;
	}
}



task Shot
{
	loop
	{
		let dir=rand_int(0,1)*2-1;
		let dir2=rand_int(0,1)*2-1; 
		shot(GetX,GetY,1.5,GetAngleToPlayer,ORANGE21,30,dir);
		shot(GetX,GetY,1.5,GetAngleToPlayer+90,ORANGE21,30,-dir2);
		shot(GetX,GetY,1.5,GetAngleToPlayer-90,ORANGE21,30,dir2);
		wait(80);
		shot(GetX,GetY,1.5,GetAngleToPlayer+45,YELLOW21,30,-dir);
		shot(GetX,GetY,1.5,GetAngleToPlayer-45,YELLOW21,30,dir);
		wait(80);
	}
}


task shot(let x, let y,let speed,let angle, let graphic,let delay,let dir)//oya
{
	let count=0;
	let count1=0;
	let r=70;
	let w=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	Obj_SetAlpha(obj, 0);
	Obj_SetCollisionToPlayer(obj,false);
	ObjShot_SetBombResist(obj,true);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	loop(5)
	{
		ascent(let i in 0..8)
		{
	shot2(obj,r,w+i*45,i*45,graphic,0,dir);
	shot2(obj,r,-w+i*45,i*45,graphic,0,dir);
		}
		w+=4.5;
		r-=(2*r-r/cos(22.5))/5;	
	}
	while(!Obj_BeDeleted(obj) && graphic!=ORANGE21)
	{
		if(Obj_GetX(obj)<GetClipMinX && count==0)//[ł̋
		{
			Obj_SetX(obj, GetClipMinX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
			count=1;
        	}
		if(Obj_GetX(obj)>GetClipMaxX && count==0)//E[ł̋
		{
			Obj_SetX(obj, GetClipMaxX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
			count=1;
        	}
		if(Obj_GetY(obj)<GetClipMinY && count1==0)//[ł̋
		{
			Obj_SetY(obj, GetClipMinY*2-Obj_GetY(obj));
			Obj_SetAngle(obj,360-Obj_GetAngle(obj));
			count1=1;
        	}
		yield;
    	}

}

task shot2(let parent,let r,let w,let angle,let graphic,let delay,let dir)//ko
{
	let count=0;
	let count1=0;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, Obj_GetX(parent)+r*cos(w), Obj_GetY(parent)+r*sin(w));
	Obj_SetSpeed(obj, 0);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	while(!Obj_BeDeleted(obj))
	{
	Obj_SetPosition(obj, Obj_GetX(parent)+r*cos(w), Obj_GetY(parent)+r*sin(w));
	Obj_SetAngle(obj, angle);
	w+=dir*1.5;
	angle+=dir*1.5;
	if(Obj_BeDeleted(parent))
	{
	Obj_Delete(obj);
	}
	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 ".\data.txt"
#include_function ".\lib/lib_anime_Patchouli.txt"
}
