script_enemy_main{

let size2=3;

let shot1=0;
let bullet1=[];
let timer1=[];
let shoottime=0;
let xpos=0;
let ypos=0;

let effect3=0;
let object3=[];
let cannonscale=0;
let cannonangle1=90;
let cannonangle2=90;
let shootradius=0;

let size=0;
let effect1=0;
let angle1=0;

let effect2=0;
let scale2=2;
let fade2=0;
let angle2=rand(0,360);
let blink=0;

let inrange=false;
let fadeout=false;
let shoot=false;

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

let SEfocus=("script\SoundEffects\charge1.wav");
let SEcannon=("script\SoundEffects\mechanic1normal.wav");
let SEshotb1=("script\SoundEffects\shotb1.wav");
let SEshotb4=("script\SoundEffects\shotb4.wav");
let SEwarning2=("script\SoundEffects\warning2.wav");
let SEbomb2=("script\SoundEffects\bomb2.wav");

let GRcannon=("\script\Images\OtherEffects\Cannon.png");
let GRcrosshair=("\script\Images\OtherEffects\Crosshair.png");
let GRsearchlight=("\script\Images\OtherEffects\WhiteBlur.png");

let BG1=("\script\Images\BackgroundLayers\Shinichi1.png");
let GRboss=("\script\Images\CharacterSprites\Shinichi.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\ShotsShinichi1.txt");

	LoadSE("script\SoundEffects\charge1.wav");
	LoadSE("script\SoundEffects\shotb1.wav");
	LoadSE("script\SoundEffects\shotb4.wav");
	LoadSE("script\SoundEffects\mechanic1normal.wav");
	LoadSE("script\SoundEffects\warning2.wav");
	LoadSE("script\SoundEffects\bomb2.wav");

	LoadGraphic("\script\Images\OtherEffects\Cannon.png");
	LoadGraphic("\script\Images\OtherEffects\Crosshair.png");
	LoadGraphic("\script\Images\OtherEffects\WhiteBlur.png");

	LoadGraphic("\script\Images\BackgroundLayers\Shinichi1.png");
	LoadGraphic("\script\Images\CharacterSprites\Shinichi.png");

	SetScore(2500000);
	SetLife(400);
	SetTimer(70);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+140,50);

	SetDurableSpellCard;
}
	
@MainLoop{

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

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=0; }
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("Blitz [Lock On And Terminate The Target]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time%150==0 && time>=60){
let angle=rand(0,360);
let shotx=0;
	loop(30){
	let speed=3;
		loop(size2){
		CreateShotA(shotx,GetX-12,GetY-30,0);
		SetShotDataA(shotx,0,3,angle,2.5,0,0,84);
		SetShotDataA(shotx,40,3,NULL,0,-0.1,speed,84);
		FireShot(shotx);
		CreateShotA(shotx,GetX-12,GetY-30,0);
		SetShotDataA(shotx,0,3,angle,-2.5,0,0,84);
		SetShotDataA(shotx,40,3,NULL,0,-0.1,speed,84);
		FireShot(shotx);
		speed-=0.2;
		}
	angle+=360/30;
	}
	loop(30){
	let speed=3;
		loop(size2){
		CreateShotA(shotx,GetX-12,GetY-30,0);
		SetShotDataA(shotx,0,3,angle,5,0,0,84);
		SetShotDataA(shotx,40,3,NULL,0,-0.1,speed,84);
		FireShot(shotx);
		CreateShotA(shotx,GetX-12,GetY-30,0);
		SetShotDataA(shotx,0,3,angle,-5,0,0,84);
		SetShotDataA(shotx,40,3,NULL,0,-0.1,speed,84);
		FireShot(shotx);
		speed-=0.2;
		}
	angle+=360/30;
	}
PlaySE(SEshotb1);
usespell=30;
}
if(size<1.75){ size+=0.00025; }

if(time==700 || GetLife<420 && size2==3){ SetColor(120,120,120); Concentration01(90); SetColor(255,255,255); PlaySE(SEfocus); size2++; }
if(time==1400 || GetLife<340 && size2==4){ SetColor(120,120,120); Concentration01(90); SetColor(255,255,255); PlaySE(SEfocus); size2++; }
if(time==2100 || GetLife<260 && size2==5){ SetColor(120,120,120); Concentration01(90); SetColor(255,255,255); PlaySE(SEfocus); size2++; }
if(time==2800 || GetLife<180 && size2==6){ SetColor(120,120,120); Concentration01(90); SetColor(255,255,255); PlaySE(SEfocus); size2++; }
if(time==3500 || GetLife<100 && size2==7){ SetColor(120,120,120); Concentration01(90); SetColor(255,255,255); PlaySE(SEfocus); size2++; }


if(time==40){
	loop(2){
	effect3=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect3,GetX,GetY-10); ObjEffect_SetScale(effect3,1,1);
	Obj_SetAngle(effect3,0); ObjEffect_SetAngle(effect3,0,0,0);
	ObjEffect_SetLayer(effect3,1); ObjEffect_SetTexture(effect3,GRcannon); ObjEffect_SetRenderState(effect3,ALPHA);
	ObjEffect_SetPrimitiveType(effect3,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect3,4);
	ObjEffect_SetVertexXY(effect3,0,-120,-15); ObjEffect_SetVertexUV(effect3,0,0,0);
	ObjEffect_SetVertexXY(effect3,1,120,-15); ObjEffect_SetVertexUV(effect3,1,240,0);
	ObjEffect_SetVertexXY(effect3,2,-120,15); ObjEffect_SetVertexUV(effect3,2,0,30);
	ObjEffect_SetVertexXY(effect3,3,120,15); ObjEffect_SetVertexUV(effect3,3,240,30);
	ObjEffect_SetVertexColor(effect3,0,255,255,255,255); ObjEffect_SetVertexColor(effect3,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect3,2,255,255,255,255); ObjEffect_SetVertexColor(effect3,3,255,255,255,255);
	object3=object3~[effect3];
	}
PlaySE(SEcannon);
}

if(time>=40){
if(cannonangle1>-50){ cannonangle1-=2; }
if(cannonangle2<230){ cannonangle2+=2; }
	Obj_SetPosition(object3[0],GetX+shootradius*cos(cannonangle1),(GetY-10)+shootradius*sin(cannonangle1));
	Obj_SetPosition(object3[1],GetX+shootradius*cos(cannonangle2),(GetY-10)+shootradius*sin(cannonangle2));

	Obj_SetAngle(object3[0],cannonangle1); ObjEffect_SetAngle(object3[0],0,0,cannonangle1);
	Obj_SetAngle(object3[1],cannonangle2); ObjEffect_SetAngle(object3[1],0,0,cannonangle2);

	ObjEffect_SetScale(object3[0],cannonscale,1); ObjEffect_SetScale(object3[1],cannonscale,1);
	if(cannonscale<1){ cannonscale+=0.02; }
	if(shootradius<0){ shootradius+=0.5; }
}


if(time==90){
let xsize=200;
let ysize=200;
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY);
	ObjEffect_SetScale(effect1,1.5,1.5);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,GRsearchlight); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect1,1,xsize,0);
	ObjEffect_SetVertexXY(effect1,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect1,2,0,ysize);
	ObjEffect_SetVertexXY(effect1,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect1,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect1,0,200,255,255,255); ObjEffect_SetVertexColor(effect1,1,200,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,200,255,255,255); ObjEffect_SetVertexColor(effect1,3,200,255,255,255);
}
if(time>=90 && size<1){ size+=0.03; }

if(time==90){
let xsize=300;
let ysize=300;
	effect2=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect2,GetPlayerX,GetPlayerY);
	ObjEffect_SetScale(effect2,1,1);
	ObjEffect_SetLayer(effect2,7); ObjEffect_SetTexture(effect2,GRcrosshair); ObjEffect_SetRenderState(effect2,ALPHA);
	ObjEffect_SetPrimitiveType(effect2,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect2,4);
	ObjEffect_SetVertexXY(effect2,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(effect2,0,0,0);
	ObjEffect_SetVertexXY(effect2,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(effect2,1,xsize,0);
	ObjEffect_SetVertexXY(effect2,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(effect2,2,0,ysize);
	ObjEffect_SetVertexXY(effect2,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(effect2,3,xsize,ysize);
	ObjEffect_SetVertexColor(effect2,0,255,255,255,255); ObjEffect_SetVertexColor(effect2,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect2,2,255,255,255,255); ObjEffect_SetVertexColor(effect2,3,255,255,255,255);
}

angle1=atan2(GetPlayerY-Obj_GetY(effect1),GetPlayerX-Obj_GetX(effect1));
Obj_SetAngle(effect1,angle1);
if(fadeout==false && inrange==false){ Obj_SetSpeed(effect1,1.5); }
if((((GetPlayerX-Obj_GetX(effect1))^2+(GetPlayerY-Obj_GetY(effect1))^2)^0.5)<10 || shoottime>0){ Obj_SetSpeed(effect1,0); }

if((((GetPlayerX-Obj_GetX(effect1))^2+(GetPlayerY-Obj_GetY(effect1))^2)^0.5)<50*size && fadeout==false || shoot==true){ inrange=true; }
else{ inrange=false; fadeout=true; }

if(inrange==true){ if(scale2>1){ scale2-=1/40; } if(fade2<255){ fade2+=255/40; angle2+=3; } }
else{ if(fade2>0){ fade2-=255/20; } fadeout=true; }

if(fade2<=0){ fadeout=false; scale2=2; }

if(fade2>0 && inrange==true && shoot==false){ Obj_SetPosition(effect2,GetPlayerX,GetPlayerY); }
	ObjEffect_SetScale(effect1,size,size);
	ObjEffect_SetScale(effect2,scale2/1.5,scale2/1.5);
	ObjEffect_SetAngle(effect2,0,0,angle2);
	ObjEffect_SetVertexColor(effect2,0,fade2,255,blink,0); ObjEffect_SetVertexColor(effect2,1,fade2,255,blink,0);
	ObjEffect_SetVertexColor(effect2,2,fade2,255,blink,0); ObjEffect_SetVertexColor(effect2,3,fade2,255,blink,0);

if(fade2==255 && inrange==true && shoot==false){ shoot=true; }



if(shoot==true && shoottime==0){
xpos=GetPlayerX;
ypos=GetPlayerY;
	loop(7){
	CreateShot01(GetX+120*cos(cannonangle1-5),GetY+120*sin(cannonangle1-5),8,cannonangle1+rand(-15,15),68,0);
	CreateShot01(GetX+120*cos(cannonangle2+5),GetY+120*sin(cannonangle2+5),8,cannonangle2+rand(-15,15),68,0);
	}
let speed=8;
	loop(30){
	let angle=0+rand(-80,-20);
	CreateShot12(GetX+110*cos(cannonangle1-5),GetY+110*sin(cannonangle1-5),speed*cos(angle),rand(1,-2),-0.03*cos(angle),0.05,0.2*cos(angle),rand(3,4),rand_int(85,86),10);
	speed-=6/30;
	}
let speed=8;
	loop(30){
	let angle=180+rand(80,20);
	CreateShot12(GetX+110*cos(cannonangle2+5),GetY+110*sin(cannonangle2+5),speed*cos(angle),rand(1,-2),-0.03*cos(angle),0.05,0.2*cos(angle),rand(3,4),rand_int(85,86),10);
	speed-=6/30;
	}
shootradius=-10;
PlaySE(SEshotb4);
shoottime++;
}


if(shoottime==60){
	loop(14){
	let radius=rand(400,600);
	let angle=270+rand(-60,60);
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,xpos+radius*cos(angle),ypos+radius*sin(angle));
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,8);
	ObjShot_SetGraphic(shot1,68);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	}
}
if((shoottime+20)%30==0 && shoottime>=10 && shoottime<120){ PlaySE(SEwarning2); blink=255; }
if(blink>0){ blink-=255/20; }
if(shoottime==120){ fadeout=true; shoot=false; shoottime=0; }


let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); timer1=erase(timer1,i); i--; }
	else{
		Obj_SetAngle(bullet1[i],atan2(ypos-Obj_GetY(bullet1[i]),xpos-Obj_GetX(bullet1[i])));
		if((((xpos-Obj_GetX(bullet1[i]))^2+(ypos-Obj_GetY(bullet1[i]))^2)^0.5)<rand_int(60,15)){
		let shotx=0;
			loop(50){
			CreateShotA(shotx,Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),0);
			SetShotDataA(shotx,0,rand(2,5),rand(0,360),0,-0.1,0,rand_int(37,38));
			SetShotKillTime(shotx,rand_int(20,50));
			FireShot(shotx);
			}
		PlaySE(SEbomb2);
		Obj_Delete(bullet1[i]);
		}
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(shoottime>=1){ shoottime++; }


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<200){bgfade+=5;}

	SetGraphicRect(0-(time*2),0-(time*2),900-(time*2),600-(time*2));
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@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{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",16); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}