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

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

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

    @Finalize {
        DeleteGraphic(imgBoss);
    }

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


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

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

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


task shot
{
let dir=rand_int(0,1)*2-1;
loop
{
let angle=rand(0,360);
let angleplus=0;
loop(25)
{
	ascent(let i in 0..6)
	{
		CreateShot01(GetX,GetY,1.5,angle+i*60,27,10);
	}
wait(4);
}
loop(130)
{
	ascent(let i in 0..6)
	{
		CreateShot01(GetX,GetY,1.5,angle+i*60,27,10);
	}
angle+=angleplus;
angleplus+=0.5*dir;
wait(4);
}
wait(120);
dir=dir*-1;	
}
}


task roundshot(let x, let y, let speed,let angle, let graphic, let delay,let dir)
{
	let dispeed=speed;
	let anglespeed=1.5;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	Obj_SetAutoDelete(obj,false);
	let r=0;
	wait(20);
	loop(60)
	{
		Obj_SetPosition(obj, x+r*cos(angle), y+r*sin(angle));
		r+=speed;
		speed-=dispeed/60;
		yield;
	}
	speed=1;
	wait(30);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj, x+r*cos(angle), y+r*sin(angle));
		r+=speed;
		speed+=0.005;
		angle+=anglespeed*dir;
		anglespeed-=0.005;
		yield;
		if(Obj_GetY(obj)>GetClipMaxY+32)
		{
			Obj_Delete(obj);
		}
    	}
}

task roundshot2(let x, let y, let speed,let angle, let graphic, let delay,let dir)
{
	let dispeed=speed;
	let anglespeed=1.5;
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	Obj_SetAutoDelete(obj,false);
	let r=0;
wait(20);
	loop(60)
	{
		Obj_SetPosition(obj, x+r*cos(angle), y+r*sin(angle));
		r+=speed;
		speed-=dispeed/60;
		yield;
	}
	speed=1.2;
	wait(30);
	while(!Obj_BeDeleted(obj))
	{
		Obj_SetPosition(obj, x+r*cos(angle), y+r*sin(angle));
		r+=speed;
		speed+=0.015;
		angle+=anglespeed*dir;
		anglespeed-=0.005;
		yield;
		if(Obj_GetY(obj)>GetClipMaxY+32)
		{
			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_Yuka.txt"
}
