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

#include"./lib/AllStarShot_Const.dnh"
#include"./lib/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;
let eimg = CSD~"img/magiccircle.png";
@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){SetScriptResult(1300);}
	case(EV_REQUEST_TIMER){SetScriptResult(70);}
case(EV_REQUEST_SPELL_SCORE){SetScriptResult(90000);}
}

@Initialize{
	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
//SetShotAutoDeleteClip(50,50,50,50);
SetAutoDeleteObject(true);
ObjEnemy_SetDamageRate(Enemy,0,0);
DrawTimer03(1);
InitializeAction(Enemy,GetCurrentScriptDirectory ~"img/dot_edorev.png");
DrawBoss_Task(Enemy);
name("Edorev Milton",0,30);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
	
	BossActions;
}

task DrawPig{
ObjPrim_SetTexture(Enemy,GetCurrentScriptDirectory~"img/pig_sheet.png");
ObjSprite2D_SetSourceRect(Enemy,405,0,540,145);
ObjSprite2D_SetDestCenter(Enemy);
}

@MainLoop{
	yield;
}

task BossActions{
ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 140, 20,6);
//SetAction(Enemy,ACT_MOVE_R,100);
//wait(120);
	ShootBullets;
//Texto;
	while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 0){
		EnemyX = ObjMove_GetX(Enemy);
		EnemyY = ObjMove_GetY(Enemy);
		ObjEnemy_SetIntersectionCircleToShot(Enemy, EnemyX, EnemyY, 20);
		ObjEnemy_SetIntersectionCircleToPlayer(Enemy, EnemyX, EnemyY, 20);
		yield;
	}
DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(Enemy);
	//loop(60){yield;}
	CloseScript(GetOwnScriptID);
}
function wait(t){loop(t){yield;}}

task ShootBullets{
//Preparation
MagicCircleEx2(Enemy,false); //Magic Circle, false doesnt contain opening, but loads the last script's pos and angle
LifeCircleBar_A(Enemy,0.5,0.0,false);//Active Lifebar part(enemy,usable part,unusable part(empity),opening)
LifeCircleBar_B(Enemy,0.0,0.0,false);//Inactive LB part
LifeCircleBar_Marker(Enemy,0.5);//Marker
Aura1(Enemy,8,128,128,0);	//Aura(enemy,spawn rate,r,g,b)			
wait(60);
//Spellcard
SE(CSD~"sfx/spell.wav");
Cutin01(3,0,0,CSD ~ "img/endo.png",0,0,700,1200);
Cutin03(2,0,0,"Cielo y Tierra -Rayo Celestial-");
SpellBGoverlay;
SpellBG1;
SpellBG2;
wait(90);
ObjEnemy_SetDamageRate(Enemy,0,0);
//Shots
let angul = 0;
let angul2 = 0;
let time = 180;
let radius = 30;
wait(80);
SpawnEarth;
SpawnSky;
wait(120);
Ray;
loop{
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
angul = getAtanAngle(Enemy,Player);
GravityShot(rand(0,GetStgFrameWidth),0,0,90,0.04,90,DROP_BLUE,1);

wait(5);
  }
}
function angleToPlayer{
let angle=atan2(GetPlayerY-EnemyY,GetPlayerX-EnemyX);
return angle;
}

task SpawnEarth{
SE(CSD~"sfx/tan04.wav");
let b1=CreateShotFA2(EnemyX,EnemyY,5.2,90,-0.05,0,LARGE_ORANGE,60,false);
ObjShot_SetSpellResist(b1,true);
wait(80);
ascent(i in 0..50){
SE(CSD~"sfx/kira00.wav");
 let a=CreateShotFA1(0+i*GetStgFrameWidth/49,GetStgFrameHeight-10,0,0,LARGE_ORANGE,15,true);
 ObjRender_SetColorHSV(a,50,255,100);
 ObjShot_SetSpellResist(a,true);
  let b=CreateShotFA1(0+i*GetStgFrameWidth/49,GetStgFrameHeight-30,0,0,LARGE_ORANGE,15,true);
 ObjRender_SetColorHSV(b,50,255,100);
 ObjShot_SetSpellResist(b,true);
 let c=CreateShotFA1(0+i*GetStgFrameWidth/49,GetStgFrameHeight-50,0,0,LARGE_ORANGE,15,true);
 ObjRender_SetColorHSV(c,50,255,100);
 ObjShot_SetSpellResist(c,true);
 wait(1);
 }
}

task SpawnSky{
SE(CSD~"sfx/tan04.wav");
let b1=CreateShotFA2(EnemyX,EnemyY,5.2,-90,-0.1,0,LARGE_GRAY,60,false);
ObjShot_SetSpellResist(b1,true);
wait(80);
ascent(i in 0..50){
SE(CSD~"sfx/kira00.wav");
 let a=CreateShotFA1(GetStgFrameWidth-i*GetStgFrameWidth/49,0+10,0,0,LARGE_GRAY,15,true);
 //ObjRender_SetColorHSV(a,50,255,100);
 ObjShot_SetSpellResist(a,true);
  let b=CreateShotFA1(GetStgFrameWidth-i*GetStgFrameWidth/49,0+30,0,0,LARGE_GRAY,15,true);
 //ObjRender_SetColorHSV(b,50,255,100);
 ObjShot_SetSpellResist(b,true);
 let c=CreateShotFA1(GetStgFrameWidth-i*GetStgFrameWidth/49,0+50,0,0,LARGE_GRAY,15,true);
 //ObjRender_SetColorHSV(c,50,255,100);
 ObjShot_SetSpellResist(c,true);
 wait(1);
 }

}

function GravityShot(x,y,speed,angle,grvSpeed,grvAngle,graphic,	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 Ray{
loop(5){
SE(CSD~"sfx/Laser.wav");
CreateStraightLaserA1(rand(0,GetStgFrameWidth),0,90,400,60,40,ST_LASER_YELLOW,30); 
 wait(120);
 }
 SE(CSD~"sfx/charge00.wav");
 nTestCharge(EnemyX,EnemyY,90,255,255,0);
 ObjEnemy_SetDamageRate(Enemy,15,5);
 loop(6){
 SE(CSD~"sfx/Laser.wav");
CreateStraightLaserA1(rand(0,GetStgFrameWidth),0,90,400,60,40,ST_LASER_YELLOW,30); 
CreateStraightLaserA1(rand(0,GetStgFrameWidth),0,90,400,60,40,ST_LASER_RED,30); 
 wait(120);
 }
 SE(CSD~"sfx/charge00.wav");
  nTestCharge(EnemyX,EnemyY,90,255,255,0);
  ObjEnemy_SetDamageRate(Enemy,30,5);
  loop{
  SE(CSD~"sfx/Laser.wav");
CreateStraightLaserA1(rand(0,GetStgFrameWidth),0,90,400,90,40,ST_LASER_YELLOW,30);
CreateStraightLaserA1(rand(0,GetStgFrameWidth),0,90,400,90,40,ST_LASER_RED,30);  
 wait(90);
 }
}