
#Title[13,Ł]
#Text[]
#Image[]
#BGM[.\bgm\.mp3]
#Player[FREE]
#BackGround[User(.\img\.png, 0, 0)]//384~448 
#ScriptVersion[2]

script_enemy_main {
	let imgExRumia   = GetCurrentScriptDirectory~"img\ExRumia.png";
	let haikei=GetCurrentScriptDirectory~"img\2back.png";
	let imgEnemy=GetCurrentScriptDirectory~"g\img\kiri2.png";//Enemy.pngւ̃pX
	let coun      =  0;
	let cou      =  0;
	let co       =  0;
	let an       =  0;
	let cx;
	let cy;



                let csd        = GetCurrentScriptDirectory;
                let shotData   = csd ~ "kshotData.txt";
                let tam         =csd~"se\counte.wav";
                let tama         =csd~"se\syan.wav";
                let taman         =csd~"se\shot10.wav";

	@Initialize {; 
		LoadGraphic(imgEnemy);
		SetTimer(30);

		SetX(GetCenterX);
		SetY(GetClipMinY + 120);
		cx=GetCenterX();  
		cy=GetCenterY(); 
		SetLife(5000);
		SetGraphicRect(64,1,127,64);
		SetMovePosition03(cx,cy-120,40,5);  
		LoadGraphic(imgExRumia); 
		SetTexture(imgExRumia);
		SetDamageRate(150,150); 
		LoadGraphic(haikei);
		LoadUserShotData(shotData);
                SetInvincibility(200);


                     TMove;
                     UpDown_Task;
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 48);
		SetCollisionB(GetX, GetY, 24);

		coun++;
		cou++;
		co++;

		if(coun==1200)
			{
                                PlaySE(tam);	
				coun=1140;
			}


		if(cou==172)
			{
				co=172;
                                an=0;
                        }
		if(cou==372)
			{
				co=0;
				cou=0;
                        }
		if(co==100)
			{
				loop(1){
                                 an+=10;
                                PlaySE(tama);	
		                CreateEnemyFromFile(GetCurrentScriptDirectory~"g\Enemy1-3.txt",GetX,GetY,10,an,0);
                                }
				co=98;
                        }

                        yield;
	}
    function wait(w) {
        loop(w) { yield; }
    }
	@DrawLoop {
		SetTexture(imgExRumia);
		if(int(GetSpeedX())==0){SetGraphicRect(64,1,127,64);}
		else if(GetSpeedX()>0){SetGraphicRect(192,1,255,64);}
		else if(GetSpeedX()<0){SetGraphicRect(128,1,191,64);}
		DrawGraphic(GetX, GetY);
	}
		@BackGround
		{
			SetGraphicRect(1,1,384,448);
		        SetTexture(haikei);
                        DrawGraphic(cx,cy);

		}

	@Finalize {
		DeleteGraphic(imgExRumia);
	}

    task UpDown_Task {
        let updown = 0;

        loop{
        if(GetSpeed==0 && updown==0){
        SetMovePosition02(GetX,GetY+20,80);
        updown+=1;
        }
        if(updown>0 && updown<81){
        updown+=1;
        }

        if(GetSpeed==0 && updown==81){
        SetMovePosition02(GetX,GetY-20,80);
        updown+=1;
        }
        if(updown>81 && updown<161){
        updown+=1;
        }

        if(updown==161){
        updown=0;
        }

        yield;
        }
    }

  /**/        task TMove
                 {
                      wait(200);
                    yield;

                    loop 
                    {
                        loop(200) { yield; }
                        moveToPlayer(rand(30, 120), rand(10, 20), 4,
                        GetClipMinX+60, cy-140,
                        GetClipMaxX-60, cy-80);
                    }
                 }


   /**/        function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;

        if(GetPlayerX < GetX) {
            // vC[EɓG΁AG͍ɓ܂B
            x = GetX - xMove;

            // AAG̈̍[ɂ悤ȂAEɓ܂B
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            // Ȃ΁AG͉Eɓ܂B
            x = GetX + xMove;

            // AAG̈̉E[Eɂ悤ȂAɓ܂B
            if(right < x) {
                x = GetX - xMove;
            }
        }

        // ̈̊Oɍsꍇ́A[Ŏ~߂܂B
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition03(x, y,20, frame);
    }
                     
}