script_enemy_main {
    let time = -700;
    let phase = 1;
    let rate = 20;
    let kaku = 40;
    let lv = 0;
    let score = 0;
    let angle = GetAngle();
    let rank = GetSpeed();
    let arg = GetArgument();
    let ex = GetCommonData("ex");
    let mapx = GetX();
    let mapy = GetY();
    let imgEnemy = GetCurrentScriptDirectory~"img\st1semiboss.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se7 = GetCurrentScriptDirectory~"wav\se7.wav";
    let se3 = GetCurrentScriptDirectory~"wav\se3.wav";
    let seshot1 = GetCurrentScriptDirectory~"wav\shot1.wav";
    let seshot2 = GetCurrentScriptDirectory~"wav\shot2.wav";
    SetCommonData("haya",0);
    @Initialize(){
		SetLife( 2100 );
		SetInvincibility( 160 );
		LoadGraphic( imgEnemy );
		LoadUserShotData( tama );
		SetX(mapx-GetCommonData("bgx"));
		SetY(GetCommonData("bgy")-mapy);
		Tmove;
		Tgazou(1,1,320,320);
		layer = 0;
		bairitu = 0.7;
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           score = 30000;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, 224, 240, 500);}
           Tdeath(14,64,2,0);
           Tbaku;Toti;
           SetCommonData("haya",1);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>2000){VanishEnemy;}
        if(phase>=1&&time>=0){
           SetCollisionA(GetX(), GetY(), 100);
           SetCollisionA(GetX()+100, GetY(), 40);
           SetCollisionA(GetX()-100, GetY(), 40);
           SetCollisionB(GetX, GetY, 55);
           SetCollisionB(GetX+80, GetY, 25);
           SetCollisionB(GetX-80, GetY, 25);
        }
        if(time<-80){
           SetX(mapx-GetCommonData("bgx"));
           SetY(GetCommonData("bgy")-mapy);
        }
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}


        if(time==0){layer=1;}
        if(time>-80&&time<0){bairitu=1+time/80*0.3;}
        time++;
        yield;
    }
    @Finalize() {
       SetCommonData("haya",1);
    }
    @DrawLoop {
    }

    task Tshot1{
        yield;
        loop{
        let p=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()+60));
        let b=0;
        loop(7){
           if(phase<=0){return;}
           SetShotDirectionType(ABSOLUTE);
           let c=-2-ex*2;
           loop(5+ex*4){
           CreateShotFromScript( "shot1",GetX()+60, GetY(), 2.8+b*0.3, genteikaku(p,32)+c*(17-ex*6), 0, 06);
              c++;
           }
           PlaySE(seshot1);
           wait(3);
           b++;
        }
        wait(35-lv*35);
        let p=atan2( GetPlayerY()-(GetY()), GetPlayerX()-(GetX()-60));
        let b=0;
        loop(7){
           if(phase<=0){return;}
           SetShotDirectionType(ABSOLUTE);
           let c=-2-ex*2;
           loop(5+ex*4){
              CreateShotFromScript( "shot1",GetX()-60, GetY(), 2.8+b*0.3, genteikaku(p,32)+c*(17-ex*6), 0, 06);
              c++;
           }
           PlaySE(seshot1);
           wait(3);
           b++;
        }
        wait(35-lv*35);
        let p=atan2( GetPlayerY()-(GetY()+30), GetPlayerX()-(GetX()));
        let b=0;
        loop(14){
           if(phase<=0){return;}
           SetShotDirectionType(ABSOLUTE);
           let c=-2-ex*2;
           loop(5+ex*4){
           CreateShotFromScript( "shot1",GetX(), GetY()+30, 2.8+b*0.3, genteikaku(p,32)+c*(17-ex*6), 0, 06);
              c++;
           }
           PlaySE(seshot1);
           wait(3);
           b++;
        }
        wait(35-lv*35);

        wait(30-lv*20);

        let a=0;
        let b=0;
        let kakudo=0;
        while(a<180){
           if(phase<=0){return;}
           SetShotDirectionType(ABSOLUTE);
           if(b<=3){kakudo=-2+b;}
           if(b>3){kakudo=6-b;}
           let c=0;
           loop(3+ex*2){
              let d=-2;
              loop(5){
                 CreateShotFromScript( "shot1",GetX()+60, GetY()-20, 2.7+c*0.17+ex, 90+kakudo*35+d*22, 0, 13);
                 CreateShotFromScript( "shot1",GetX()-60, GetY()-20, 2.7+c*0.17+ex, 90+kakudo*35+d*22, 0, 13);
                 d++;
              }
              c++;
           }
           PlaySE(seshot2);
           a+=15-lv*7;
           wait(15-lv*7);
           b++;
           b=b%8;
        }
        wait(30-lv*20);

        }
    }
    task Tmove {
		while(time<-80){yield;}
		SetMovePosition02(224, 140, 80);
		wait(80);
		Tshot1;
		loop(12){
			SetMovePosition02(224+rand(40,-40), 140+rand(20,-20), 80);
			wait(80);
			if(phase<=0){return;}
		}
		SetMovePosition02(224, -100, 120);
		phase=0;
		wait(120);
		VanishEnemy();
    }
   task setmove(a,t) {
      loop(t) {
         mapx+=cos(a)*0.8;mapy-=sin(a)*0.8;
         yield;
      }
   }
   task Toti{
      layer=1;
      SetMovePosition02(224, 260, 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();
   }


    #include_function".\efanction.txt"
    #include_function".\effobj.txt"
}

#include_script".\escript.txt"