#TouhouDanmakufu
#ScriptVersion[3]
#Title["Nature Sign \"Water Nymphs\""]

#include".\ZUNShot_Const.txt"
#include".\drawstuff.txt"
#include "script/default_system/Default_Effect.txt"

let ex;
let ey;
let mx;
let my;
let objEnemy;


	@Initialize{
		objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
		ObjEnemy_Regist(objEnemy);
		ObjEnemy_SetDamageRate(objEnemy, 0, 0);
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2,10,2);
		DeleteShotAll(TYPE_ALL, TYPE_ITEM);
		Magiccircle(objEnemy);
		AuraMake;
		EnglandMove;
		mainTask;	
		}

	@MainLoop
	{
		ex = ObjMove_GetX(objEnemy);
		ey = ObjMove_GetY(objEnemy);
		ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//Sets the hitbox against player bullets
		ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 24);//Sets the hitbox against the player
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=0){
			loop(20){CreateItemA1(ITEM_POINT,ex+rand(-50,50),ey+rand(-50,50),GetCommonData("PIValue",10000));}
			Obj_Delete(objEnemy);
			DeleteShotAll(TYPE_ALL, TYPE_ITEM);
			Reset2DCamera();
			CloseScript(GetOwnScriptID());
			}
		yield;
	}

	@Event
	{
		alternative(GetEventType())
		case(EV_REQUEST_LIFE)
		{
			SetScriptResult(420);
		}
		case(EV_REQUEST_TIMER)
		{
			SetScriptResult(80);//Sets the time limit to 60
		}
		case(EV_REQUEST_SPELL_SCORE)
		{
			SetScriptResult(0);//Sets spellcard bonus to 30000 points
		}
	}

task mainTask{
	yield;
	backCall;
	backCall2;
	cutin(GetCurrentScriptDirectory~"cutin.png",0,0,211,325);
	SpellName("Nature Sign \"Elemental Nymphs\"",100,80,120,120,80,100);
	EnglandMove;	
	score(320000000,100,80,120,120,80,100);
	loop(180){yield;}
	FamSpawn;
	loop(240){yield;}
	ObjEnemy_SetDamageRate(objEnemy, 10, 0);
	yield;
	}

task FamSpawn(){
	Fam2(135);
	Fam2(135+90);
	Fam2(135-90);
	Fam2(135+180);
	let n = 0;
	let dir = 0;
	loop{
		while(n<5){
			DelaySE(SShot2,0,0);
			CreateShotA2(ex,ey,1.5,GetAngleToPlayer(objEnemy)+dir,0,0,39,10);
			dir+=360/5;
			n++;
			yield;
		}
		n = 0;
		loop(70){yield;}
	}
}

task backCall{
	let objBgOne = ObjPrim_Create(OBJ_SPRITE_2D);
	background1(objBgOne,GetCurrentScriptDirectory~"bg1.png",0,0,640,640,10000000,255,200,150,150,22,BLEND_ALPHA,-0.3,0,0);
	}
task backCall2{
	let objBgTwo = ObjPrim_Create(OBJ_SPRITE_2D);
	background1(objBgTwo,GetCurrentScriptDirectory~"bg2.png",0,0,960,600,10000000,100,0,0,0,22,BLEND_ALPHA,0,0,1);
	}

task background1(obj,imgbg1,r,t,l,b,time,alpha,R,G,B,prio,render,xmove,ymove,zangle){
let c = 0;
LoadTexture(imgbg1);
ObjPrim_SetTexture(obj,imgbg1);
Obj_SetRenderPriorityI(obj,prio);
ObjSprite2D_SetDestRect(obj,0,0,GetStgFrameWidth,GetStgFrameHeight);
ObjRender_SetBlendType(obj,render);
ObjRender_SetAlpha(obj,alpha);
ObjSprite2D_SetSourceRect(obj,r,t,l,b);
loop(time){
	if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=0){
		Obj_Delete(obj);
		}
	ObjSprite2D_SetSourceRect(obj,r+(c*xmove),t+(c*ymove),l+(c*xmove),b+(c*ymove));
	c++;
	yield;
}
Obj_Delete(obj);
}

task famshoot2(obj){
	let n = 0;
	let dir = 0;
	loop{
		DelaySE(SShot1,0,0);
		while(n<60){
			let water = CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),3.2,dir,-0.05,0,180,60);
			dir+=360/60;
			FadeDelete(water,120);
			n++;
		}
		n = 0;
		loop(60){yield;}
	}
}
task Fam2(i){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	let frame = 0;
	let familiar = GetCurrentScriptDirectory~"stg3enm.png";
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,familiar);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjEnemy_Regist(obj);
	ObjRender_SetColor(obj,0,0,255);
	ObjMove_SetPosition(obj,ex,ey);
	ObjMove_SetAngle(obj,i);
	ObjMove_SetSpeed(obj,2);
	while(!Obj_IsDeleted(obj)){
		ObjEnemy_SetIntersectionCircleToShot(objEnemy,ObjMove_GetX(obj),ObjMove_GetY(obj),32);
		if(frame==120){famshoot2(obj); }
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=0){
			Obj_Delete(obj);
		}
		if(ObjMove_GetX(obj)>GetStgFrameWidth||ObjMove_GetX(obj)<0){
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
		}
		if(ObjMove_GetY(obj)>GetStgFrameHeight||ObjMove_GetY(obj)<0){
			ObjMove_SetAngle(obj,360-ObjMove_GetAngle(obj));
		}
		ObjRender_SetAngleXYZ(obj,0,0,frame);
		ObjSprite2D_SetDestCenter(obj);
		ObjSprite2D_SetSourceRect(obj,2,99,62,159); 
		if(frame<=128){ObjRender_SetAlpha(obj,frame*2);}
		frame++;
		yield;
	}	
}
