#TouhouDanmakufu
#Title[Bonus 2]
#Text[SHAPES EVERWHERE. Didn't make the cut. Reason: Boring/doesn't fit.]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User(.\moon.png, 0, 0)]
script_enemy_main {
    let ImgBoss = "script\img\ExRumia.png";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let eyb = GetCurrentScriptDirectory~"eyb.mp3";
    let frame = -60;
	let background = GetCurrentScriptDirectory~"patchybackground.png";
	let shot4 = GetCurrentScriptDirectory~"shot4.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
    @Initialize {
        SetLife(10);
        SetTimer(51);
	LoadSE(shot4);
	LoadMusic(eyb);
	PlayMusic(eyb);
	CutIn(KOUMA, ""\""Geometric View of Gensokyo"\", GetCurrentScriptDirectory~"rumia.png", 0, 0, 128, 256);
	LoadSE(shot);
	LoadGraphic(background);
	SetDamageRate(0, 0);
	SetDurableSpellCard;
	shotinit;
	SetScore(100000);
	let f = 2;
	let h = 2;
	SetInvincibility(1000000);
	SetDamageRate(100, 0);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
	

        LoadGraphic(ImgBoss);
        SetTexture(ImgBoss);
        SetGraphicRect(0, 0, 64, 64);
    }

    @MainLoop {
	

	if(frame == -9){SetMovePosition02(GetPlayerX, GetPlayerY, 40);
	
	}
	if(frame>120){
	frame=-10;
	}
	let b = rand_int(3, 6);
	let v = b+11;
	if(b == 3){
		
		}
        SetCollisionA(GetX, GetY, 0);
        SetCollisionB(GetX, GetY, 0);

if(frame == 30){
ShootShape(GetX, GetY, 1.75, rand(0, 16)+GetAngleToPlayer, b, v, BLUE01, 30);
PlaySE(shot4);

}
	if(frame==60){
	PlaySE(shot);
	}

if(GetTimer<40 && GetTimer>30){
	if(frame==100){
	frame=-20;
}
}
if(GetTimer<30 && GetTimer>20){
	if(frame==80){
	frame=-20;
}
}
	
	if(GetTimer<20 && GetTimer>10){
	if(frame==75){
	frame=-10;
		}
		}

	if(GetTimer<10){
	let b = 3;
	if(frame==63){
	frame=-10;
	}
	}
        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 y = 0;
let q = 0;
@BackGround{
   SetTexture(background);
   SetGraphicRect(0, 0 - y, 512, 512 - y);
   DrawGraphic(GetCenterX, GetCenterY);
   y+=7;
}
    
function ShootShape(spawnX, spawnY, v, angle, num, bside, graphic, delay) {
	ascent(i in 0..num) {
		let sx = spawnX+cos(angle+i*360/num); let sy = spawnY+sin(angle+i*360/num); let sxN = spawnX+cos(angle+(i+1)*360/num); let syN = spawnY+sin(angle+(i+1)*360/num);
		CreateShot01(spawnX, spawnY, v*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), atan2(sy-spawnY,sx-spawnX), graphic, delay);
		ascent(j in 0..bside) {
			let toAngle = atan2(syN-sy,sxN-sx); let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5); let sx2 = sx+toDist/bside*j*cos(toAngle); let sy2 = sy+toDist/bside*j*sin(toAngle);
			CreateShot01(spawnX, spawnY, v*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.5), atan2(sy2-spawnY,sx2-spawnX), graphic, delay);
		}
	}
}


    @Finalize {
        DeleteGraphic(ImgBoss);
    }




}
