#TouhouDanmakufu
#Title[17]
#Text[Hm...]
#Player[FREE]
#PlayLevel[Normal]
#BGM[.\theme]
#ScriptVersion[2]

script_enemy_main{
	let shot = GetCurrentScriptDirectory ~ "bgm\se_tan01.wav";
	let ling = GetCurrentScriptDirectory ~ "bgm\se_kira00.wav";
	let laser = GetCurrentScriptDirectory ~ "bgm\se_lazer01.wav";
	let caution = GetCurrentScriptDirectory ~ "bgm\se_caution.wav";
	let ch = GetCurrentScriptDirectory ~ "bgm\se_charge.wav";



    	let BossCutIn = "script\Shiro\Shiro.png"; 
    	let image="script\Shiro\sheet.png"; 
	let frame = 0;
	let angle = 0;
	let CSD = GetCurrentScriptDirectory;
	let lay = CSD ~ "iceflakes.png";
	let bg = CSD ~ "spbg.png";
	let slide = 200;
	let slide2 = 0;
	let rotate = 0;
	let bosseffect2 = CSD ~ "bosseffect2.png" ;


	let time = 0;
	let time2 = 0;

	@Initialize{
		SetLife(1700);
		SetDamageRate(20, 0);
		SetInvincibility(1200);
		LoadGraphic(image);
		LoadGraphic(lay);
		LoadGraphic(bg);
		LoadGraphic(bosseffect2);
		LoadSE(shot);
		LoadSE(laser);
		LoadSE(caution);
		LoadSE(ch);
		LoadSE(ling);
		SetTimer(49);
		SetDurableSpellCard;
		LoadUserShotData(CSD ~ "tiro\ZUN's shotdata.txt");
		CutIn(KOUMA, " "\""Bloody Heaven "\", BossCutIn, 0, 0, 200,282);
		SetEnemyMarker(true);
		SetEffectForZeroLife(120, 105, 2);
		SetDurableSpellCard;
		SetScore(13000000);
		SetMovePosition02(GetCenterX, GetCenterY, 60); 

		main;
	}
	

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


	}

	@DrawLoop{

		SetTexture(lay);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetGraphicAngle(0, 0, 0);
		SetGraphicRect(0,0,600000,600000);
		SetGraphicScale(1, 1);
		DrawGraphic(GetX+rotate,GetY+rotate/2);


		SetTexture(bosseffect2);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetGraphicAngle(0, 0, rotate);
		SetGraphicRect(0,0,256,256);
		SetGraphicScale(2, 2);
		DrawGraphic(GetX,GetY);



		SetTexture(image);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetAlpha(120);
		SetGraphicAngle(0, 0, 0);
		SetGraphicRect(0,0,83,117);
		SetGraphicScale(1, 1);
		DrawGraphic(GetX,GetY);

	}

	@BackGround{


		SetTexture(bg);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicAngle(0, 0, rotate/2);
		SetGraphicScale(2, 2);
		SetGraphicRect(0,0,256,256);
		DrawGraphic(GetCenterX,GetCenterY);

		rotate+=1;
		slide2+=1;
		}


	@Finalize
	{
		DeleteSE(shot);
		DeleteGraphic(bg);
		DeleteGraphic(lay);
		DeleteGraphic(image);
	}

	task main{
		fire;
		yield;
		}

	task fire{


		wait(210);
		PlaySE(ch);
		Concentration02(100);
		wait(180);

		let x = 0;
		let xa = 5;
		let dir= 0;
		let time = 0;

		loop{
		loop(9){
			while(x<1){
				ascent(i in 0..18){
					ascent(k in 0..2){
					reflect(GetX, GetY, 1+i*0.15, dir+k*3, 155, 3); }
					x++;
					}
					PlaySE(shot);
					dir+=17;
				}
			x=0;
			wait(5);
			}
			dir+=rand(0, 360);
			wait(180 - time);
			time+=5;

		loop(9){
			while(x<1){
				ascent(i in 0..18){
					ascent(k in 0..2){
					reflect(GetX, GetY, 1+i*0.15, dir+k*3, 155, 3); }
					x++;
					}
					PlaySE(shot);
					dir+=65;
				}
			x=0;
			wait(5);
			}
			dir+=rand(0, 360);
			wait(180 - time);
			time+=5;

		loop(9){
			while(x<1){
				ascent(i in 0..18){
					ascent(k in 0..2){
					reflect(GetX, GetY, 1+i*0.15, dir+k*2, 155, 3); }
					x++;
					}
					PlaySE(shot);
					dir+=rand(52, 107);
				}
			x=0;
			wait(5);
			}
			dir+=rand(0, 360);
			wait(180 - time);
			time+=5;

		}

			
	}

		


	task reflect(x, y, speed, dir, graph, delay){
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, dir);
		ObjShot_SetGraphic(obj, graph);	
		ObjShot_SetDelay(obj, delay);	
		ObjShot_SetBombResist(obj, true); 

				wait(40);
				loop(10){
					Obj_SetSpeed(obj, Obj_GetSpeed(obj) - Obj_GetSpeed(obj)/10);
					wait(2);
					}
				Obj_SetSpeed(obj, 0);
				wait(30);

				ObjShot_SetGraphic(obj, 16);	
				wait(40);	
				ObjShot_SetGraphic(obj, 156);
				loop(10){
					Obj_SetSpeed(obj, Obj_GetSpeed(obj) + 0.2);
					Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
					wait(1);
					}
				wait(10);
				loop(20){
					Obj_SetSpeed(obj, Obj_GetSpeed(obj) - Obj_GetSpeed(obj)/20);
					wait(1);
					}
				Obj_SetSpeed(obj, 0);

				wait(10);
				ObjShot_SetGraphic(obj, 4);	
				wait(40);	
				ObjShot_SetGraphic(obj, 157);

				PlaySE(ling);
				loop(20){
					Obj_SetSpeed(obj, Obj_GetSpeed(obj) + 0.3);
					Obj_SetAngle(obj, atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));
					wait(1);
					}

				yield;

	}


			
	//Função "wait"

	function wait(w){
		loop(w){yield;}
		}


}