#include "./MS_ShotFunctions.txt"
#include "./MS_DefaultFunctions.txt"
SetCommonData("CameraHeight", 0);
task WorldBG{
	SetCameraFocusX(0);
	SetCameraFocusY(-100);
	SetCameraFocusZ(500);
	SetCameraRadius(250);
	SetCameraElevationAngle(15);
	SetCameraAzimuthAngle(90);
	SetFogParam(1950, 2300, 0, 0, 0);
	SetCameraPerspectiveClip(10, 2400);

	let ground = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(ground, 22);
	ObjPrim_SetTexture(ground, GetCurrentScriptDirectory ~ "/img/Ingame/water.png");
	ObjRender_SetBlendType(ground, BLEND_ADD_ARGB);
	ObjRender_SetAlpha(ground, 125);
	ObjSprite3D_SetSourceRect(ground, 0, 0, 2048, 4096);
	ObjSprite3D_SetDestRect(ground, -1024, -2048, 1024, 2048);
	ObjRender_SetPosition(ground, 0, 0, 0);
	ObjRender_SetAngleX(ground, 90);
	
	let ground2 = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(ground2, 22);
	ObjPrim_SetTexture(ground2, GetCurrentScriptDirectory ~ "/img/Ingame/sand.png");
	ObjRender_SetAlpha(ground2, 122);
	ObjSprite3D_SetSourceRect(ground2, 0, 0, 4096, 4096);
	ObjSprite3D_SetDestRect(ground2, -2048, -2048, 2048, 2048);
	ObjRender_SetPosition(ground2, 200, -200, 0);
	ObjRender_SetAngleX(ground2, 90);
	
	let water = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(water, 25);
	ObjPrim_SetTexture(water, GetCurrentScriptDirectory ~ "/img/Ingame/color.png");
	ObjSprite2D_SetSourceRect(water,0,0,512,512);
	ObjSprite2D_SetDestCenter(water);
	ObjRender_SetPosition(water,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(water, 255);
	ObjRender_SetColor(water, 5, 5, 255);
	ObjRender_SetBlendType(water, BLEND_MULTIPLY);
	
	let wave = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(wave, 25);
	ObjPrim_SetTexture(wave, GetCurrentScriptDirectory ~ "/img/Ingame/wave.png");
	ObjSprite2D_SetSourceRect(wave,0,0,512,512);
	ObjSprite2D_SetDestCenter(wave);
	ObjRender_SetPosition(wave,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(wave, 70);
	ObjRender_SetColor(wave, 122, 122, 255);
	ObjRender_SetBlendType(wave, BLEND_ADD_ARGB);

	let sky = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(sky, 21);
	ObjPrim_SetTexture(sky, GetCurrentScriptDirectory ~ "/img/Ingame/sky.png");
	ObjSprite3D_SetSourceRect(sky, 0, 0, 256, 418);
	ObjSprite3D_SetDestRect(sky, -512, -128, 512, 128);
	ObjRender_SetPosition(sky, 0, 300, -800);
	ObjRender_SetFogEnable(sky, false);
	ObjRender_SetAngleX(sky, 180);
	ObjRender_SetScaleXYZ(sky, 2, 2, 0);

	let clouds = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(clouds, 22);
	ObjPrim_SetTexture(clouds, GetCurrentScriptDirectory ~ "/img/Ingame/cloud.png");
	ObjSprite3D_SetSourceRect(clouds, 0, 0, 1024, 256);
	ObjSprite3D_SetDestRect(clouds, -512, -128, 512, 128);
	ObjRender_SetPosition(clouds, 0, 450, -500);
	ObjRender_SetFogEnable(clouds, false);
	ObjRender_SetColor(clouds, 5, 5, 5);
	ObjRender_SetAngleX(clouds, 180);
	ObjRender_SetScaleXYZ(clouds, 1.5, 1.5, 0);

	let clouds2 = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(clouds2, 22);
	ObjPrim_SetTexture(clouds2, GetCurrentScriptDirectory ~ "/img/Ingame/cloud.png");
	ObjSprite3D_SetSourceRect(clouds2, 0, 0, 1024, 256);
	ObjSprite3D_SetDestRect(clouds2, -512, -128, 512, 128);
	ObjRender_SetPosition(clouds2, 0, 350, -400);
	ObjRender_SetColor(clouds2, 5, 5, 5);
	ObjRender_SetFogEnable(clouds2, false);
	ObjRender_SetAngleX(clouds2, 180);
	ObjRender_SetScaleXYZ(clouds2, 2, 2, 0);

	let pos = 0;
	let cameraY = 100;
	let sinn = 150;
	while(GetCommonData("SeasonEnd", 0) == 0){
		ObjSprite3D_SetSourceRect(ground, 0, -pos, 2048, 4096 - pos);
		ObjSprite3D_SetDestRect(ground, -1024, -2048, 1024, 2048);
		
		ObjSprite3D_SetSourceRect(ground2, 0, -pos, 2048, 4096 - pos);
		ObjSprite3D_SetDestRect(ground2, -1024, -2048, 1024, 2048);

		ObjSprite3D_SetSourceRect(clouds, -pos*0.125, 0, 1024 - pos*0.125, 256);
		ObjSprite3D_SetDestRect(clouds, -512, -128, 512, 128);

		ObjSprite3D_SetSourceRect(clouds2, -pos*0.15 + 256, 0, 1024 - pos*0.15 + 256, 256);
		ObjSprite3D_SetDestRect(clouds2, -512, -128, 512, 128);
		
		ObjSprite2D_SetSourceRect(wave,0-pos/12,0,512-pos/12,512);
		
		SetCameraFocusY(cameraY);
		
		ObjRender_SetColor(water, 159-GetCommonData("Stacks",0)/2, 150-GetCommonData("Stacks",0)/2, 255);
		
		cameraY = 50+150*cos(GetCommonData("CameraHeight", 0));
		
		if(cameraY <= -60){
		Obj_SetVisible(water, true);
		Obj_SetVisible(wave, true);
		SetCommonData("Underwater", true);
		}
		else{
		Obj_SetVisible(water, false);
		Obj_SetVisible(wave, false);
		SetCommonData("Underwater", false);
		}
		
		pos += 2;
		yield;
	}
	Obj_Delete(ground);
	Obj_Delete(clouds);
	Obj_Delete(clouds2);
	Obj_Delete(sky);
}

task Spell1(color){
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/apples.jpg");
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	ObjRender_SetColor(obj, color[0], color[1], color[2]);
	loop{
	ObjRender_SetAlpha(obj, count*2);
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task Spell1Rainbow{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/apples.jpg");
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	ObjRender_SetColorHSV(obj, count, 255, 255);
	ObjRender_SetAlpha(obj, count*2);
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task Spell2{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,23);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bg2.png");
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 0);
	loop{
	ObjSprite2D_SetSourceRect(obj, 0+(count/2)*cos(count/6), 0-(count/2)*sin(count/6), 512+(count/2)*cos(count/6), 512-(count/2)*sin(count/6));
	if(count < 50){ObjRender_SetAlpha(obj, count);}
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task Spell3{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,23);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bg1.png");
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 0);
	loop{
	ObjSprite2D_SetSourceRect(obj, 0, 0-count/2, 512, 512-count/2);
	if(count < 122){ObjRender_SetAlpha(obj, count*2);}
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task Bubbles{
loop{
BubbleSmallBG(GetCenterX+rand(-200, 200), GetStageDown);
wait(5);
}
}

task BubbleSmallBG(x, y){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(obj);
	ObjRender_SetPosition(obj,x,y,0);
	ObjMove_AddPatternA2(obj, 0, rand(0.2, 1), rand(270-15, 270+15), 0.01, 0, 2);
	Render(obj);

		task Render(obj){
				
			ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/bubblesmall.png");
			Obj_SetRenderPriorityI(obj, 22);
			ObjSprite2D_SetSourceRect(obj,0,0,256,256);
			ObjRender_SetScaleXYZ(obj, 0.05, 0.05, 1);
			ObjRender_SetAlpha(obj, 50);
			ObjSprite2D_SetDestCenter(obj);	
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			wait(60*5);
			Obj_Delete(obj);
		}
	}
