script_enemy_main {
	let time = 0;
	let phase = 1;
	let rate = 7;
	let kaku = 40;
	let score = 1600;
	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\tank1.png";
	let tama = GetCurrentScriptDirectory~"tama.txt";
	let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
	let se2 = GetCurrentScriptDirectory~"wav\se2.wav";
	@Initialize(){
		//SetLife( 340 );
		SetLife( 370 - rank*30);
		SetInvincibility( 60 );
		LoadGraphic( imgEnemy );
		LoadUserShotData( tama );
		SetX(mapx-GetCommonData("bgx"));
		SetY(GetCommonData("bgy")-mapy);
		if(arg==0){
			if( (|angle|) ==1){Tmove1;}
			if( (|angle|) ==2){Tmove2;}
			if( (|angle|) ==3){Tmove3;}
		}
		else{setmove(angle,arg);}
		Tshot1;
		Tshot2;
		if(rank==4){
			Tgazou(1, 156, 156, 312);
		}
		else{
			Tgazou(1, 1, 156, 156);
		}
		Tgazou3(192, 0, 272, 80,16);
   	layer = 0;
    }
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY+30, 64);}
           PlaySE(se2);
           Tdeath(14,64,2,1);
        }
        if(time>240&&GetY>500){VanishEnemy;}
        if(time>1000){VanishEnemy;}
        if(phase>=1&&GetY>0){SetCollisionA(GetX(), GetY(), 60);}
        SetX(mapx-GetCommonData("bgx"));
        SetY(GetCommonData("bgy")-mapy);
        if(GetCommonData("kakusei")>0){lv=1}
        else{lv=0}
        time++;
        yield;
    }
    @Finalize() {
    }
    @DrawLoop {
    }

    task Tshot1{
        yield;
        wait(30);
        loop{
           if(GetX>32&&GetX<416&&GetY>25&&GetY<300){
              SetShotDirectionType(ABSOLUTE);
              let a=0;
              loop(5+rank/2){
                 if(phase==0){return;}
                 CreateShotFromScript( "shot1",GetX()+cos(angle)*38, GetY()+sin(angle)*30, 2.3+ex, 90, 0, 12);
                 CreateShotFromScript( "shot1",GetX()+cos(angle+180)*38, GetY()+sin(angle+180)*30, 2.3+ex, 90, 0, 12);
                 a++;
                 wait(4);
              }
           }
           if(lv==0){wait(20-rank*3);}
           wait(15);
        }
    }
    task Tshot2{
        yield;
        wait(30);
        loop{
           if(GetX>32&&GetX<416&&GetY>16&&GetY<280){
              loop(10+rank*3){
                 if(phase==0){return;}
                 let a=0;
                 let p=genteikaku(GetAngleToPlayer,16);
                 loop(1+ex){
                    CreateShotFromScript( "shot1",GetX()+cos(p+10)*30, GetY()+sin(p+10)*25, 3+a, p, 0, 04);
                    CreateShotFromScript( "shot1",GetX()+cos(p-0)*30, GetY()+sin(p-0)*25, 3+a, p, 0, 04);
                    CreateShotFromScript( "shot1",GetX()+cos(p-10)*30, GetY()+sin(p-10)*25, 3+a, p, 0, 04);
                    a++;
                 }
              wait(3);
              }
           }
           if(lv==0){wait(40-rank*6);}
           wait(10);
        }
    }
    task Tmove1{
        let a=angle;
        angle=90;
        yield;
        SetMovePosition02( GetX(), GetY()+500, 800);
        wait(800);
        VanishEnemy;
    }
    task Tmove2{
        let a=angle;
        a/=2;
        angle=90;
        yield;
        SetMovePosition02( GetX(), GetY()+120, 80);
        wait(80);
        SetMovePosition02( GetX()-24*a, GetY()+35, 30);
        angle=90+45*a;
        wait(30);
        SetMovePosition02( GetX()-1000*a, GetY+500, 1000);
        angle=90+90*a;
    }
    task Tmove3{
        let a=angle;
        a/=3;
        angle=90*a;
        yield;
        SetMovePosition02( GetX()-100, GetY()+200*a, 200);
        wait(200);
        SetMovePosition02( GetX()-35, GetY()+24*a, 30);
        angle=180-45*a;
        wait(30);
        SetMovePosition02( GetX()-600, GetY(), 400);
        angle=180;
    }

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



let layer = 1;
let bairitu = 1;

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_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);
		Obj_SetX(objenemy,GetX);
		Obj_SetY(objenemy,GetY);
		yield;
	}
	Obj_Delete(objenemy);
}

task Tgazou3(x1,y1,x2,y2,way)
{
	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_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);
		ObjEffect_SetAngle(objenemy,30,0,genteikaku(GetAngleToPlayer(),way));
		Obj_SetX(objenemy,GetX);
		Obj_SetY(objenemy,GetY);
		yield;
	}
	Obj_Delete(objenemy);
}
    #include_function".\efanction.txt"
}

#include_script".\escript.txt"