script_enemy_main{

let shooton=0;
let cannonmove=0;

let effect1=0;
let object1=[];
let cannonscale=0;
let cannonangle1=-80;
let cannonangle2=260;
let cannonangle3=-80;
let cannonangle4=260;

let shot1=0;
let bullet1=[];
let bounce1=[];

let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0;
let time=0;
let move=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEcannon=("script\SoundEffects\mechanic1long.wav");
let SEshot1=("script\SoundEffects\shotb2.wav");

let GReffect1=("\script\Images\OtherEffects\Cannon.png");
let GRboss=("\script\Images\CharacterSprites\Shinichi.png");

@Initialize{
	LoadGraphic("\script\Images\CharacterSprites\Shinichi.png");
	LoadGraphic("\script\Images\OtherEffects\Cannon.png");

	LoadSE("script\SoundEffects\mechanic1long.wav");
	LoadSE("script\SoundEffects\shotb2.wav");

	SetColor(128,128,128);
	Concentration01(90);
	SetColor(255,255,255);
	SetLife(10000);
	MagicCircle(false);
	SetInvincibility(120);
	SetX(GetCommonData("Boss2X"));
	SetY(GetCommonData("Boss2Y"));
	SetMovePosition02(cx,miny+90,60);
}
	
@MainLoop{

SetCollisionB(GetX,GetY,16);


if(time%1==0 && shooton==1){

let shot1=0;
CreateShotA(shot1,GetX+110*cos(cannonangle1+10*sin(cannonmove)),GetY+110*sin(cannonangle1+10*sin(cannonmove)),20);
SetShotDataA(shot1,0,0,0,0,0,0,42);
SetShotKillTime(shot1,0);
FireShot(shot1);

CreateShotA(shot1,GetX+110*cos(cannonangle2+10*sin(cannonmove)),GetY+110*sin(cannonangle2+10*sin(cannonmove)),20);
SetShotDataA(shot1,0,0,0,0,0,0,42);
SetShotKillTime(shot1,0);
FireShot(shot1);

	shot1=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shot1,GetX+100*cos(cannonangle1+10*sin(cannonmove)),GetY+100*sin(cannonangle1+10*sin(cannonmove)));
	Obj_SetAngle(shot1,cannonangle1+10*sin(cannonmove));
	ObjLaser_SetWidth(shot1,15); 	ObjLaser_SetLength(shot1,50);
	ObjLaser_SetSource(shot1,false);
	ObjShot_SetGraphic(shot1,66);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_LASER));
	Obj_SetPosition(shot1,GetX+100*cos(cannonangle2+10*sin(cannonmove)),GetY+100*sin(cannonangle2+10*sin(cannonmove)));
	Obj_SetAngle(shot1,cannonangle2+10*sin(cannonmove));
	ObjLaser_SetWidth(shot1,15); 	ObjLaser_SetLength(shot1,50);
	ObjLaser_SetSource(shot1,false);
	ObjShot_SetGraphic(shot1,66);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;
}
if(time%6==0 && shooton==1){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+60*cos(cannonangle3-15*sin(cannonmove)),GetY+60*sin(cannonangle3-15*sin(cannonmove)));
	Obj_SetAngle(shot1,cannonangle3-15*sin(cannonmove));
	Obj_SetSpeed(shot1,8);
	ObjShot_SetGraphic(shot1,48);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;

	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX+60*cos(cannonangle4-15*sin(cannonmove)),GetY+60*sin(cannonangle4-15*sin(cannonmove)));
	Obj_SetAngle(shot1,cannonangle4-15*sin(cannonmove));
	Obj_SetSpeed(shot1,8);
	ObjShot_SetGraphic(shot1,48);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;
PlaySE(SEshot1);
}

if(time>=60 && shooton==1){
let i=0;
	while(i<length(bullet1)){
		if(Obj_BeDeleted(bullet1[i])){
		bullet1=erase(bullet1,i); bounce1=erase(bounce1,i);
		i--;
		}
		else{
	if(Obj_GetY(bullet1[i])>GetY && bounce1[i]<1){
	Obj_SetPosition(bullet1[i],Obj_GetX(bullet1[i])+6*cos(Obj_GetAngle(bullet1[i])),Obj_GetY(bullet1[i])+6*sin(Obj_GetAngle(bullet1[i])));
	}
	if(Obj_GetY(bullet1[i])>GetY && bounce1[i]>=1){
	Obj_SetPosition(bullet1[i],Obj_GetX(bullet1[i])+6*cos(Obj_GetAngle(bullet1[i])),Obj_GetY(bullet1[i])+6*sin(Obj_GetAngle(bullet1[i])));
	}
			if(bounce1[i]<2){
			let obj=bullet1[i];
				if(Obj_GetX(obj)<=minx && Obj_GetY(obj)>GetY){
				Obj_SetAngle(obj,180-Obj_GetAngle(obj));
				bounce1[i]=bounce1[i]+2;
				}
				if(Obj_GetX(obj)>=maxx && Obj_GetY(obj)>GetY){
				Obj_SetAngle(obj,180-Obj_GetAngle(obj));
				bounce1[i]=bounce1[i]+2;
				}

				if(Obj_GetX(obj)<=minx && Obj_GetY(obj)<GetY){
				Obj_SetAngle(obj,180-Obj_GetAngle(obj));
				bounce1[i]=bounce1[i]+1;
				}
				if(Obj_GetX(obj)>=maxx && Obj_GetY(obj)<GetY){
				Obj_SetAngle(obj,180-Obj_GetAngle(obj));
				bounce1[i]=bounce1[i]+1;
				}
				if(Obj_GetY(obj)<=miny){
				CreateShot12(Obj_GetX(obj),Obj_GetY(obj),rand(1,0.1),0,-0.0045,0.02,0,2.5,49,0);
				CreateShot12(Obj_GetX(obj),Obj_GetY(obj),rand(-1,-0.1),0,0.0045,0.02,0,2.5,49,0);
				Obj_Delete(obj);
				}
			}
		}
	i++;
	}
}


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

if(time>=60){
	if(time>=90){
	if(cannonangle1<55){ cannonangle1+=2; }
	if(cannonangle2>125){ cannonangle2-=2; }
	if(cannonangle3<-30){ cannonangle3+=1; }
	if(cannonangle4>210){ cannonangle4-=1; }
	}
	Obj_SetPosition(object1[0],GetX,GetY);
	Obj_SetPosition(object1[1],GetX,GetY);
	Obj_SetPosition(object1[2],GetX,GetY);
	Obj_SetPosition(object1[3],GetX,GetY);

	Obj_SetAngle(object1[0],cannonangle1+10*sin(cannonmove)); ObjEffect_SetAngle(object1[0],0,0,cannonangle1+10*sin(cannonmove));
	Obj_SetAngle(object1[1],cannonangle2+10*sin(cannonmove)); ObjEffect_SetAngle(object1[1],0,0,cannonangle2+10*sin(cannonmove));
	Obj_SetAngle(object1[2],cannonangle3-15*sin(cannonmove)); ObjEffect_SetAngle(object1[2],0,0,cannonangle3-15*sin(cannonmove));
	Obj_SetAngle(object1[3],cannonangle4-15*sin(cannonmove)); ObjEffect_SetAngle(object1[3],0,0,cannonangle4-15*sin(cannonmove));

	ObjEffect_SetScale(object1[0],cannonscale,1); ObjEffect_SetScale(object1[1],cannonscale,1);
	ObjEffect_SetScale(object1[2],cannonscale/2,0.8); ObjEffect_SetScale(object1[3],cannonscale/2,0.8);
	if(cannonscale<1){ cannonscale+=0.02; }
}

if(shooton==1){ cannonmove++; }

if(time==180){ shooton=1; }


time++;
frame++;

if(GetCommonData("UseSpell2")!=0){ usespell=GetCommonData("UseSpell2"); SetCommonData("UseSpell2",0); }
if(usespell>0){ usespell-=1; }
if(usespell<0){ usespell+=1; }

SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",GetY);
}

@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{
	CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,"Shinichi");
}

}