#TouhouDanmakufu
#ScriptVersion[3]
#Title["Beverage \"Milk Tea\""]

#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);
		EnglandMove;
		AuraMake;
		Magiccircle(objEnemy);
		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("Beverage \"Milk Tea\"",100,80,120,120,80,100);
	score(600000000,100,80,120,120,80,100);
	EnglandMove;	
	loop(120){yield;}
	Tea(0);
	Tea(120);
	Tea(240);
	loop(180){yield;}
	ObjEnemy_SetDamageRate(objEnemy, 10, 0);
	yield;
	}

task Tea(dir){
	let frame = 0;
	let b = 0;
	let v = 0;
	loop(10){
		loop(3){
			DelaySE(SShot1,0,0);
			Ingredient(GetStgFrameWidth/2-100,GetStgFrameHeight/2,dir,v,-0.65,b,71);
			Ingredient(GetStgFrameWidth/2+100,GetStgFrameHeight/2,-dir,v,0.65,b,63);
			Ingredient(GetStgFrameWidth/2,GetStgFrameHeight/2-100,dir,v,0.45,b,77);
			Ingredient(GetStgFrameWidth/2,GetStgFrameHeight/2-100,dir-180,v,-0.45,b,77);
			b+=11;
		}
		yield;
		dir+=101;
		frame++;
	}
}

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 Ingredient(x,y,angle,accel,veloc,b,graphic){
	let objAnc = ObjShot_Create(OBJ_SHOT);
	let frame = 0;
	let m = 0;
	let ang = 0;
	ObjMove_SetSpeed(objAnc,4);
	ObjMove_SetPosition(objAnc,x,y);
	ObjShot_SetGraphic(objAnc,graphic);
	ObjMove_SetAngle(objAnc,90);
	ObjShot_SetDelay(objAnc,120);
	ObjShot_Regist(objAnc);
	ObjShot_SetAutoDelete(objAnc,false);
	ObjShot_SetSpellResist(objAnc,true);
	while(!Obj_IsDeleted(objAnc)){
		ObjMove_SetPosition(objAnc,x+b*cos(angle),y+b*sin(angle));
		b+=accel;
		angle+=veloc;
		frame++;
		yield;
		}
	}