script_enemy_main {
	let time = rand_int(0,60);
    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\clone2.png";
    let tama = GetCurrentScriptDirectory~"tama.txt";
    let se1 = GetCurrentScriptDirectory~"wav\se1.wav";
    let se11 = GetCurrentScriptDirectory~"wav\se11.wav";
    if(ex==1){rank=4;}
    @Initialize(){
		SetLife( 120 );
		SetInvincibility( 10 );
		LoadGraphic( imgEnemy );
		LoadUserShotData( tama );
		SetX(mapx-GetCommonData("bgx"));
		SetY(GetCommonData("bgy")-mapy);
    	
    	if(arg==0){
    	}
    	else{
			setmove(angle,arg);
    	}
    	
		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-(|sin(time*5)*80|));
        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>48&&GetX<400&&GetY>16&&GetY<(250+rank*25)){
				let p=genteikaku(GetAngleToPlayer(),32);
				SetShotDirectionType(ABSOLUTE);
				let a=0;
				loop(3){
					CreateShotFromScript( "shot1",GetX()+cos(p)*10, GetY()+sin(p)*10, 2+a+ex, p+ex*(a-2)*5, 0, 06);
					if(ex==1){
						CreateShotFromScript( "shot1",GetX()+cos(p)*10, GetY()+sin(p)*10, 2+a+ex, p-ex*(a-2)*5, 0, 06);
					}
					a++;
				}

			}
			if(lv==0){wait(32-rank*7);}
			wait(4);
		}
	}


	task setmove(a,t) {
		loop(t) {
			mapx+=cos(a)*1.2;mapy-=sin(a)*1.2;
			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=64;
			/*
			if(time%40<10){
				y=64;
				ObjEffect_SetAngle(objenemy,0,0,0);
			}
			else if(time%40<20){
				y=32;
				ObjEffect_SetAngle(objenemy,0,180,0);
			}
			else if(time%40<30){
				y=0;
				ObjEffect_SetAngle(objenemy,0,0,0);
			}
			else{
				y=32;
				ObjEffect_SetAngle(objenemy,0,0,0);
			}
			*/
			if(time%24<6){x=0;}
			else if(time%24<12){x=24;}
			else if(time%24<18){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"