#東方弾幕風
#Title[「ベルゼブブの威光-Hard」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "「ベルゼブブの威光-Hard」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_wriggle.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;
	let Bonus;
	let DBonusItem;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","Normal"))
	case("Easy")
	{
		DBonusItem=1;
	}
	case("Normal")
	{
		DBonusItem=2;
	}
	case("Hard")
	{
		DBonusItem=3;
	}
	case("Lunatic")
	{
		DBonusItem=4;
	}
	let StandardSpellBonus=GetCommonDataDefault("BONUSPOINT",10000)*(20*DBonusItem+20*GetCommonDataDefault("STAGEPROGRESS",2));
	let SpellTimer=50;
	let SpellBonus=StandardSpellBonus/3;
    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(41);
        SetLife(1500);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

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

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(41);
	loop(20)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }

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

task Trate
{
	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.4,180,1);
laser(GetX,GetY,0,0,180,2);
laser(GetX,GetY,0,-0.4,180,3);
laser(GetX,GetY,0,-0.8,180,4);
laser(GetX,GetY,0,-1.2,180,4);

laser(GetX,GetY,180,0.4,180,3);
laser(GetX,GetY,180,0,180,2);
laser(GetX,GetY,180,-0.4,180,1);
laser(GetX,GetY,180,0.8,180,4);
laser(GetX,GetY,180,1.2,180,4);
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..8)
		{
		CreateShot01(shotx,shoty,1.5,shotangle+i*45,163,20);
		}
		wait(30);
	}
	}

	if(num==2)
	{
	while(!Obj_BeDeleted(obj))
	{
	let shotangle=atan2(GetPlayerY-shoty,GetPlayerX-shotx);
		loop(8)
		{
		ascent(let i in -2..3)
		{
		CreateShot01(shotx,shoty,2.5,shotangle+i*20,162,20);
		}
		wait(4);
		}
		wait(45);
	}
	}

	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);
		CreateLaserA(0,shotx,shoty,600,10,153,60);		
		SetLaserDataA(0,0,shotangle+3,0,0,0,0);
		SetShotKillTime(0,120);
		FireShot(0);
		CreateLaserA(0,shotx,shoty,600,10,153,60);		
		SetLaserDataA(0,0,shotangle-3,0,0,0,0);
		SetShotKillTime(0,120);
		FireShot(0);
		wait(240);
	}
	}

	if(num==4)
	{
	while(!Obj_BeDeleted(obj))
	{
		let shotangle=rand(70,110);
		CreateShot01(shotx,shoty,1.5,shotangle,163,20);
		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"
}
