script_enemy_main {
    let time = 0;
    let phase = 1;
    let rate = 1;
    let kaku = 10;
    let score = 120;
    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\zakotank1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se8 = GetCurrentScriptDirectory~"wav\se8.wav";
    if(ex==1){rank=4;}
    @Initialize(){
		SetLife( 110 );
		SetInvincibility( 10 );
		LoadGraphic( imgEnemy );
		LoadUserShotData( tama );
		SetX(mapx-GetCommonData("bgx"));
		SetY(GetCommonData("bgy")-mapy);
		if(arg==0){
			if( (|angle|) ==106){Tmove106;}
			if( (|angle|) ==107){Tmove107;}
			if( (|angle|) ==202){Tmove202;}
			if( (|angle|) ==203){Tmove203;}
			if( (|angle|) ==503){Tmove503;}
			if( (|angle|) ==504){Tmove504;}
			if( (|angle|) ==508){Tmove508;}
		}
		else{setmove(angle,arg);}
		Tshot;
		Tgazou2(1,1,48,48);
		Tgazou3(48,1,96,48,24);
   	layer = 0;
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY+10, 30);}
           PlaySE(se8);
           Tdeath(2,24,2,1);
        }
        if(GetX<12||GetX>436||GetY<16){
           SetInvincibility( 5 );
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1500){VanishEnemy;}
        if(phase>=1){SetCollisionA(GetX, GetY, 24);}
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
    }

    task Tshot{
        yield;
        wait(60+sin(GetCommonData("ransu")*73)*20-rank*15);
        SetCommonData("ransu",GetCommonData("ransu")+1);
        loop{
           if(phase<=0){return;}
           if(GetX>32&&GetX<416&&GetY>16&&GetY<(250+rank*25)&&(GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2>150^2){
              let p=genteikaku(GetAngleToPlayer(),24);
              SetShotDirectionType(ABSOLUTE);
              CreateShotFromScript( "shot1",GetX()+cos(p)*20, GetY()+sin(p)*20, 2.5, p, 0, 14);
              if(ex==1){
                 CreateShotFromScript( "shot1",GetX()+cos(p)*20, GetY()+sin(p)*20, 3.0, p, 0, 14);
                 CreateShotFromScript( "shot1",GetX()+cos(p)*20, GetY()+sin(p)*20, 3.5, p, 0, 14);
              }
           }
           if(lv==0){wait(32-rank*7);}
           wait(4);
        }
    }
    task Tmove106{
        angle=-32;
        setmove(-32,300);
        wait(300);
        angle=0;
        setmove(0,600);
        wait(600);
        VanishEnemy;
    }
    task Tmove107{
        angle=90;
        setmove(90,220);
        wait(220);
        angle=148;
        setmove(148,400);
        wait(400);
        VanishEnemy;
    }
    task Tmove202{
        angle=-53;
        setmove(-53,480);
        wait(480);
        angle=250;
        setmove(250,50);
        wait(50);
        angle=198;
        setmove(198,250);
        wait(250);
        VanishEnemy;
    }
    task Tmove203{
        angle=198;
        setmove(198,200);
        wait(200);
        angle=160;
        setmove(160,50);
        wait(50);
        angle=127;
        setmove(127,530);
        wait(530);
        VanishEnemy;
    }
	task Tmove503{
		let r=angle/503;
		angle = 90;
		setmove(angle,65);
		wait(65);
		angle = 90+45*r;
		setmove(angle,40);
		wait(40);
		angle = 90+90*r;
		setmove(angle,400);
		wait(400);
		VanishEnemy;
	}
	task Tmove504{
		let r=angle/504;
		angle = 90;
		setmove(angle,115);
		wait(115);
		angle = 90+45*r;
		setmove(angle,40);
		wait(40);
		angle = 90+90*r;
		setmove(angle,450);
		wait(450);
		VanishEnemy;
	}
	task Tmove508{
		angle = 90;
		setmove(angle,380);
		wait(380);
		angle = 45;
		setmove(angle,40);
		wait(40);
		angle = 0;
		setmove(angle,1000);
		wait(1000);
		VanishEnemy;
	}

   task setmove(a,t) {
      loop(t) {
         mapx+=cos(a)*0.8;mapy-=sin(a)*0.8;
         yield;
      }
   }



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

#include_script".\escript.txt"