#TouhouDanmakufu
#ScriptVersion[3]
#Title["Bonfire Night \"Guy Fawkes\""]

#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;
		Reset2DCamera;
		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);
			CloseScript(GetOwnScriptID());
			}
		yield;
	}

	@Event
	{
		alternative(GetEventType())
		case(EV_REQUEST_LIFE)
		{
			SetScriptResult(340);
		}
		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("Bonfire Night \"Guy Fawkes\"",100,80,120,120,80,100);
	score(260000000,100,80,120,120,80,100);
	EnglandMove;	
	loop(120){yield;}
	BottomFire;
	loop(180){yield;}
	ObjEnemy_SetDamageRate(objEnemy, 10, 0);
	FireShot;
	yield;
	}

task BottomFire(){
	let y = -25;
	let i = 0;
	loop{
		loop(36){
			CreateStraightLaserA1(GetStgFrameWidth/35*i,-10,90,rand(y-25,y+25),20,30,18,0);
			CreateStraightLaserA1(GetStgFrameWidth/35*i,GetStgFrameHeight+10,270,rand(y-25,y+25),20,30,18,0);
			i++;
		}
	if(y<90){y+=3;}
	i = 0;
	loop(15){yield;}
	}
}
task FireShot{
	let dir = 0;
	loop{
		loop(30){
		DelaySE(SShot2,0,0);
		CreateShotB2(dir,GetStgFrameHeight+10,rand(-0.4,0.4),rand(-1,-2),0,0.025,0,-1,197,10);
		CreateShotB2(GetStgFrameWidth-dir,-10,rand(0.4,-0.4),rand(1,2),0,-0.025,0,1,194,10);
		if(dir>=GetStgFrameWidth){dir = 0}
		dir+=GetStgFrameWidth/30;
		loop(5){yield;}
		}
		loop(30){
		DelaySE(SShot2,0,0);
		CreateShotB2(GetStgFrameWidth-dir,GetStgFrameHeight+10,rand(-0.4,0.4),rand(-1,-2),0,0.025,0,-1,197,10);
		CreateShotB2(dir,-10,rand(0.4,-0.4),rand(1,2),0,-0.025,0,1,194,10);
		if(dir>=GetStgFrameWidth){dir = 0}
		dir+=GetStgFrameWidth/30;
		loop(5){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);
}
