script_enemy_main {
	let time = -100;
	let phase = 1;
	let rate = 10;
	let kaku = 40;
	let score = 5000;
	let layer = 1;
	let bairitu = 1;
	let lv = 0;
	let angle = GetAngle();
	let rank = GetSpeed();
	let arg = GetArgument();
	let ex = GetCommonData("ex");
	SetCommonData("bossx",GetX);
	SetCommonData("bossy",GetY);
	SetCommonData("bossphase",1);
	let imgEnemy = GetCurrentScriptDirectory~"img\st3semiboss.png";
	let tama = GetCurrentScriptDirectory~"tama.txt";
	let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
	let se7 = GetCurrentScriptDirectory~"wav\se7.wav";
	let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
	let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
	SetCommonData("haya",0);
	@Initialize(){
		SetLife( 3000 );
		SetInvincibility( 100 );
		LoadGraphic( imgEnemy );
		LoadUserShotData( tama );
		SetX(GetCommonData("bossx")-GetCommonData("bgx"));
		SetY(GetCommonData("bgy")-GetCommonData("bossy"));
		Tgazou(1,1,320,320);
		Tmove;Tshot1;Tshot2;
	}
	@MainLoop {
		SetCommonData("bossy",GetCommonData("bossy")+1);
		if(time==-99){
			CreateEnemyFromScript( "parts1", +72, 60, 2, 0, 1);
			CreateEnemyFromScript( "parts1", -72, 60, 2, 0, 1);
			CreateEnemyFromScript( "parts2", +73, -97, 2, 0, 1);
			CreateEnemyFromScript( "parts2", -73, -97, 2, 0, -1);
		}
		if(phase==1&&GetLife<=100){
			phase-=1;
			score = 40000;
			SetCommonData("bossphase",0);
			if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 600);}
			Tdeath(20,64,2,0);
			Tbaku;Toti;
		}
		if(phase>=1&&time>=0){
			SetCollisionA(GetX(), GetY()-70, 40);
			SetCollisionA(GetX(), GetY(), 40);
		}
		SetX(GetCommonData("bossx")-GetCommonData("bgx"));
		SetY(GetCommonData("bgy")-GetCommonData("bossy"));
		if(GetCommonData("kakusei")>0){lv=1}
		else{lv=0}
		time++;
		yield;
	}
	@Finalize() {
		SetCommonData("haya",1);
	}
	@DrawLoop {
	}
	task Tmain{
	}
	task Tshot1{
	    wait(400);
	    let a=0;
	    while(time<650){
	       loop(6){
	          if(phase<=0){return;}
	          let b=0;
	          loop(12){
	             let c=(b*15+a*11.3)%180;
	             CreateShotFromScript( "shot1",GetX()+cos(c)*50, GetY()+sin(c)*50, 2.5+ex, c, 0, 13);
	             b++;
	          }
	          PlaySE(seshot1);
	          wait(4);
	       }
	       wait((35-lv*17)/(1+ex));
	       a++;
	    }
	}
	task Tshot2{
	    wait(750);
	    let a=1;
	    loop{
	       if(phase<=0||GetY>480){return;}
	       let b=0;
	       loop(18){
	          CreateShotFromScript( "shota", GetX(), GetY()-60, 2.2+ex, b*20+a*7.3, 0, a);
	          b++;
	       }
	       PlaySE(seshot2);
	       wait((60-lv*35)/(1+ex));
	       a*=-1;
	    }
	}


   task Tmove{
      loop(400){SetCommonData("bossy",GetCommonData("bossy")-2.0);yield;}
      let a=0;
      loop(9){
      loop(100){SetCommonData("bossy",GetCommonData("bossy")-2.1);yield;}
      loop(100){SetCommonData("bossy",GetCommonData("bossy")-1.9);yield;}
      }
      VanishEnemy();
   }
   task Toti{
   	loop(120){
      	yield;
   	}
      Explosion01(GetX,GetY,5,0.4,50);
      PlaySE(se7);
      VanishEnemy();
   }
   task Tgazou(x1,y1,x2,y2)
   {
      let system = GetCurrentScriptDirectory~"img\system.png";
      let objenemy = Obj_Create(OBJ_EFFECT);//エフェクトオブジェクトを作成
      ObjEffect_SetTexture(objenemy, imgEnemy);//なんらかのテクスチャを設定
      ObjEffect_SetPrimitiveType(objenemy, PRIMITIVE_TRIANGLESTRIP);//プリミティブタイプを設定
      ObjEffect_CreateVertex(objenemy, 4);//頂点を4個つくる
      ObjEffect_SetLayer(objenemy,layer);
		
      //四角形状に各頂点の座標を設定
      ObjEffect_SetVertexXY(objenemy, 0, -(x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
      ObjEffect_SetVertexXY(objenemy, 1, -(x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
      ObjEffect_SetVertexXY(objenemy, 2,  (x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
      ObjEffect_SetVertexXY(objenemy, 3,  (x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
		
      //四角形状に各頂点のUV値を設定。(0,0)-(10,10)の部分。
      ObjEffect_SetVertexUV(objenemy, 0, x1, y1);
      ObjEffect_SetVertexUV(objenemy, 1, x1, y2);
      ObjEffect_SetVertexUV(objenemy, 2, x2, y1);
      ObjEffect_SetVertexUV(objenemy, 3, x2, y2);

      Obj_SetPosition(objenemy, GetX, GetY);
   
		
      loop{
         ObjEffect_SetVertexXY(objenemy, 0, -(x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
         ObjEffect_SetVertexXY(objenemy, 1, -(x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
         ObjEffect_SetVertexXY(objenemy, 2,  (x2-x1)*bairitu/2, -(y2-y1)*bairitu/2);
         ObjEffect_SetVertexXY(objenemy, 3,  (x2-x1)*bairitu/2,  (y2-y1)*bairitu/2);
         Obj_SetX(objenemy,GetX);
         Obj_SetY(objenemy,GetY);
         yield;
      }
      Obj_Delete(objenemy);
   }



    #include_function".\efanction.txt"
}
script_enemy parts1 {
    let time = -100;
    let phase = 1;
    let rate = 6;
    let kaku = 10;
    let score = 180;
    let lv = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\st3semiboss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se8 = GetCurrentScriptDirectory~"wav\se8.wav";
    @Initialize(){
        SetLife( 300 );
        SetInvincibility( 10 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(GetCommonData("bossx")-GetCommonData("bgx")+mapx);
        SetY(GetCommonData("bgy")-GetCommonData("bossy")+mapy);
        Tshot;
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           score = 2500;
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 30);}
           PlaySE(se8);
           Tdeath(6,24,2,1);
        }
        if(phase==1&&GetCommonData("bossphase")==0){
           phase-=1;
           score=0;
           PlaySE(se8);
           Tdeath(4,24,2,1);
        }
        if(GetX<12||GetX>436||GetY<40){
           SetInvincibility( 5 );
        }
        if(time>2200){VanishEnemy;}
        if(phase>=1&&time>0){SetCollisionA(GetX, GetY, 24);}
        SetX(GetCommonData("bossx")-GetCommonData("bgx")+mapx);
        SetY(GetCommonData("bgy")-GetCommonData("bossy")+mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 320, 48, 384, 112 );
        SetGraphicAngle(0,0,genteikaku(GetAngleToPlayer(),48));
	DrawGraphic( GetX(), GetY() );
    }

    task Tshot{
        yield;
        wait(100);
        loop{
           if(GetY>32&&GetY<416){
              let p=genteikaku(GetAngleToPlayer(),48);
              let a=0;
              loop(7){
                 if(phase<=0){return;}
                 CreateShotFromScript( "shot1",GetX()+cos(p+9)*22, GetY()+sin(p+9)*22, 3+ex, p, 0, 14);
                 CreateShotFromScript( "shot1",GetX()+cos(p+9)*22, GetY()+sin(p+9)*22, 3+ex, p+10, 0, 14);
                 CreateShotFromScript( "shot1",GetX()+cos(p-9)*22, GetY()+sin(p-9)*22, 3+ex, p, 0, 14);
                 CreateShotFromScript( "shot1",GetX()+cos(p-9)*22, GetY()+sin(p-9)*22, 3+ex, p-10, 0, 14);
                 wait(4);
                 a++;
              }
           }
           wait((40-lv*20)/(1+ex));
        }
    }


    #include_function".\efanction.txt"
}
script_enemy parts2 {
    let time = -100;
    let phase = 1;
    let rate = 6;
    let kaku = 10;
    let score = 180;
    let lv = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\st3semiboss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se8 = GetCurrentScriptDirectory~"wav\se8.wav";
    @Initialize(){
        SetLife( 300 );
        SetInvincibility( 10 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        SetX(GetCommonData("bossx")-GetCommonData("bgx")+mapx);
        SetY(GetCommonData("bgy")-GetCommonData("bossy")+mapy);
        Tshot;
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           score = 2500;
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY, 30);}
           PlaySE(se8);
           Tdeath(6,24,2,1);
        }
        if(phase==1&&GetCommonData("bossphase")==0){
           phase-=1;
           score=0;
           PlaySE(se8);
           Tdeath(6,24,2,1);
        }
        if(GetX<12||GetX>436||GetY<40){
           SetInvincibility( 5 );
        }
        if(time>2200){VanishEnemy;}
        if(phase>=1&&time>0){SetCollisionA(GetX, GetY, 24);}
        SetX(GetCommonData("bossx")-GetCommonData("bgx")+mapx);
        SetY(GetCommonData("bgy")-GetCommonData("bossy")+mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
	SetTexture( imgEnemy );
        SetGraphicRect( 320, 0, 384, 48 );
	DrawGraphic( GetX(), GetY() );
    }

    task Tshot{
        yield;
        wait(100);
        let a=0;
        loop{
           if(GetX>32&&GetX<416){
              let b=0;
              loop(2+ex*1){
                 if(phase<=0){return;}
                 CreateShotFromScript( "shot1",GetX(), GetY(), 2.5+ex, a*13.7*arg+b*(180-60*ex), 0, 05);
                 CreateShotFromScript( "shot1",GetX(), GetY(), 2.5+ex+0.5, (a*13.7+5.1)*arg+b*(180-60*ex), 0, 05);
                 b++;
              }
           }
           wait(5-lv*2);
           a++;
        }
    }


    #include_function".\efanction.txt"
}

script_shot shota{//弾を撃つ弾直進
   let out=false;
   let gr=01;
   let arg=GetArgument;
   let pl=GetAngleToPlayer;
   let ex = GetCommonData("ex");
   let lv=0;
   let time=0;
   @Initialize{
      SetDefault(gr+lv*20);
   }
   @MainLoop {
      if(GetX<20||GetX>428||GetY<20||GetY>460){
         out=true;
         End;
      }
      if(GetCommonData("kakusei")>0){
         lv=1;
         if(GetPoint==0){lv=2;SetSpeed(GetSpeed+0.04)}
      }
      else{lv=0}
      SetDefault(gr+lv*20);
      if((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2<=4){SetCommonData("gekitui",1);}
   	
      if(time%4==0){//３中ボス
         CreateShotFromScript( "shot1",GetX(), GetY(), 2.6+ex*1.2, GetAngle-16*arg, 0, 12);
      }
   	SetAngle(GetAngle()+arg*0.1);
      time++;
   }
   @DrawLoop {
      DrawGraphicDefault();
   }
   @Finalize{
      if(out==false&&OnBomb==false){
         if(GetCommonData("kakusei")>0){
            CreateShotFromScript( "kinka",GetX(), GetY(), 0, 270, 0, 0);
         }
         if(OnBomb==false&&GetCommonData("kakusei")==0){
            CreateShotFromScript( "isi",GetX(), GetY(), 0, 270, 0, 0);
         }
      }
   }
}    
#include_script".\escript.txt"