#TouhouDanmakufu
#Title["Sad Story 'Memory of a Rival'"]
#Text[akyuspell1]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Hard]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\system\Effectsmore.txt";
#include_function ".\cutin.txt";
#include_function ".\drawall.txt";
#include_function ".\hitbox.txt";
#include_function ".\maple.txt" 
#include_function".\SnowFunc.txt";
let ImgBoss = GetCurrentScriptDirectory~"img\Akyu_Main.png";
let imgExRumiaBack=GetCurrentScriptDirectory~"img\ExRumiaBack.png";
let CSD = GetCurrentScriptDirectory;
let ci = CSD ~ "system\NMM.png";
let bg1 = CSD ~ "system\bg8.png";
let bg2 = CSD ~ "system\bg3.png";
let cx=GetCenterX();
let frame = 0;
let framedelay = 0;
let angle = 0;
let angle2 = 0;
let draw = false;
let anglemove = 20;
let anglestart = 0;
let x;
let switch = 1;
let switch2 = 1;
let gx;
let gy;
let Cut = GetCurrentScriptDirectory~"img\daiyousei11.png";
let ThisShot = GetCurrentScriptDirectory~"ZUN's shotdata.txt";

@Initialize
{
CreateHitbox;
SetLife(1000);
SetDamageRate(50,50);
SetTimer(40);
mainTask;

SetInvincibility(180);
SetMovePosition03(GetCenterX, GetCenterY-90, 10, 4);
LoadGraphic(ImgBoss);
LoadUserShotData(ThisShot);
LoadGraphic(Cut);
LoadGraphic(ci);
LoadGraphic(bg1);
LoadGraphic(bg2);
SetTexture(ImgBoss);
SetGraphicRect(0, 0, 64, 64);
MagicCircle(true);
Aura;

}

//---------------------------------------------------------------

@MainLoop 
{

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);


frame++;

// Start Attack

yield;

// End Attack


// Start Boss Move


// End Boss Move



}

//---------------------------------------------------------------

@DrawLoop
{
SetTexture(ImgBoss);
SetRenderState(ALPHA);
SetAlpha(255);
SetGraphicAngle(0, 0, 0);
SetGraphicScale(1.1, 1.1);
drawbossa;
DrawHitbox;

drawcirclea;


}
//---------------------------------------------------------------

@BackGround
{
	drawbga;
}	

//---------------------------------------------------------------

@Finalize
{
DeleteGraphic(ImgBoss);
        PlaySE(CSD~"sound\enemoff.wav");
        if(GotSpellCardBonus){
	PlaySE(CSD~"sound\GotBonus.wav");
	}
		loop(35){
		CreateItem(ITEM_SCORE,GetX()+rand(-100,100),GetY()+rand(-100,100));
		}
}

// main task
task mainTask{
	wait(90);
	PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
	draw = true;
	SetScore(500000);
	cutin("NAZRIN", "Sad Story 'Memory of a Rival'", Cut, 0, 0, 325, 488);
	LocateEnemy;
	StartMapleConcentrate;
	PlayDelaySE(CSD~"sound\charge2.wav",0);
	wait(60);
	fire2;
	yield;
}

task fire{
	PlaySE(CSD~"sound\fam.wav");
	ascent(i in 0..3){
	CreateEnemyFromScript("starFam",GetX,GetY,0,0,i);
	}
	wait(90);
	}

task fire2{
	ascent(n in 0..4000){
	PlayDelaySE(CSD~"sound\shot1.wav",0);
	ascent(i in 0..12){
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,0.5,360*sin(n*9)+i*30,0,0.045,6,228);
	FireShot(0);
	}
	wait(4);
	}
	}

task PlayDelaySE(se,delay){
        loop(delay){yield;}
        PlaySE(se);
}
	function wait(w){
		loop(w){yield;}
			}
}

script_enemy starFam{
	
	let ThisShot = GetCurrentScriptDirectory~"system\supershot.txt";
	let CSD = GetCurrentScriptDirectory;
	let imgFam = CSD ~ "system\Famy.png";
	let s = 0;
	let switch = 1;
	let anglefam = 0;
	let r = 120;
	let famangle = GetArgument;
	let spin = 0;
@Initialize{
	LoadUserShotData(ThisShot);
	SetLife(1000);
	LoadGraphic(imgFam);
	maintask;
}

@MainLoop{

//SetCollisionA(GetX, GetY, 24);
SetCollisionB(GetX, GetY, 18);
yield;


}
	
@DrawLoop{
	SetTexture(imgFam);
	SetRenderState(ADD);
	if(s<=1){s+= 0.05;}	
	SetGraphicScale(s,s);
	SetGraphicAngle(0,0,spin);
	SetGraphicRect(0,0,48,48);
	DrawGraphic(GetX,GetY);
	spin -= 2;

}

@Finalize{

}

task maintask{
	movement;
	wait(90);
	fire;
	yield;
	}

task fire{
	ascent(n in 0..800){
	PlaySE(CSD~"sound\shot1.wav");
	ascent(i in 0..3){
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,0.5,360*sin(n*7)+i*120,0,0.03,1.5,145);
	FireShot(0);
	}
	wait(4);
	}
	}

task movement{
	loop{
	SetMovePosition03(GetEnemyX+120*cos(anglefam+famangle*120),GetEnemyY+120*sin(anglefam+famangle*120),20,10);
	anglefam++;
	yield;
	}
	}

task tailbullet(x, y, v, dir, graphic, delay,check) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let c = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
	 ObjShot_SetBombResist(obj, true);
		 while(! Obj_BeDeleted(obj)) 
		{
		ObjShot_FadeDelete(obj);
		 yield;
		}
	}

	function wait(w){
		loop(w){yield;}
			}

}