#TouhouDanmakufu
#Title["Youkai of Darkness"]
#Text[Rumia remembers the good times. You know, before you MURDERED HER.]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
    let ImgBoss = "script\img\ExRumia.png";
	let rumia =GetCurrentScriptDirectory ~ ("\rumia.png");
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    let frame = -120;
let laser = GetCurrentScriptDirectory~"laser.wav";
    let shot = GetCurrentScriptDirectory~"shot.wav";
	let background = GetCurrentScriptDirectory~"patchybackground.png";
	let charge = GetCurrentScriptDirectory~"charge.wav";
	let music = GetCurrentScriptDirectory~"Kyuu.mp3";
    @Initialize {
        SetLife(5000);
	LoadSE(shot);
	LoadSE(charge);
	LoadSE(laser);
        SetTimer(121);
	shotinit;
	
	LoadGraphic(rumia);
	SetGraphicRect(1, 1, 128, 256);
        SetScore(1000000);
	SetShotAutoDeleteClip(20, 20, 20, 20);
	SetDamageRate(150,75);
	SetInvincibility(180);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        CutIn(KOUMA, ""\""Youkai of Darkness"\", GetCurrentScriptDirectory~"rumia.png", 0, 0, 128, 256);
	LoadGraphic(background);
        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        SetGraphicRect(0, 0, 64, 64);
    }

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

	if(GetEnemyLife<2000 && GetEnemyLife>1990){
	SetColor(30, 20, 10);
	Concentration01(60);
	frame2 = 700;
	SetColor(255, 255, 255);
	PlaySE(charge);
	let p = 1;
	
	}
	//Demarcation below here to the next message to myself.
	if(GetEnemyLife<3500){
	let u = 100;
	}
if(frame==60){
	let a = rand(30, 300);
        let numz = 100+u; //Change this number here to specify the number of bullets in the ring.
	loop(numz)
            {	PlaySE(shot);
		CreateShotA(1, GetX, GetY, 10);
		SetShotDataA(1, 0, 5, a+GetAngleToPlayer, 0.54, -0.75, 1.7, GREEN12);
		a +=360/numz;
FireShot(1);

	PlaySE(shot);
		CreateShotA(1, GetX, GetY, 10);
		SetShotDataA(1, 0, 5, a+GetAngleToPlayer, -0.54, -0.75, 1.7, BLUE12);
		a +=360/numz;
FireShot(1);
}
}

	
if(GetEnemyLife<3500 && GetEnemyLife>3000){
SetDamageRate(125, 0);
}
if(GetTimer>50){
b = 20;
}

if(GetEnemyLife>2000){
 b = 10;
}
if(GetEnemyLife<2000){
b = 20;
SetDamageRate(75, 0); 
if(GetPlayerType == REIMU_A){ 
SetDamageRate(100, 0);
 }
}
if(GetTimer<50){
b = 30;
}

//lasers
if(GetEnemyLife<2000 || GetTimer<40 && frame2==720){

 CreateLaserA(1, GetX, GetY, 4, 70, BLUE60, 60);
	    SetLaserDataA(1, 0, -50+90, 0.055, 8, 0, 60); 
	    SetShotKillTime(1, 720);
	    FireShot(1);
            PlaySE(laser);

	CreateLaserA(2, GetX, GetY, 4, 70, BLUE60, 60);
	    SetLaserDataA(2, 0, 50+90, -0.055, 8, 0, 60); 
	    SetShotKillTime(2, 720);
	    FireShot(2);
           
        }

if(frame == 121){
	frame=0;
	}
        



	if(p == 0 && frame4==720 ){
	SetColor(30, 20, 10);
	Concentration01(60);
	SetColor(255, 255, 255);
	PlaySE(charge);
	}
        frame++;
	frame2++;
	frame4+=0.1;
	if(frame2 == 721){
	frame2=0;
	}
    }

    @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 y = 0;
let u = 0;
let b = 0;
let p = 0;
let r = 0;
let o = 0;
let frame2 = 0;
let frame4 = 0;
let frame3 = 0;
@BackGround{
   SetTexture(background);
   SetGraphicRect(0, 0 - y, 512, 512 - y);
   DrawGraphic(GetCenterX, GetCenterY);
   y++;
}
 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;
		}
	}


    @Finalize {
        DeleteGraphic(ImgBoss);
	DeleteSE(music);
    }




}
