#TouhouDanmakufu
#ScriptVersion[3]
#Title["Rain Sign \"Yesterday it Rained\""]

#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;
		Magiccircle(objEnemy);
		AuraMake;
		Reset2DCamera;
		mainTask;	
		}

	@MainLoop
	{
		ex = ObjMove_GetX(objEnemy);
		ey = ObjMove_GetY(objEnemy);
		ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 0);//Sets the hitbox against player bullets
		ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 0);//Sets the hitbox against the player
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=0){
			loop(10){	CreateItemA1(ITEM_POINT,ex+rand(-50,50),ey+rand(-50,50),GetCommonData("PIValue",10000)); }
			CreateItemA1(ITEM_1UP,ex,ey,200000);
			Obj_Delete(objEnemy);
			DeleteShotAll(TYPE_ALL, TYPE_ITEM);
			CloseScript(GetOwnScriptID());
			}
		yield;
	}

	@Event
	{
		alternative(GetEventType())
		case(EV_REQUEST_LIFE)
		{
			SetScriptResult(1);
		}
		case(EV_REQUEST_TIMER)
		{
			SetScriptResult(70);//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("Rain Sign \"Yesterday it Rained\"",100,80,120,120,80,100);
	score(600000000,100,80,120,120,80,100);
	EnglandMove;	
	loop(120){yield;}
	Autumn;
	yield;
	}
task Autumn{
	charge(ex,ey,60);
	DelaySE(SCharge2,0,10);
	SubSpellName("Rain Sign \"Autumnal Fall\"",255,0,0,255,100,0,16*60);
	loop(60){yield;}
	let dir = 0;
	loop(15*20){
		DelaySE(SShot2,0,0);
		CreateShotA1(rand(0,GetStgFrameWidth),0,rand(0.5,2),rand(95,85),84,20);
		loop(3){yield;}
	}
	Winter;
}
task Winter{
	charge(ex,ey,60);
	DelaySE(SCharge2,0,10);
	SubSpellName("Rain Sign \"Christmas Snow\"",255,255,255,100,100,255,16*60);
	loop(60){yield;}
	let dir = 0;
	loop(15*30){
		DelaySE(SShot2,0,0);
		CreateShotA1(rand(0,GetStgFrameWidth),0,rand(0.5,2),rand(110,70),185,20);
		loop(2){yield;}
	}
	Spring;
}
task Spring{
	charge(ex,ey,60);
	DelaySE(SCharge2,0,10);
	SubSpellName("Rain Sign \"April Shower\"",50,200,50,100,200,100,16*60);
	loop(60){yield;}
	let dir = 0;
	loop(15*20){
		DelaySE(SShot2,0,0);
		CreateShotA1(rand(-100,GetStgFrameWidth),0,rand(1.5,3.2),rand(100,45),86,20);
		CreateShotA1(rand(-100,GetStgFrameWidth),0,rand(1.5,3.2),rand(100,45),86,20);
		loop(3){yield;}
	}
	Summer;
}
task Summer{
	charge(ex,ey,60);
	DelaySE(SCharge2,0,10);
	SubSpellName("Rain Sign \"Summer Storm\"",200,200,50,200,174,100,16*60);
	loop(60){yield;}
	let dir = 0;
	lightning;
	loop{
		DelaySE(SShot2,0,0);
		CreateShotA1(0,rand(0,GetStgFrameHeight),rand(1.5,2),rand(-15,45),219,20);
		loop(3){yield;}
	}
}
task lightning{
	loop{
		let v = rand(4,6);
		let x = GetPlayerX;
		loop(35){Light(x,0,v); yield;}
	}
}

task Light(x,y,v){
	let objAnc = ObjShot_Create(OBJ_SHOT);
	let frame = 0;
	let m = 0;
	let ang = 0;
	ObjMove_SetSpeed(objAnc,v);
	ObjMove_SetPosition(objAnc,x,y);
	ObjShot_SetGraphic(objAnc,91);
	ObjMove_SetAngle(objAnc,45);
	ObjShot_SetDelay(objAnc,20);
	ObjShot_Regist(objAnc);
	while(!Obj_IsDeleted(objAnc)){
		if(frame%60==0){	ObjMove_SetAngle(objAnc,135); 		ObjMove_SetSpeed(objAnc,v);}
		if(frame%60==30){	ObjMove_SetAngle(objAnc,45);		ObjMove_SetSpeed(objAnc,v); }
		ObjMove_SetSpeed(objAnc,ObjMove_GetSpeed(objAnc)-(v/30));
		yield;
		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);
}
