script_enemy_main {
    let time = -180;
    let phase = 1;
    let rate = 20;
    let kaku = 40;
    let lv = 0;
    let score = 0;
    let layer = 2;
    let bairitu = 1;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\st2semiboss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
    let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
    let se7 = GetCurrentScriptDirectory~"wav\se7.wav";
    let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
    let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
    SetCommonData("haya",0);
    @Initialize(){
        SetLife( 1900 );
        SetInvincibility( 180 );
        LoadGraphic( imgEnemy );
        LoadUserShotData( tama );
        Tshot1b;Tshot2a;
        Tmove;Tgazou(1,1,256,256);
    }
    @MainLoop {
        if(phase==2&&GetLife<=1500){
           phase-=1;
           score = 25000;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
           Tdeath(20,64,1,0);
           PlaySE(se2);
           Tshot2a;
        }
        if(phase==1&&GetLife<=100){
           phase-=1;
           score = 35000;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
           Tdeath(20,64,2,0);
           Tbaku;Toti;
           SetCommonData("haya",1);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>2000){VanishEnemy;}
        if(phase>=1){
           SetCollisionA(GetX(), GetY()+60, 40);
           SetCollisionA(GetX(), GetY()-20, 40);
           SetCollisionA(GetX()+80, GetY(), 30);
           SetCollisionA(GetX()-80, GetY(), 30);
           SetCollisionB(GetX(), GetY()+60, 40);
           SetCollisionB(GetX(), GetY()-20, 40);
           SetCollisionB(GetX()+80, GetY(), 30);
           SetCollisionB(GetX()-80, GetY(), 30);
        }
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}

        time++;
        yield;
    }
    @Finalize() {
       SetCommonData("haya",1);
    }
    @DrawLoop {
    }

    task Tshot1a{
        wait(180);
        loop{
           let a=0;
           loop(4){
              if(phase<=1){return;}
              let p1=atan2( GetPlayerY()-(GetY()-25+a*4), GetPlayerX()-(GetX()+40+a*20));
              let p2=atan2( GetPlayerY()-(GetY()-25+a*4), GetPlayerX()-(GetX()-40-a*20));
              let b=-2-ex;
              loop(5+ex*2){
                 let c=0;
                 loop(3){
                    CreateShotFromScript( "shot1",GetX()+40+a*20, GetY()-25+a*4, 3+c*0.2, p1+b*(22-ex*8), 0, 06);
                    CreateShotFromScript( "shot1",GetX()-40-a*20, GetY()-25+a*4, 3+c*0.2, p2+b*(22-ex*8), 0, 06);
                    c++;
                 }
                 b++;
              }
              a++;
              PlaySE(seshot2);
              wait(6);
           }
           wait(70-lv*50);
        }
    }
    task Tshot1b{
        yield;
        wait(180);
        let b=0;
        loop{
              let p1=atan2( GetPlayerY()-(GetY()+2), GetPlayerX()-(GetX()+65));
              p1=genteikaku(p1,32);
              let p2=atan2( GetPlayerY()-(GetY()+2), GetPlayerX()-(GetX()-65));
              p2=genteikaku(p2,32);
              SetShotDirectionType(ABSOLUTE);
              let a=0;
              loop(8){
                 if(phase==0){return;}
                 let b=-1-ex;
                 loop(3+ex*2){
                    CreateShotFromScript( "shot1",GetX()+65+b*3.5, GetY()+2, 3.5, p1-b*2, 0, 12);
                    CreateShotFromScript( "shot1",GetX()-65+b*3.5, GetY()+2, 3.5, p2-b*2, 0, 12);
                    b++;
                 }
                 a++;
                 PlaySE(seshot1);
                 wait(3);
              }
           wait(35-lv*25);
           b++;
        }
    }
    task Tshot2a{
        wait(220);
        loop{
           let a=6+ex*2;
           let p=atan2( GetPlayerY()-(GetY()+20), GetPlayerX()-GetX());
           loop(6){
              if(phase<=0){return;}
              let b=-ex/2;
              loop(1+ex){
                 CreateShotFromScript( "shot5",GetX(), GetY()+20, 1.8+a*0.2, p+b*10, 0, 09);
                 b++;
              }
              a--;
           }
           PlaySE(seshot2);
           wait(70-lv*45);
        }
    }
    task Tmove {
        SetMovePosition02(224+60, 140, 180);
        wait(180);
        let a=0;
    	
        SetMovePosition02(224-60, 180, 280);
        wait(280);
        if(phase<=0){return;}
       
        SetMovePosition02(224+60, 180, 280);
        wait(280);
        if(phase<=0){return;}
        
        SetMovePosition02(224-60, 180, 280);
        wait(280);
        if(phase<=0){return;}
    	
        SetMovePosition02(224-350, 140, 120);
        phase=0;
        wait(120);
        VanishEnemy();
    }
   task Toti{
      layer=1;
      SetMovePosition02(224+(GetX-224)/2, GetY+100, 80);
      let a=0;
      loop(80){
        if(a%10==0){PlaySE(se3);}
        bairitu=1-a/80*0.3;
        a++;
        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"
}

#include_script".\escript.txt"