#TouhouDanmakufu
#ScriptVersion[3]
#Title["Remembrance \"Silent Field Clad in Poppy Red\""]

#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-150,75,10,2);
		DeleteShotAll(TYPE_ALL, TYPE_ITEM);
		EnglandMove;
		Magiccircle(objEnemy);
		AuraMake;
		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(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("Remembrance \"Silent Field Clad in Poppy Red\"",100,80,120,120,80,100);
	score(270000000,100,80,120,120,80,100);
	EnglandMove;	
	loop(120){yield;}
	Englandshot;
	yield;
	}

task Englandshot(){
	let dir = 0;
	let i = 1;
	charge(ex,ey,90);
	ObjEnemy_SetDamageRate(objEnemy, 10, 0);
	loop{
		Poppy(ex,0,90);
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2-50,75,10,2);
		loop(90){yield;}
		Poppy(ex,0,90);
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2+50,75,10,2);
		loop(90){yield;}
		Poppy(ex,0,90);
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2+150,75,10,2);
		loop(90){yield;}
		Poppy(ex,0,90);
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2-150,75,10,2);
		loop(300){yield;}
}
}


task Poppy(posx,posy,angle){
	let objAnc = ObjShot_Create(OBJ_SHOT);
	let frame = floor(rand(0,60));
	let ang = rand(0,360);
	ObjMove_SetSpeed(objAnc,0);
	ObjMove_SetPosition(objAnc,posx,posy);
	ObjShot_SetGraphic(objAnc,87);
	ObjMove_SetAngle(objAnc,angle);
	ObjShot_SetSpellResist(objAnc,true);
	ObjShot_SetDelay(objAnc,10);
	ObjShot_Regist(objAnc);
	while(!Obj_IsDeleted(objAnc)){
		ObjMove_SetPosition(objAnc,posx+(sin(ang)*20),ObjMove_GetY(objAnc)+1.4);
		if(frame%6==1){ bullet(ObjMove_GetX(objAnc),ObjMove_GetY(objAnc),ang-180);}
		if(frame%70==0){DelaySE(SShot1,0,0); PoppyGrow(ObjMove_GetX(objAnc),ObjMove_GetY(objAnc)); }
		frame++;
		ang+=6;
		yield;
	}
}
task bullet(posix,posiy,dir){
	let obj = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetSpeed(obj,0);
	ObjMove_SetPosition(obj,posix,posiy);
	ObjShot_SetGraphic(obj,87);
	ObjMove_SetAngle(obj,dir);
	ObjShot_SetSpellResist(obj,true);
	ObjShot_Regist(obj);
	loop(120){yield;}
		ObjMove_SetSpeed(obj,0.7);
}
task PoppyGrow(x,y){
	let toplayer = atan2(y-GetPlayerY,x-GetPlayerX);
	let middle = CreateShotA1(x,y,0,0,63,10);
	let petal1 = CreateShotA1(x+cos(toplayer)*10,y+sin(toplayer)*10,0,toplayer,79,10);
	let petal2 = CreateShotA1(x+cos(toplayer+90)*10,y+sin(toplayer+90)*10,0,toplayer+90,79,10);
	let petal3 = CreateShotA1(x+cos(toplayer+180)*10,y+sin(toplayer+180)*10,0,toplayer+180,79,10);
	let petal4 = CreateShotA1(x+cos(toplayer-90)*10,y+sin(toplayer-90)*10,0,toplayer-90,79,10);
	let petal5 = CreateShotA1(x+cos(toplayer+45)*10,y+sin(toplayer+45)*10,0,toplayer+45,79,10);
	let petal6 = CreateShotA1(x+cos(toplayer+135)*10,y+sin(toplayer+135)*10,0,toplayer+135,79,10);
	let petal7 = CreateShotA1(x+cos(toplayer-135)*10,y+sin(toplayer-135)*10,0,toplayer-135,79,10);
	let petal8 = CreateShotA1(x+cos(toplayer-45)*10,y+sin(toplayer-45)*10,0,toplayer-45,79,10);
	loop(120){yield;}
	Obj_Delete(middle);
	ObjMove_SetSpeed(petal1,1);
	ObjMove_SetSpeed(petal2,1);
	ObjMove_SetSpeed(petal3,1);
	ObjMove_SetSpeed(petal4,1);
	ObjMove_SetSpeed(petal5,1);
	ObjMove_SetSpeed(petal6,1);
	ObjMove_SetSpeed(petal7,1);
	ObjMove_SetSpeed(petal8,1);
}
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);
}
