#TouhouDanmakufu
#ScriptVersion[3]
#Title["\"Independence Day\""]

#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,75,10,3);
		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(7200);
		}
		case(EV_REQUEST_TIMER)
		{
			SetScriptResult(140);//Sets the time limit to 60
		}
		case(EV_REQUEST_SPELL_SCORE)
		{
			SetScriptResult(0);//Sets spellcard bonus to 30000 points
		}
	}

task mainTask{
	loop(60){yield;}
	DelaySE(SCharge2,0,0);
	charge(0,0,0);
	loop(30){yield;}
	DelaySE(SCharge2,0,0);
	charge(0,0,0);
	loop(30){yield;}
	DelaySE(SCharge2,0,0);
	charge(0,0,0);
	loop(30){yield;}
	backCall;
	backCall2;
	cutin(GetCurrentScriptDirectory~"cutin.png",0,0,211,325);
	SpellName("\"Independence Day\"",100,80,120,120,80,100);
	score(600000000,100,80,120,120,80,100);
	EnglandMove;	
	loop(120){yield;}
	Walls;
	Bubbles;
	loop(180){yield;}
	move;
	ObjEnemy_SetDamageRate(objEnemy, 50, 0);
	yield;
	}

task Walls{
	let x = 0;
	let m = 0;
	let n = 0;
	loop{
		DelaySE(SShot1,0,0);
		while(x<GetStgFrameHeight){
			RedShot(x);
			BlueShot(x);
			x+=GetStgFrameHeight/50;
		}
		x = 0;
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=3000&&m==0){
			DelaySE(SCharge2,0,0);
			charge(0,0,0);
			m = 1;
		}
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=4200&&n==0){
			DelaySE(SCharge2,0,0);
			charge(0,0,0);
			aimed;
			n = 1;
		}
		loop(30){yield;}
	}
}
task Bubbles{
	loop{
		CreateShotA1(-30,rand(0,GetStgFrameHeight),0.5,0,324,10);
		CreateShotA1(GetStgFrameWidth+30,rand(0,GetStgFrameHeight),0.5,180,326,10);
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=3000){
		CreateShotA1(-30,rand(0,GetStgFrameHeight),1,0,134,10);
		CreateShotA1(-30,rand(0,GetStgFrameHeight),1,0,134,10);
		CreateShotA1(GetStgFrameWidth+30,rand(0,GetStgFrameHeight),1,180,138,10);
		CreateShotA1(GetStgFrameWidth+30,rand(0,GetStgFrameHeight),0.5,180,326,10);
		}
		loop(30){yield;}
	}
}
task aimed{
	loop{
		DelaySE(SShot2,0,0);
		CreateShotA1(-30,GetPlayerY,2,0,272,10);
		CreateShotA1(GetStgFrameWidth+30,GetPlayerY,2,180,273,10);
		loop(120){yield;}
	}
}
task move{
	let dir = 0;
	loop{
		ObjMove_SetPosition(objEnemy,GetStgFrameWidth/2+((900-(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)/8))/10)*cos(dir),75);
		dir++;
		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 RedShot(y){
	let objAnc = ObjShot_Create(OBJ_SHOT);
	let frame = 0;
	let m = 0;
	let ang = 0;
	ObjMove_SetSpeed(objAnc,2);
	ObjMove_SetPosition(objAnc,-20,y);
	ObjShot_SetGraphic(objAnc,65);
	ObjMove_SetAngle(objAnc,0);
	ObjShot_SetDelay(objAnc,20);
	ObjShot_Regist(objAnc);
	ObjShot_SetAutoDelete(objAnc,false);
	ObjShot_SetSpellResist(objAnc,true);
	while(!Obj_IsDeleted(objAnc)){
		if(ObjMove_GetX(objAnc)>ObjMove_GetX(objEnemy)-90){
			ObjMove_SetSpeed(objAnc,0);
			ObjShot_FadeDelete(objAnc);
			}
		yield;
		}
	}
task BlueShot(y){
	let objAnc = ObjShot_Create(OBJ_SHOT);
	let frame = 0;
	let m = 0;
	let ang = 0;
	ObjMove_SetSpeed(objAnc,2);
	ObjMove_SetPosition(objAnc,GetStgFrameWidth+20,y);
	ObjShot_SetGraphic(objAnc,69);
	ObjMove_SetAngle(objAnc,180);
	ObjShot_SetDelay(objAnc,20);
	ObjShot_Regist(objAnc);
	ObjShot_SetAutoDelete(objAnc,false);
	ObjShot_SetSpellResist(objAnc,true);
	while(!Obj_IsDeleted(objAnc)){
		if(ObjMove_GetX(objAnc)<ObjMove_GetX(objEnemy)+90){
			ObjMove_SetSpeed(objAnc,0);
			ObjShot_FadeDelete(objAnc);
			}
		yield;
		}
	}