#TouhouDanmakufu
#ScriptVersion[3]
#Title["\"Mediterranean Sun\""]

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

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

	@Initialize{
		objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
		objRoma = ObjEnemy_Create(OBJ_ENEMY);
		ObjEnemy_Regist(objEnemy);
		ObjEnemy_Regist(objRoma);
		ObjEnemy_SetDamageRate(objEnemy, 30, 0);
		ObjMove_SetPosition(objRoma,GetCommonData("RomaX",GetStgFrameWidth),GetCommonData("RomaY",0));
		ObjMove_SetDestAtWeight(objEnemy,50,50,10,2);
		ObjMove_SetDestAtWeight(objRoma,GetStgFrameWidth-50,50,10,2);
		DeleteShotAll(TYPE_ALL, TYPE_ITEM);
		SpainMove(objEnemy,GetCurrentScriptDirectory ~ "spain.png");
		SpainMove(objRoma,GetCurrentScriptDirectory ~ "romano.png");
		Magiccircle(objEnemy);
		AuraMakeBoss(objRoma,200,200,50);
		Magiccircle(objRoma);
		AuraMakeBoss(objEnemy,255,100,100);
		mainTask;	
		}

	@MainLoop
	{
		ex = ObjMove_GetX(objEnemy);
		ey = ObjMove_GetY(objEnemy);
		SetCommonData("RomaX",ObjMove_GetX(objRoma));
		SetCommonData("RomaY",ObjMove_GetY(objRoma));
		mx = GetCommonData("RomaX",NULL);
		my = GetCommonData("RomaY",NULL);
		ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//Sets the hitbox against player bullets
		ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 24);//Sets the hitbox against the player
		ObjEnemy_SetIntersectionCircleToShot(objEnemy, mx, my, 32);//Sets the hitbox against player bullets
		ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, mx, my, 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));
						CreateItemA1(ITEM_POINT,mx+rand(-50,50),my+rand(-50,50),GetCommonData("PIValue",10000)); }
			Obj_Delete(objEnemy);
			Obj_Delete(objRoma);
			DeleteShotAll(TYPE_ALL, TYPE_ITEM);
			Reset2DCamera();
			CloseScript(GetOwnScriptID());
			}
		yield;
	}

	@Event
	{
		alternative(GetEventType())
		case(EV_REQUEST_LIFE)
		{
			SetScriptResult(7500);
		}
		case(EV_REQUEST_TIMER)
		{
			SetScriptResult(50);//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~"cutin2.png",0,0,347,347);
	SpellName("\"Mediterranean Sun\"",100,80,120,120,80,100);
	score(1000000000,100,80,120,120,80,100);
	loop(180){yield;}
	ObjEnemy_SetDamageRate(objEnemy, 100, 30);
	DelaySE(SExplode1,0,0);
	Sun(GetCurrentScriptDirectory~"etama7b.png",128,true,255,255,55);
	Sun(GetCurrentScriptDirectory~"etama7a.png",128,false,255,255,105);
	loop(120){yield;}
	SpainShot;
	loop(240){yield;}
	yield;
	}

task SpainShot{
	loop{
		DelaySE(SShot2,0,0);
		CreateShotA2(mx,my,1.5,GetAngleToPlayer(objRoma)+rand(15,-15),0.01,2,186,0);
		CreateShotA2(ex,ey,1.5,GetAngleToPlayer(objEnemy)+rand(-15,15),0.01,2,186,0);
		loop(5){yield;}
	}
}
task move{
	let dir = 0;
	loop{
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2+150*cos(dir),100,10,5);
		ObjMove_SetDestAtWeight(objRoma,GetStgFrameWidth/2+150*cos(dir+180),100,10,5);
		dir+=3;
		yield;
	}
}
task backCall{
	let objBgOne = ObjPrim_Create(OBJ_SPRITE_2D);
	background1(objBgOne,GetCurrentScriptDirectory~"bg3.png",0,0,833,600,10000000,255,200,150,150,22,BLEND_ALPHA,-0.3,0.1,0);
	}
task backCall2{
	let objBgTwo = ObjPrim_Create(OBJ_SPRITE_2D);
	background1(objBgTwo,GetCurrentScriptDirectory~"bg4.png",0,0,640,420,10000000,100,0,0,0,22,BLEND_ALPHA,0,0,0);
	}

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));
	ObjRender_SetAngleXYZ(obj,0,0,c*zangle);
	c++;
	yield;
}
Obj_Delete(obj);
}

task Sun(familiar,scaling,shoot,R,G,B){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	let frame = 0;
	let scale = 0;
	let dir = 0;
	Obj_SetRenderPriorityI(obj,40);
	ObjPrim_SetTexture(obj,familiar);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjEnemy_Regist(obj);
	ObjRender_SetColor(obj,R,G,B);
	ObjMove_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2);
	ObjMove_SetAngle(obj,0);
	ObjRender_SetAlpha(obj,200);
	ObjMove_SetSpeed(obj,0);
	while(!Obj_IsDeleted(obj)){
		ObjEnemy_SetIntersectionCircleToShot(objEnemy, ObjMove_GetX(obj), ObjMove_GetY(obj), 110*scale);
		ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),110*scale);
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=0){
			Obj_Delete(obj);
		}
		if(frame%90==0&&frame>scaling+10&&shoot==true){ DelaySE(SShot1,0,0); loop(15){CreateShotA1(GetStgFrameWidth/2+(128*0.85)*cos(dir),GetStgFrameHeight/2+(128*0.85)*sin(dir),1.5,dir,321,20); dir+=360/15;} }
		ObjRender_SetAngleXYZ(obj,0,0,frame);
		ObjSprite2D_SetDestCenter(obj);
		ObjSprite2D_SetSourceRect(obj,0,0,256,256); 
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		if(scale<1){scale+=0.9/scaling;}
		frame++;
		dir+=rand(1,3);
		yield;
	}	
}
