
script_enemy_main
{    

    let count=-100;
    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 x = GetCenterX;
    let y1= GetCenterY;
    let y2= GetCenterY;
    let timing = 8;

   @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>=0&&count%(timing*6)==0){
		y1 = rand(GetClipMinY, GetClipMaxY);
		y2 = rand(GetClipMinY, GetClipMaxY);
		x = rand(GetClipMinX, GetClipMaxX);
		PlaySE(tir);
	}
	
	if(count>0&&count%timing==1){
		Invisible(GetClipMaxX, y1, 180, 2, (y1%20-10)/20, 10);
	}

	if(count>0&&count%timing==1){
		Invisible(GetClipMinX, y2, 0, 2, (y2%20-10)*-0.05, 17);
	}

	if (count==1800) {
		timing=6;
	}

	if (count>3000&&count%timing==2){
		Invisible(x, GetClipMinY, 90, 2, (x%20-10)*-0.05, 9);
	}

	if (count==6000) {
		timing=4;
	}

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 Invisible(x, y, a, v, angular, g){

		let obj=Obj_Create(OBJ_SHOT);
            Obj_SetPosition(obj, x, y);
            Obj_SetAngle(obj, a);
            Obj_SetSpeed(obj, v);
            ObjShot_SetGraphic(obj, g);
		let alpha = 255;
		let change = 4;

	    while(Obj_BeDeleted(obj)==false) {
          	Obj_SetAlpha(obj, alpha);
		alpha+=change;
		if (alpha<0){
			change=4;
		}
		if (alpha>255){
			change=-4;
		}

		Obj_SetAngle(obj, Obj_GetAngle(obj)+angular);
         	yield;
            }
	}

}
