#搶曽抏枊晽
#Title[嵾晞乽巌柦懜偺挔曤-Hard乿]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "嵾晞乽巌柦懜偺挔曤-Hard乿";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_eiki.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st6bg1.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 bgy=0;
    @Initialize {

       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(89);

        SetLife(800);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

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


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

	DrawSpellHistory;
    }

    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(89);
	loop(30)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
	loop(10)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,0,1280,960+bgy);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);
		bgy+=3;
	}
    // 儊僀儞僞僗僋
task TMain 
{
	standBy;
	spell;
	Trate;
	move;
	Shot;
	SubShot;
//	SubShot2;
}

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

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


sub standBy//弶婜埵抲傊
{
	SetAction(ACT_MOVE, wIni);
	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
{
	wait(60);
loop
{
	CreateShot01(GetX,GetY,0.5,GetAngleToPlayer,171,5);
	CreateShot01(GetX,GetY,0.5,GetAngleToPlayer+30,171,5);
	CreateShot01(GetX,GetY,0.5,GetAngleToPlayer-30,171,5);
	CreateShot01(GetX,GetY,0.5,GetAngleToPlayer+60,171,5);
	CreateShot01(GetX,GetY,0.5,GetAngleToPlayer-60,171,5);
	wait(120);
}
}

task SubShot
{
let w=160;
loop
{
	XShot(90);
	wait(w);
	YShot(0);
	wait(w);
	XShot(270);
	wait(w);
	YShot(180);
	wait(w);
}
}

task XShot(dir)
{
let dx=rand(-30,30);
let y;
if(dir==90)
{
	y=GetClipMinY;
}
else
{
	y=GetClipMaxY;
}
	loop(20)
	{
		ascent(let i in -3..18)
		{
			CreateShotA(0,24*i+dx,y,30);
			SetShotDataA(0,0,0,0,12,0,0,164);
			SetShotDataA(0,30,3,dir,0,0,0,164);
			FireShot(0);
		}
		wait(10);
	}
}

task YShot(dir)
{
let x;
let dy=rand(-30,30);
if(dir==0)
{
	x=GetClipMinX;
}
else
{
	x=GetClipMaxX;
}
	loop(20)
	{
		ascent(let i in -1..25)
		{
			CreateShotA(0,x,24*i+dy,30);
			SetShotDataA(0,0,0,0,12,0,0,164);
			SetShotDataA(0,30,3,dir,0,0,0,164);
			FireShot(0);
		}
		wait(10);
	}
}

task SubShot2
{
	loop
	{
		loop(5)
		{
			SetShotDirectionType(PLAYER);
			CreateShot01(rand(GetClipMinX,GetClipMaxX),GetClipMinY,3,0,46,20);
			SetShotDirectionType(ABSOLUTE);
		}
		wait(60);
	}
}

task snake2(let dir)
{
	let angle=90-90*dir;
	let distance=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	let distance1=distance+15;
	let distance2=distance-15;

	let objl= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objl,GetX,GetY);
	ObjLaser_SetWidth(objl,8);
	ObjLaser_SetLength(objl,distance);
	ObjLaser_SetSource(objl,false);
        ObjShot_SetGraphic(objl,WHITE01);
	Obj_SetAngle(objl, angle);
	ObjShot_SetDelay(objl,0);
	Obj_SetCollisionToPlayer(objl,false);
	Obj_SetAlpha(objl,100);

	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, 156);
	ObjShot_SetDelay(obj, 0);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	Obj_SetPosition(obj, GetX+distance*cos(angle), GetY+distance*sin(angle));
	Obj_SetAlpha(obj,0);

	let objs= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objs,GetX+distance1*cos(angle), GetY+distance1*sin(angle));
	ObjLaser_SetWidth(objs,40);
	ObjLaser_SetLength(objs,240);
	ObjLaser_SetSource(objs,false);
        ObjShot_SetGraphic(objs,PURPLE01);   
	Obj_SetAngle(objs, angle+90*dir);
	ObjShot_SetDelay(objs,0);
	Obj_SetAutoDelete(objs,false);

	let objs2= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objs2,GetX+distance2*cos(angle), GetY+distance2*sin(angle));
	ObjLaser_SetWidth(objs2,40);
	ObjLaser_SetLength(objs2,240);
	ObjLaser_SetSource(objs2,false);
        ObjShot_SetGraphic(objs2,PURPLE01);   
	Obj_SetAngle(objs2, angle+90*dir);
	ObjShot_SetDelay(objs2,0);
	Obj_SetAutoDelete(objs2,false);

	let objs3= Obj_Create(OBJ_LASER);
	Obj_SetPosition(objs3,GetX+distance*cos(angle), GetY+distance*sin(angle));
	ObjLaser_SetWidth(objs3,40);
	ObjLaser_SetLength(objs3,240);
	ObjLaser_SetSource(objs3,false);
        ObjShot_SetGraphic(objs3,PURPLE01);   
	Obj_SetAngle(objs3, angle+90*dir);
	ObjShot_SetDelay(objs3,0);
	Obj_SetAutoDelete(objs3,false);

	EffectOrbit(distance);

	wait(30);
	loop(30)
	{
		Obj_SetPosition(obj, GetX+distance*cos(angle), GetY+distance*sin(angle));
		CreateShadow(obj);
		angle+=6*dir;
		Obj_SetPosition(objs,GetX+distance1*cos(angle), GetY+distance1*sin(angle));
		Obj_SetAngle(objs, angle+90*dir);
		Obj_SetPosition(objs2,GetX+distance2*cos(angle), GetY+distance2*sin(angle));
		Obj_SetAngle(objs2, angle+90*dir);
		Obj_SetPosition(objs3,GetX+distance*cos(angle), GetY+distance*sin(angle));
		Obj_SetAngle(objs3, angle+90*dir);
		Obj_SetAngle(objl, angle);
		yield;
	}
	Obj_Delete(obj);
	Obj_Delete(objl);
	Obj_Delete(objs);
	Obj_Delete(objs2);
	Obj_Delete(objs3);
}

task EffectOrbit(let distance)
{
ascent(i in 0..180)
{
	Orbit(GetX+distance*cos(i*1),GetY+distance*sin(i*1));
}
}

task Orbit(let x,let y)
{
	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, PURPLE03);
	ObjShot_SetDelay(obj, 3);
	Obj_SetAutoDelete(obj,false);
	ObjShot_SetBombResist(obj,true);
	Obj_SetPosition(obj, x, y);
	Obj_SetAlpha(obj,0);
	loop(30)
	{
		ObjShot_SetDelay(obj, 3);
		yield;
	}
	Obj_Delete(obj);
}

task CreateShadow(let obj)
{
		CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),60);
		SetShotDataA(0,0,0,0,0,0,0,PURPLE03);
		SetShotKillTime(0,0);
		FireShot(0);
}



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 ".\..\txt\Spelldata.txt"
#include_function ".\..\lib/lib_anime_Eiki.txt"
}
