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\clone1.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se11 = GetCurrentScriptDirectory~"wav\se11.wav";
    if(ex==1){rank=4;}
	let spin=1;
    @Initialize(){
		SetLife( 120 );
		SetInvincibility( 10 );
		LoadGraphic( imgEnemy );
		LoadUserShotData( tama );
		SetX(mapx-GetCommonData("bgx"));
		SetY(GetCommonData("bgy")-mapy);
		
		if(arg==0){
			if(angle<360){
				if(GetX<=224){spin=-1;}
				Tspin1(angle);
			}
			else{
				//spin=-1;
				Tspin2(angle);
			}
		}
		else{
			if(GetX<224){spin=-1;}
			setmove(angle,arg);
			angle=rand(0,360);
		}
		
		if(ex==1){
			Tshotex;
		}
		else{
			Tshot;
		}
		
		Tgazou();
	}
    @MainLoop {
        if(phase==1&&GetLife<=100){
           phase-=1;
           if(lv==0||GetPoint>0){DeleteEnemyShotImmediatelyInCircle(SHOT, GetX, GetY+10, 30);}
           PlaySE(se11);
           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;
		loop{
			if(phase<=0){return;}
			if(GetX>48&&GetX<400&&GetY>16&&GetY<(250+rank*25)){
				SetShotDirectionType(ABSOLUTE);
				CreateShotFromScript( "shot1",GetX()+cos(angle+90)*15, GetY()+sin(angle+90)*10+8, 3.0+ex, angle+90-50, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle+90)*15, GetY()+sin(angle+90)*10+8, 3.0+ex, angle+90-140, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle-90)*15, GetY()+sin(angle-90)*10+8, 3.0+ex, angle-90-50, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle-90)*15, GetY()+sin(angle-90)*10+8, 3.0+ex, angle-90-140, 0, 14);
			}
			wait(3-lv*1);
			angle+=9.1*spin;
			if(angle<0){angle+=360;}
			angle = angle%360;
		}
    }
    task Tshotex{
		yield;
		angle=rand(0,360);
		loop{
			if(phase<=0){return;}
			if(GetX>48&&GetX<400&&GetY>16&&GetY<(250+rank*25)){
				SetShotDirectionType(ABSOLUTE);
				CreateShotFromScript( "shot1",GetX()+cos(angle+90)*15, GetY()+sin(angle+90)*10+8, 3.0+ex, angle+90-60, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle+90)*15, GetY()+sin(angle+90)*10+8, 3.0+ex, angle+90-90, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle+90)*15, GetY()+sin(angle+90)*10+8, 3.0+ex, angle+90-120, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle-90)*15, GetY()+sin(angle-90)*10+8, 3.0+ex, angle-90-60, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle-90)*15, GetY()+sin(angle-90)*10+8, 3.0+ex, angle-90-90, 0, 14);
				CreateShotFromScript( "shot1",GetX()+cos(angle-90)*15, GetY()+sin(angle-90)*10+8, 3.0+ex, angle-90-120, 0, 14);
			}
			wait(3-lv*1);
			angle+=9.1*spin;
			angle = angle%360;
		}
    }

	task Tspin1(let s){
		let cx=mapx;
		let cy=mapy;
		loop{
			s-=0.8*spin;
			mapx=cx+cos(s)*70;
			mapy=cy+sin(s)*45;
			yield;
		}
	}
	
	task Tspin2(let s){
		let cx=mapx;
		let cy=mapy;
		loop{
			s-=0.4*spin;
			mapx=cx+cos(s)*140;
			mapy=cy+sin(s)*90;
			yield;
		}
	}

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


	task Tgazou()
	{
		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_SetVertexXY(objenemy, 0, -18, -24);
		ObjEffect_SetVertexXY(objenemy, 1, -18,  24);
		ObjEffect_SetVertexXY(objenemy, 2,  18, -24);
		ObjEffect_SetVertexXY(objenemy, 3,  18,  24);

		ObjEffect_SetLayer(objenemy,0);
		
		loop{
			let x=24;
			let y;
			
			if(angle>=45 && angle<135){
				y=64;
				ObjEffect_SetAngle(objenemy,0,0,0);
			}
			else if(angle>=135 && angle<225){
				y=32;
				ObjEffect_SetAngle(objenemy,0,180,0);
			}
			else if(angle>=225 && angle<315){
				y=0;
				ObjEffect_SetAngle(objenemy,0,0,0);
			}
			else{
				y=32;
				ObjEffect_SetAngle(objenemy,0,0,0);
			}
			
			/*
			if(time%12<3){x=0;}
			else if(time%12<6){x=24;}
			else if(time%12<9){x=48;}
			else{x=24;}
			*/
			//四角形状に各頂点のUV値を設定。(0,0)-(10,10)の部分。
			ObjEffect_SetVertexUV(objenemy, 0, x, y);
			ObjEffect_SetVertexUV(objenemy, 1, x, y+32);
			ObjEffect_SetVertexUV(objenemy, 2, x+24, y);
			ObjEffect_SetVertexUV(objenemy, 3, x+24, y+32);
			Obj_SetX(objenemy,GetX);
			Obj_SetY(objenemy,GetY);
			yield;
		}
	Obj_Delete(objenemy);
	}

    #include_function".\efanction.txt"
}

#include_script".\escript.txt"