#TouhouDanmakufu
#Title[Nonspell 1]
#Text[First Nonspell]
#Player[FREE]
#ScriptVersion[2]
#BGM[.\trueadmin.mp3]
#BackGround[User(.\moon.png, 0, 0)]
script_enemy_main {
    let ImgBoss = "script\img\ExRumia.png";
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    let frame = 0;
    let shot = GetCurrentScriptDirectory~"shot.wav";

    @Initialize {
	LoadSE(shot);

        SetLife(2000);
        SetTimer(55);
	SetInvincibility(180);
	SetEnemyMarker(true);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        shotinit;
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        SetGraphicRect(0, 0, 64, 64);
	SetDamageRate(100, 100);
	SetShotAutoDeleteClip(20, 20, 20, 20);
    }

@MainLoop {
	SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	
	

        if(frame == 121){
	

	let a   = 0.5;
        let num = 24; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 3.75, a+GetAngleToPlayer, BLUE02, 0);
            a += 360/num;
	    
		frame=-10;
		
}
        }
   

if(frame == 20){
	

	let a   = 0.5;
        let num = 24; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 3.75, a+GetAngleToPlayer, BLUE02, 0);
            a += 360/num;
		PlaySE(shot);
		
		
}
        }



if(frame == 60){
	

	let a   = 0.5;
        let num = 24; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 3.75, a+GetAngleToPlayer, BLUE02, 0);
            a += 360/num;
		PlaySE(shot);
		
}
        }



if(frame == 100){
	

	let a   = 2;
        let num = 24; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 3.75, a+GetAngleToPlayer, BLUE02, 0);
            a += 360/num;
		PlaySE(shot);
		
}
        }




if(frame == 60) {

SetMovePosition03(rand(50, 15)+GetX, rand(-10, -20)+GetY, 3, 1.5); 

}

if(frame == 20){

	let a   = 4;
        let num = 20; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 2.5, a+GetAngleToPlayer, YELLOW02, 0);
            a += 360/num;
        PlaySE(shot);
    }
	}



if(frame == 60){

	let a   = 4;
        let num = 20; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 2.5, a+GetAngleToPlayer, YELLOW02, 1);
            a += 360/num;
        PlaySE(shot);
    }
	}



if(frame == 100){

	let a   = 4;
        let num = 20; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 2.5, a+GetAngleToPlayer, YELLOW02, 0);
            a += 360/num;
        PlaySE(shot);
    }
	}

if(frame == 120){

	let a   = 4;
        let num = 20; //Change this number here to specify the number of bullets in the ring.
        
        loop(num)
        {
            CreateShotReflect(GetX, GetY, 2.5, a+GetAngleToPlayer, YELLOW02, 0);
            a += 360/num;
	PlaySE(shot);
        
    }
	}



if(frame == 120) {

SetMovePosition03(rand(-50, -15)+GetX, rand(10, 20)+GetY, 3, 1); 

}

frame++;

}

task CreateShotReflect(x, y, v, ang, graphic, delay) {
		let obj_id = Obj_Create(OBJ_SHOT); let border = 20; 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) { 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;
		}
	}

    @DrawLoop {
        SetTexture(ImgBoss);
                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);
    }



    @Finalize {
        DeleteGraphic(ImgBoss);
    }
}
