

script_enemy_main
{    

    let count=-300;
    let diff = 4;
    let bg = "script\DanMUku\Image\bonusroom.png";
    let bonus = "script\DanMUku\Image\bonus.png";
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";
    let timer = 0;
    let v = 1;
    let x = GetCenterX;
    let change=1;
    let graphic=100;
    let phase = false;
    let rate=300;


   @Initialize
   {
      LoadUserShotData("script\DanMUku\MUtir\MUtir.txt");
      LoadGraphic(bg);
      LoadGraphic(bonus);
      LoadSE(tir);
      LoadSE(munch);
	LastSpell;
	//PlayMusic("script\DanMUku\Musique\bonus.mp3");
            SetLife(8500);
            SetTimer(120);
            SetInvincibility(100);
            SetEnemyMarker(false);
            SetScore(0);
   }
   
 function Wait(let frames){
   loop(frames){yield;}
 }

   @MainLoop
   {

	if(count==-200){
		CreateLaserA(1, 0, 0, 500, 20, 4, 0);
		SetLaserDataA(1, 0, 0, 0, 0, 1, 90);
		SetLaserDataA(1, 145, 0, 0, 0, 0, 90);
		FireShot(1);
		CreateLaserA(2, 0, GetClipMaxY+20, 500, 20, 4, 0);
		SetLaserDataA(2, 0, 0, 0, 0, 1, 270);
		SetLaserDataA(2, 145, 0, 0, 0, 0, 270);
		FireShot(2);
		CreateLaserA(3, 0, 0, 500, 20, 4, 0);
		SetLaserDataA(3, 0, 90, 0, 0, 1, 0);
		SetLaserDataA(3, 145, 90, 0, 0, 0, 0);
		FireShot(3);
		CreateLaserA(4, GetClipMaxX+20, 0, 500, 20, 4, 0);
		SetLaserDataA(4, 0, 90, 0, 0, 1, 180);
		SetLaserDataA(4, 145, 90, 0, 0, 0, 180);
		FireShot(4);
	}

	if (count==rate) {
		let angle = rand(0,360);
		loop(6){
			Bouncing_Bullet(GetPlayerX+cos(angle)*100, GetPlayerY+sin(angle)*100, 1, angle, 30, 28);
			angle+=60;			
		}
		rate+=3;
		count=0;
	}


timer=GetTimer;

count++;
yield;
   }
   @Finalize
   {
	DeleteMusic("script\DanMUku\Musique\bonus.mp3");
	if (GetArgument==5) {
		if(timer==0){
			CreateItem(ITEM_BOMB, rand(GetX-20, GetX+20), GetClipMinY); 
		}
		if(timer<20){
			CreateItem(ITEM_1UP, rand(GetX-20, GetX+20), GetClipMinY);  
		}
		if(timer<40){
			CreateItem(ITEM_BOMB, rand(GetX-20, GetX+20), GetClipMinY);  
		}
		if(timer<60){
			CreateItem(ITEM_1UP, rand(GetX-20, GetX+20), GetClipMinY);  
		}
		if(timer<90){
			CreateItem(ITEM_BOMB, rand(GetX-20, GetX+20), GetClipMinY);  
		}
	}
	if (GetArgument==4) {
		if(timer==0){
			CreateItem(ITEM_1UP, rand(GetX-20, GetX+20), GetClipMinY); 
		}
		if(timer<20){
			CreateItem(ITEM_BOMB, rand(GetX-20, GetX+20), GetClipMinY);  
		}
		if(timer<40){
			CreateItem(ITEM_1UP, rand(GetX-20, GetX+20), GetClipMinY);  
		}
		if(timer<60){
			CreateItem(ITEM_BOMB, rand(GetX-20, GetX+20), GetClipMinY);  
		}
	}
	if (GetArgument==3) {
		if(timer==0){
			CreateItem(ITEM_BOMB, rand(GetX-20, GetX+20), GetClipMinY); 
		}
		if(timer<20){
			CreateItem(ITEM_1UP, rand(GetX-20, GetX+20), GetClipMinY);  
		}
		if(timer<40){
			CreateItem(ITEM_BOMB, rand(GetX-20, GetX+20), GetClipMinY);  
		}
	}


	loop(GetArgument*((120-timer)/5) ){
		CreateItem(ITEM_SCORE, rand(GetX-20, GetX+20), rand(GetClipMinY+20, GetClipMinY+50));  
	}

   }

   @DrawLoop
   {

            SetTexture(bg);
            SetRenderState(ALPHA);
            SetAlpha(255);
            SetGraphicRect(0, 0, 50000, 50000);

            SetGraphicScale(1,1);
            SetGraphicAngle(0, 0, 0);
            DrawGraphic(GetCenterX, GetCenterY-50);


			SetTexture(bonus);
		    SetRenderState(ALPHA);
		    SetAlpha(255);
		    SetGraphicRect(0, 0, 150, 80);
			SetGraphicScale(1,1);
            		SetGraphicAngle(0, 0, 0);
			DrawGraphic(GetCenterX, GetCenterY-50);


	DrawText("Bonus", GetClipMinX+10, GetClipMinY+15, 12, 255);
   }


   task Bouncing_Bullet(x, y, v, angle, delay, bullet)
   {
            let obj=Obj_Create(OBJ_SHOT);

            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, angle);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, bullet);
            ObjShot_SetDelay  (obj, delay);

            while(Obj_BeDeleted(obj)==false)
      {
                    if(Obj_GetX(obj)<GetClipMinX)
         {
                          Obj_SetAngle(obj,  180-Obj_GetAngle(obj) );
                          Obj_SetX(obj,  Obj_GetX(obj) + 0.1);
                    }

                    if(Obj_GetX(obj)>GetClipMaxX)
         {
                          Obj_SetAngle(obj,  180-Obj_GetAngle(obj) );

                          Obj_SetX(obj,  Obj_GetX(obj) - 0.1);
                    }

                    if(Obj_GetY(obj)<GetClipMinY)
         {
	        Obj_SetAngle(obj, -Obj_GetAngle(obj) );
                          Obj_SetY(obj,  Obj_GetY(obj) + 0.1);
                    }
                    if(Obj_GetY(obj)>GetClipMaxY)
         {
	        Obj_SetAngle(obj, -Obj_GetAngle(obj) );
                          Obj_SetY(obj,  Obj_GetY(obj) - 0.1);
                    }

         yield;
            }
   }

}
