#東方弾幕風
#Title[「ベルゼブブの威光-Easy」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "「ベルゼブブの威光-Easy」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_wriggle.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st3bg1.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;

	#include_function ".\..\txt\SpellCardBonusDefine.txt"
	let SpellTimer=50;

	let bgx=0;
	let bgy=0;
    @Initialize {
	SetShotAutoDeleteClip(16,64,16,16);
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(39);
        SetLife(1100);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

    @MainLoop {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 128);
        SetCollisionB(GetX, GetY, 16);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;

    }

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

    @Finalize {
        DeleteGraphic(imgBoss);
        DeleteGraphic(imgBG);
	EndSpellHistory(39);
	loop(20)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,bgy,1280+bgx,960);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);	
	bgx+=1;
	bgy-=1;
	}

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

task Trate
{
	while(OnBomb==true){yield;}
	wait(240);
        SetDamageRate(25, 25);
}


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(SpellTimer);
        SetScore(SpellBonus);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task shot
{
loop(1)
{
laser(GetX,GetY,0,0.5,180,1);
laser(GetX,GetY,0,0,180,3);
laser(GetX,GetY,0,-0.5,180,4);

laser(GetX,GetY,180,0.5,180,4);
laser(GetX,GetY,180,0,180,3);
laser(GetX,GetY,180,-0.5,180,1);
wait(120);
}
}

task laser(let x,let y,let angle,let anglemove,let length,let num)
{
	length=0;
        let obj = Obj_Create(OBJ_LASER);
      	ObjLaser_SetSource(obj, false);
        Obj_SetPosition(obj, x, y);
        ObjLaser_SetLength(obj, length);
        ObjLaser_SetWidth(obj, 16);
        Obj_SetAngle(obj,angle);
        ObjShot_SetBombResist(obj, true);
        ObjShot_SetGraphic(obj,RED02);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetDelay(obj, 90);
        Obj_SetCollisionToPlayer(obj, false);
	loop(30)
	{
       		ObjLaser_SetLength(obj, length);
		length+=6;
		yield;
	}
	loop(60)
	{
		Obj_SetAngle(obj,angle);
		angle+=anglemove;
		yield;
    	}
	let shotx=Obj_GetX(obj)+length*cos(angle);
	let shoty=Obj_GetY(obj)+length*sin(angle);
	let shothx=Obj_GetX(obj)+length/2*cos(angle);
	let shothy=Obj_GetY(obj)+length/2*sin(angle);
	damage(shothx,shothy);
	ascent(let i in 0..120)
	{
		shotL(shotx, shoty, 20, i*3);
	}
	wait(30);
      	ObjLaser_SetSource(obj, true);
	if(num==1)
	{
	while(!Obj_BeDeleted(obj))
	{
		let shotangle=rand(0,360);
		ascent(let i in 0..6)
		{
	//	CreateShot01(shotx,shoty,1.5,shotangle+i*60,163,20);
		CreateShotFromScript( "shot1",shotx,shoty, 1.5, shotangle+i*60, 20, 163);
		}
		wait(45);
	}
	}

	if(num==2)
	{
	while(!Obj_BeDeleted(obj))
	{
	let shotangle=atan2(GetPlayerY-shoty,GetPlayerX-shotx);
		loop(5)
		{
		ascent(let i in -1..2)
		{
	//	CreateShot01(shotx,shoty,2.5,shotangle+i*30,162,20);
		CreateShotFromScript( "shot1",shotx,shoty, 2.5, shotangle+i*30, 20, 162);
		}
		wait(3);
		}
		wait(60);
	}
	}

	if(num==3)
	{
	while(!Obj_BeDeleted(obj))
	{
	let shotangle=atan2(GetPlayerY-shoty,GetPlayerX-shotx);
		CreateLaserA(0,shotx,shoty,600,10,153,60);		
		SetLaserDataA(0,0,shotangle,0,0,0,0);
		SetShotKillTime(0,120);
		FireShot(0);
		wait(240);
	}
	}

	if(num==4)
	{
	while(!Obj_BeDeleted(obj))
	{
		let shotangle=rand(60,120);
	//	CreateShot01(shotx,shoty,1.5,shotangle,163,20);
		CreateShotFromScript( "shot1",shotx,shoty, 1.5, shotangle, 20, 163);
		wait(15);
	}
	}
}

task damage(let x,let y)
{
loop
{
      //  SetCollisionA(x, y, 64);
	yield;
}
} 
task shotL(let x, let y, let speed, let angle) 
{
        let obj = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(obj, RED01);
        Obj_SetAngle(obj, angle);
        Obj_SetSpeed(obj, speed);
        Obj_SetPosition(obj,x, y);
       Obj_SetCollisionToPlayer(obj, false);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
 
        let objE = Obj_Create(OBJ_SHOT);
        ObjShot_SetGraphic(objE, RED01);
        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);
        loop(90)
	{
	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);
    }
#include_function ".\..\txt\data.txt"
#include_function ".\..\txt\Spelldata.txt"
#include_function ".\..\lib/lib_anime_Patchouli.txt"
}
#include_script ".\..\txt/EnemyShotData.txt"