#TouhouDanmakufu
#Title[spell for]
#Text[epic]
#Player[REIMU]
#ScriptVersion[2]
#PlayLevel[Normal]

script_enemy_main{

	let D	= GetCurrentScriptDirectory;

	let imgBoss = D ~ ".\ReIMu.png";
	let cut = D ~ ".\Raimu.png";
	let s1 = D ~ "Shot.wav";
	let w1 = D ~ "Wave.wav";
	let shot = D ~ "supershot.txt";


	CutIn(YOUMU,"thu epic amuletes of reimu - DOOM-",cut,0,0,360,290);


	@Initialize{
		SetLife(2000);
		SetTimer(30);
		SetScore(100000);
		SetMovePosition01(GetCenterX,GetCenterY,5);
		LoadGraphic(imgBoss);
		LoadSE(s1);
		LoadSE(w1);
		SetInvincibility(120);
    		LoadUserShotData(shot);
		fire;
		fireb;
		movement;
	}

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

	@DrawLoop{
		SetTexture(imgBoss);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicRect(0,0,110,110);
		SetGraphicScale(0.7,0.7);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetX,GetY);
	}

	@BackGround{}

	@Finalize{
		loop(20){CreateItem(ITEM_SCORE,GetX+rand(-150,150),GetY+rand(50,200)); DeleteSE(s1);}
		DeleteGraphic(imgBoss);
		DeleteSE(w1);
	}
	task movement{
		loop{
			SetMovePosition01(GetCenterX-100,GetCenterY-120,5);
			wait(240);
			SetMovePosition01(GetCenterX+100,GetCenterY-30,5);
			wait(60);
			yield;
		}
	}

	task fire{
		let dir = GetAngleToPlayer;
		loop{
		PlaySE(s1);
			loop(30){
				loop(8){
					bullet(GetX, GetY, 5, dir-rand(30,-30), 99, 0);
					bullet(GetX, GetY, 5, dir-180-rand(30,-30), 99, 0);
					bullet(GetX, GetY, 5, dir-90-rand(30,-30), 99, 0);
					bullet(GetX, GetY, 5, dir-270-rand(30,-30), 99, 0);
				dir+=45;}
			wait(1);
	dir = GetAngleToPlayer;
		}
	wait(30);
	}
	}
	task fireb{
		let dir = GetAngleToPlayer;
		let hi = 0;
		loop{
		wait(60);
			loop(30){
				loop(64){CreateShot01(GetX, GetY, 50, dir, 96, 0); dir+=5;}
			wait(1); PlaySE(s1);
	dir = GetAngleToPlayer;
		}
	wait(30);
	PlaySE(w1);
		wait(60);
			loop(30){
				loop(64){CreateShot01(GetX, GetY, 50, dir, 96, 0); dir+=5;}
			wait(1); PlaySE(s1);
	dir += hi;
	hi+=0.2;
		}
	wait(30);
	PlaySE(w1);
	}
	}
task bullet(x,y,v,dir,graphic,delay){
	
	 let obj=Obj_Create(OBJ_SHOT);


	Obj_SetPosition(obj,x,y);



	Obj_SetSpeed(obj,v);

	
	Obj_SetAngle(obj,dir);
	 ObjShot_SetGraphic(obj,graphic);


	ObjShot_SetDelay(obj,delay);


	ObjShot_SetBombResist(obj, true);



	while(!Obj_BeDeleted(obj)){
wait(30);
Obj_SetAngle(obj,GetAngleToPlayer);
ObjShot_SetGraphic(obj,97);


PlaySE(w1);
wait(20);
Obj_SetSpeed(obj,3);


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