#TouhouDanmakufu
#Title[1]
#Text[Hm...]
#Player[FREE]
#PlayLevel[Normal]
#BackGround[IceMountain]
#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 charge = GetCurrentScriptDirectory ~ "bgm\se_charge.wav";


    	let image="script\Shiro\sheet.png"; 
	let CSD = GetCurrentScriptDirectory;


	@Initialize{
		SetLife(6000);
		SetDamageRate(120, 100);
		LoadGraphic(image);
		LoadSE(shot);
		LoadSE(laser);
		LoadSE(caution);
		LoadSE(charge);
		LoadSE(ling);
		SetTimer(82);
		LoadUserShotData(CSD ~ "tiro\ZUN's shotdata.txt");
		SetEnemyMarker(true);
		SetMovePosition02(GetPlayerX, GetCenterY-100, 60); 

		main;
	}
	

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

	}

	@DrawLoop{
		SetTexture(image);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetGraphicAngle(0, 0, 0);
		SetGraphicScale(1, 1);
		SetGraphicRect(0,0,85,120);
		DrawGraphic(GetX,GetY);
	}


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

	task main{
		wait(120);
		circle;
		move;
		yield;
		}





	task circle{

		let x = 0;
		let dir = 0;
		let dir2=0;

		let xa = 10;
		let sp = 0;
		wait(60);
		PlaySE(charge);
		Concentration01(40);
		wait(120);
		loop{
			loop(1){
				while(x<xa){
					reflect(GetX, GetY, 0.7, dir,74, 10);
					reflect(GetX, GetY, 1.2, -dir,76, 10);
					dir+=360/xa;
					x++;
					}
				x=0;
				dir+=rand(7, 10);
				PlaySE(shot);
				wait(10);
				}
			}
		}






	task move{
		loop{
			SetMovePosition03(GetCenterX+rand(-40, 40), GetCenterY+rand(-30, 30), 30, 30);
			wait(240);
			}
	yield;

	}


	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);


			while(Obj_BeDeleted(obj)==false) {


				yield;
					}
		
	}


	//Função "wait"

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

}