#東方弾幕風
#Title[映姫通常3-Easy]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "映姫通常3-Easy";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_eiki.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 96;
	let wIni=60;

let arrayObj = [];

    @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,0,255);
	DrawBoss( imgBoss );

    }

    @Finalize {
        DeleteGraphic(imgBoss);
    }

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


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

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

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

task Shot1
{
	sinshot(GetCenterX,GetCenterY-64);
	sinshot(GetCenterX+100,GetCenterY-32);
	sinshot(GetCenterX-100,GetCenterY-32);
}

task sinshot(let x,let y)
{
	let obj = Obj_Create(OBJ_SHOT);   
	Obj_SetPosition(obj, x, y);
	ObjShot_SetGraphic(obj, 255);
	ObjShot_SetDelay(obj, 0);
	ObjShot_SetBombResist(obj,true);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAlpha(obj,100);
	arrayObj = arrayObj ~ [obj];
 	while(!Obj_BeDeleted(obj))
	{
		yield;
	}

}

task Shot2
{
loop
{
	moveshot(GetX,GetY,1.8,0);
	wait(60);
	moveshot(GetX,GetY,1.8,180);
	wait(60);
}
}

task moveshot(let x,let y,let speed,let angle)
{
	let rangle=rand(0,360);
	let obj = Obj_Create(OBJ_SHOT);   
	Obj_SetPosition(obj, x, y);
	ObjShot_SetGraphic(obj, 8);
	ObjShot_SetDelay(obj, 0);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	wait(20);
	while(!Obj_BeDeleted(obj))
	{
		ascent(let i in 0..18)
		{
			minishot(Obj_GetX(obj), Obj_GetY(obj),1.5,rangle+i*20);
		}
		wait(45);
	}	
}

task minishot(let x,let y,let speed,let angle)
{
	let obj = Obj_Create(OBJ_SHOT);   
	Obj_SetPosition(obj, x, y);
	ObjShot_SetGraphic(obj, 8);
	ObjShot_SetDelay(obj, 0);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	while(!Obj_BeDeleted(obj))
	{
		ascent(let i in 0..length(arrayObj))
		{
			if(Collision_Obj_Obj(arrayObj[i], obj))
			{
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), speed*2, angle, 164, 0);
				CreateShot01(Obj_GetX(obj), Obj_GetY(obj), speed, angle, 8, 0);
				Obj_Delete(obj);//触れたら削除
				break;
			}
		}
	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_Eiki.txt"
}
