//TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spellcard 1"]
#Text[""]
#System[".\system\Default_System.txt"]

#include"script/default_system/Default_ShotConst.txt"
#include"./Functions.txt"
#include"./BGTask.txt"
#include"./Animation_lib.txt"
let Enemy = ID_INVALID;
let EnemyX = 0;
let EnemyY = 0;
let yuyuX = 0;
let yuyuY = 0;
let yuyuko = 0;
//those Min and Max x y are taken from Shadow's Raimoo, Edited for full screen by Me(i am too honest :))
//if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}  my god "function"
let MinX = 0;
let MaxX = 640;
let MinY = 0;
let MaxY = GetStgFrameHeight*1.8;
@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){SetScriptResult(2500);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
case(EV_REQUEST_SPELL_SCORE){SetScriptResult(90000);}
}

@Initialize{
	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
yuyuko = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(yuyuko);
SetShotAutoDeleteClip(50,50,50,50);
SetAutoDeleteObject(true);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
ObjEnemy_SetDamageRate(Enemy,40,10);
name("Remilia Scarlet",0,30);
name("Yuyuko Saigyouki",0,40);
CutinSpell("Scarlet Butterfly\"Bloody Scarlet Butterflies\"",0,12);
InitializeAction(Enemy,GetCurrentScriptDirectory ~"img/dot_remilia.png");
DrawBoss_Task(Enemy);
spawnYuyuko;
SpellBGoverlay;
SpellBG1;
SpellBG2;
	ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 100, 20,4);
	BossActions;
}

@MainLoop{
	yield;
}

task BossActions{
	ShootBullets;
//Texto;
	while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 0){
		EnemyX = ObjMove_GetX(Enemy);
		EnemyY = ObjMove_GetY(Enemy);
		ObjEnemy_SetIntersectionCircleToShot(Enemy, EnemyX, EnemyY, 40);
		ObjEnemy_SetIntersectionCircleToPlayer(Enemy, EnemyX, EnemyY, 30);
		yield;
	}
DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(Enemy);
	//loop(60){yield;}
	CloseScript(GetOwnScriptID);
}
function wait(t){loop(t){yield;}}

task ShootBullets{
let angul = 0;
let angul2 = 0;
wait(60);
loop{
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
let s= GravityShot(EnemyX,EnemyY,3,-90+sin(angul)*60,0.1,90,DS_RICE_S_RED,10);
ObjRender_SetColor(s,255,0,0);
let s2= GravityShot(EnemyX,EnemyY,3,-90-sin(angul)*60,0.1,90,DS_RICE_S_RED,10);
ObjRender_SetColor(s2,255,0,0);
angul += 6;
wait(8);
  }
}
function angleToPlayer{
let angle=atan2(GetPlayerY-EnemyY,GetPlayerX-EnemyX);
return angle;
}
task spawnYuyuko{
ObjEnemy_SetLife(yuyuko,2500);
ObjRender_SetPosition(yuyuko,GetCommonData("FX",0),GetCommonData("FY",0),0);
InitializeAction(yuyuko,GetCurrentScriptDirectory ~"img/dot_yuyuko.png");
DrawBoss_Task(yuyuko);
SetAction(yuyuko,YACT_STAND,999999999999999999999);
ObjMove_SetDestAtWeight(yuyuko,GetStgFrameWidth/2,150, 20,4);
yuyukoShot;
while(!Obj_IsDeleted(Enemy) && ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 0 && ObjEnemy_GetInfo(yuyuko, INFO_LIFE) > 0){
yuyuX = ObjMove_GetX(yuyuko);
yuyuY = ObjMove_GetY(yuyuko);
ObjEnemy_SetIntersectionCircleToShot(Enemy, yuyuX, yuyuY, 40);
ObjEnemy_SetIntersectionCircleToPlayer(Enemy, yuyuX, yuyuY, 30);
                                  
		yield;
	}
SetCommonData("FX",ObjMove_GetX(yuyuko));
SetCommonData("FY",ObjMove_GetY(yuyuko));
Obj_Delete(yuyuko);
}
task yuyukoShot{
wait(60);
let angleB = 0;
loop{
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
let B1 =CreateShotFA1(GetStgFrameWidth/2+sin(angleB)*200,0,3,90,DS_BUTTERFLY_RED,10,true);
let B2 =CreateShotFA1(GetStgFrameWidth/2-sin(angleB)*200,0,3,90,DS_BUTTERFLY_PURPLE,10,true);
Trail(B1,DS_BALL_S_RED,10,2);
rice(B1,60);
angleB += 18.231;
wait(6);
  }
}

//Japanese function, do not disqualify me 4 dis
function GravityShot(
                     let x,			// x

	let y,			// y
	let speed,		// 速度

	let angle,		// 角度（絶対角度）

	let grvSpeed,	// 重力加速度

	let grvAngle,	// 重力角度（絶対角度）

	let graphic,	// 画像

	let delay		// 遅延フレーム数

){
	let xSpeed = speed * cos( angle );

	let ySpeed = speed * sin( angle );

	let accXSpeed = grvSpeed * cos( grvAngle );

	let accYSpeed = grvSpeed * sin( grvAngle );

	let maxXSpeed = [ 99, - 99 ][ accXSpeed < 0 ];

	let maxYSpeed = [ 99, - 99 ][ accYSpeed < 0 ];

	let gs=CreateShotB2(x,y,xSpeed,ySpeed,accXSpeed,accYSpeed,maxXSpeed,maxYSpeed,graphic,delay);
	return gs;
}


task Trail(obj,color,size,time){
while(!Obj_IsDeleted(obj)){
let tra = CreateShotOA1(obj,0,0,color,size);
ObjShot_SetDeleteFrame(tra,0);
wait(time);
}
}
task rice(obj,frame){
wait(frame);
//GravityShot(ObjMove_GetX(obj),ObjMove_GetY(obj),3,-90+rand(-10,10),0.1,90,DS_RICE_S_RED,10);
}