#TouhouDanmakufu
#ScriptVersion[3]
#Title["Pirate Sign \"Fire the Harpoon!\""]

#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,GetStgFrameWidth/2,10,2);
		DeleteShotAll(TYPE_ALL, TYPE_ITEM);
		Magiccircle(objEnemy);
		AuraMake;
		EnglandMove;
		mx = 0;
		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());
			}
		mx++;
		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;
	AuraMake;
	cutin(GetCurrentScriptDirectory~"cutin.png",0,0,211,325);
	SpellName("Pirate Sign \"Fire the Harpoon!\"",100,80,120,120,80,100);
	score(275000000,100,80,120,120,80,100);
	EnglandMove;	
	loop(120){yield;}
	Englandshot;
	yield;
	}

task Englandshot(){
	let dir = 0;
	let i = 1;
	charge(ex,ey,90);
		DelaySE(SBoon1,0,7);
		loop(2){
			Anchor(GetStgFrameWidth/3*i,0,i,90,0);
			i++;
		}
	loop(120){yield;}
	ObjEnemy_SetDamageRate(objEnemy, 10, 0);
	charge(ex,ey,60);
	loop{
		i = 1;
		loop(6){
		DelaySE(SBoon1,0,7);
			Anchor(GetStgFrameWidth/7*i,0,i,90,0);
			i++;
		}
		loop(180){yield;}
		i = 1;
		loop(11){
			DelaySE(SBoon1,0,7);
			Anchor(GetStgFrameWidth/12*i,0,i,rand(45,135),rand(0,360));
			loop(20){yield;}
			i++;
		}
		loop(120){yield;}
		i = 1;
		ObjMove_SetDestAtWeight(objEnemy,rand(100,GetStgFrameWidth-100),rand(50,150),10,2);	
	}
}


task Anchor(posx,posy,i,angle,cir){
	let objAnc = ObjShot_Create(OBJ_SHOT);
	let frame = 0;
	let ang = 0;
	ObjMove_SetSpeed(objAnc,0);
	ObjMove_SetPosition(objAnc,posx,posy);
	ObjShot_SetGraphic(objAnc,239);
	ObjMove_SetAngle(objAnc,angle);
	ObjShot_SetSpellResist(objAnc,true);
	ObjShot_Regist(objAnc);
	while(!Obj_IsDeleted(objAnc)){
		if(frame%3==1){bullet(ObjMove_GetX(objAnc),ObjMove_GetY(objAnc),angle-180);}
		if(ObjMove_GetX(objAnc)<0||ObjMove_GetX(objAnc)>GetStgFrameWidth||ObjMove_GetY(objAnc)>GetStgFrameHeight){
			Shake(10);
			DelaySE(SExplode1,0,10);
			loop(18){
				CreateShotA1(ObjMove_GetX(objAnc),ObjMove_GetY(objAnc),1.3,cir,54,10);
				cir+=360/18;
				}
			Obj_Delete(objAnc);
			}
		ObjMove_SetSpeed(objAnc,ObjMove_GetSpeed(objAnc)+0.06);
		frame++;
		ang+=6;
		yield;
	}
}
task bullet(posix,posiy,dir){
	let obj = ObjShot_Create(OBJ_SHOT);
	let wait = 0;
	ObjMove_SetSpeed(obj,0);
	ObjMove_SetPosition(obj,posix,posiy);
	ObjShot_SetGraphic(obj,220);
	ObjMove_SetAngle(obj,dir);
	ObjShot_SetSpellResist(obj,true);
	ObjShot_Regist(obj);
	loop(30){yield;}
	while(!Obj_IsDeleted(obj)){
		while(wait<60){ObjMove_SetSpeed(obj,wait/60*1); wait++ }
		wait++;
		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);
}
