script_enemy_main {

let starsize=15;
let color=0;

let xpos=0;
let flarepos=rand(0,360);
let newx=0;

let rise=0;
let effect1=0;

let character="Youko";
let cutin=character;
let spellcards=12;
let spellcardnumber=46;
let dispelled=0;
let damagerate=10;
let outfit=5;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=-180;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotm8=("script\SoundEffects\shotm8.wav");
let SEshotb7=("script\SoundEffects\shotb7.wav");

let BG1=("\script\Images\BackgroundLayers\Youko3.png");
let BG2=("\script\Images\BackgroundLayers\Youko2.png");
let GRboss=("\script\Images\CharacterSprites\Youko.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsYouko1.txt");
	
	LoadSE("script\SoundEffects\shotm8.wav");
	LoadSE("script\SoundEffects\shotb7.wav");

	LoadGraphic("\script\Images\BackgroundLayers\Youko3.png");
	LoadGraphic("\script\Images\BackgroundLayers\Youko2.png");
	LoadGraphic("\script\Images\CharacterSprites\Youko.png");

	SetScore(750000);
	SetLife(600);
	SetTimer(60);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+60,50);
	
	SetX(GetCommonData("Boss1X"));
	SetY(GetCommonData("Boss1Y"));
	SetCommonData("Boss1Vanish",1);
}
	
@MainLoop {

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(255,255,255,255);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=2.5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Prominence [Solar Flare]",spellcardnumber); 
HealthBar();
Portrait(cutin,2);

if(time%100==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,cy-100),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,cy-100),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,cy-100),1.5);
	}
}


if(time%20==0 && time>=90){
let shotx=0;
let speed=6;
let angle=rand(-25,25);
	loop(starsize){
	CreateShotA(shotx,GetX,GetY,0);
	SetShotDataA_XY(shotx,0,speed*cos(angle),rand(-1.5,-2),-(speed/50)*cos(angle),rand(0.02,0.035),(speed/20)*cos(angle),rand(3,4),73+color);
	FireShot(shotx);
	speed-=12/(starsize-1);
	}
color--;
if(color<0){ color=9; }
PlaySE(SEshotb7);
}
if(time%180==0 && time>=60){ starsize++; }


if(time==0){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,cx,maxy); ObjEffect_SetLayer(effect1,3);
	ObjEffect_SetScale(effect1,1.5,1.5);
	ObjEffect_SetTexture(effect1,BG2); ObjEffect_SetRenderState(effect1,ADD);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-256,-256); ObjEffect_SetVertexUV(effect1,0,0,1);
	ObjEffect_SetVertexXY(effect1,1,256,-256); ObjEffect_SetVertexUV(effect1,1,512,1);
	ObjEffect_SetVertexXY(effect1,2,-256,256); ObjEffect_SetVertexUV(effect1,2,0,511);
	ObjEffect_SetVertexXY(effect1,3,256,256); ObjEffect_SetVertexUV(effect1,3,512,511);
	ObjEffect_SetVertexColor(effect1,0,100,255,255,230); ObjEffect_SetVertexColor(effect1,1,100,255,255,230);
	ObjEffect_SetVertexColor(effect1,2,100,255,255,230); ObjEffect_SetVertexColor(effect1,3,100,255,255,230);
}

if(time==60){
SetCommonData("WarningX",cx);
SetCommonData("WarningSide",3);
SetCommonData("WarningTime",90);
SetCommonData("WarningSize",1);
SetCommonData("WarningType",1);
CreateEnemyFromFile("script\Functions\warnings.txt",0,0,0,0,0);
}

if(time>=120){ Obj_SetPosition(effect1,cx,maxy-rise); }


if(time%20==0 && time>=240){
let shot1=0;
let angle=rand(-180,-170);
	loop(90){
	CreateShotA(shot1,cx+200*cos(angle),maxy-rise+40+10*sin(angle),0);
	SetShotDataA(shot1,0,0,0,0,0,0,59);
	SetShotKillTime(shot1,20);
	FireShot(shot1);
	angle+=4;
	}
}
if(time%20==0 && time>=240){
let shot1=0;
let angle=rand(-180,-170);
	loop(90){
	CreateShotA(shot1,cx+200*cos(angle),maxy-rise+100+10*sin(angle),0);
	SetShotDataA(shot1,0,0,0,0,0,0,59);
	SetShotKillTime(shot1,20);
	FireShot(shot1);
	angle+=4;
	}
}


if((time+60)%300==0){
newx=270+70*cos(flarepos);
SetCommonData("WarningX",cx+170*cos(newx));
SetCommonData("WarningY",maxy-rise-40);
SetCommonData("WarningSide",3);
SetCommonData("WarningTime",60);
SetCommonData("WarningSize",0.75);
SetCommonData("WarningType",2);
CreateEnemyFromFile("script\Functions\warnings.txt",cx+170*cos(newx),maxy-rise-40,0,0,1);
}
if(time%300==0){ xpos=newx; flarepos+=rand(180,240); }

if(time%20==0 && time>=300){
let shot1=0;
let shot2=1;
let angle1=xpos+rand(-5,5);
let angle=0;
if(xpos>=270){ angle=270+rand(-30,-50); }
if(xpos<270){ angle=270+rand(30,50); }
let a=0;
	CreateShotA(shot1,cx+200*cos(angle1),maxy-rise+50+10*sin(angle1),0);
	SetShotDataA_XY(shot1,0,0+2*cos(angle),-1.5+2*sin(angle),0,0.02,0,4,38);
	SetShotKillTime(shot1,300);
		loop(300){
		CreateShotA(shot2,0,0,0);
		SetShotDataA(shot2,0,0.2,rand(0,360),0,0,0,rand_int(37,39));
		SetShotKillTime(shot2,50);
		AddShot(a,shot1,shot2,0);
		a+=1;
		}
	FireShot(shot1);
}

if(rise<120 && time>=240){ rise+=0.1; }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<255){bgfade+=5;}

	SetGraphicRect(0,0,3000,3000);
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,128,0);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,time/70);
	DrawGraphic(cx,maxy+1000);
	
	SetGraphicRect(0,0,300,300);
	SetGraphicScale(2,2);
	SetTexture(BG2);
	SetAlpha(bgfade);
	SetColor(255,128,0);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,maxy+400);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,5);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}