#TouhouDanmakufu
#Title[Echoed Voice -Hard-]
#Text[Yambikoooo]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
    let ImgBoss = "script\img\ExRumia.png";
		#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    let frame = 0;
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
let shot = GetCurrentScriptDirectory~"shot.wav";
	let background = GetCurrentScriptDirectory~"patchybackground.png";
    @Initialize {
        SetLife(3000);
        SetTimer(80);
        SetScore(2000000);
	SetInvincibility(180);
	shotinit;
	LoadSE(bounce);
	LoadSE(shot);
	SetDamageRate(75, 1);
	LoadGraphic(background);
	SetShotAutoDeleteClip(300, 300, 300, 30);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        CutIn(KOUMA, ""\""Echoed Voice -Hard-"\", GetCurrentScriptDirectory~"rumia.png", 0, 0, 128, 256);
        
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        SetGraphicRect(0, 0, 64, 64);
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	m = rand(-0.7, 0.7);
        if(frame == 120 || frame == 180 || frame == 240){

	let a   = 0;
        let num = 20; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 2.5+m, a+GetAngleToPlayer+50, RED03, 10);
            a += 270/num;
	PlaySE(shot);
}
}
		
if(frame == 121|| frame == 181 || frame == 241){		
let a   = 0;
        let num = 1; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 2.5, a+GetAngleToPlayer, RED03, 10);
            a += 1/num;
	
}
}
if(frame == 241){
frame = -0;
}
	yield;
        frame++;
	

    }

    @DrawLoop {
	SetTexture(ImgBoss);
                SetRenderState(ALPHA);
                SetAlpha(255);  
                SetGraphicScale(1,1);
                SetGraphicAngle(0,0,0);

                if(GetSpeedX==0){
                         SetGraphicRect(0,0,64,64); }
                        
 
                if(GetSpeedX>0){
                        SetGraphicRect(190, 126, 256, 64);
			}
 
                if(GetSpeedX<0){
                        
                        SetGraphicRect(128,128,186,64); }
                      
 
                DrawGraphic(GetX,GetY);
    }
let m = 0;
let w = 0;
   task CreateShotReflect(x, y, v, ang, graphic, delay) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = 150+m; let  counter = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); Obj_SetAngle(obj_id, ang); ObjShot_SetDelay(obj_id, delay);
		while(!Obj_BeDeleted(obj_id)) {
			if(counter <= 1) {
				
				if(Obj_GetX(obj_id) > GetClipMaxX+border) { PlaySE(bounce); Obj_SetX(obj_id, 2*(GetClipMaxX+border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)); counter+=2; }
				else if(Obj_GetX(obj_id) < GetClipMinX-border) { Obj_SetX(obj_id, 2*(GetClipMinX-border)-Obj_GetX(obj_id)); Obj_SetAngle(obj_id, 180-Obj_GetAngle(obj_id)); counter+=2; }
				else if(Obj_GetY(obj_id) < GetClipMinY-border) { Obj_SetY(obj_id, 2*(GetClipMinY-border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
				//else if(Obj_GetY(obj_id) > GetClipMaxY+border) { Obj_SetY(obj_id, 2*(GetClipMaxY+border)-Obj_GetY(obj_id)); Obj_SetAngle(obj_id, -Obj_GetAngle(obj_id)); counter+=1; }
			}
			yield;
		}
	}


@BackGround{
   SetTexture(background);
   SetGraphicRect(0, 0 - w, 512, 512 - w);
   DrawGraphic(GetCenterX, GetCenterY);
   w+=3;
}


    @Finalize {
        DeleteGraphic(ImgBoss);
    }




}