script_enemy_main
{
	let imgRitual1 = GetCurrentScriptDirectory ~ "img/ritual/cloud.png";
	let imgRitual2 = GetCurrentScriptDirectory ~ "img/ritual/tablet.png";
	let imgRitual3 = GetCurrentScriptDirectory ~ "img/ritual/back.png";
	let imgRitual4 = GetCurrentScriptDirectory ~ "img/ritual/wings.png";
	let imgRitual5a = GetCurrentScriptDirectory ~ "img/ritual/flowerR.png";
	let imgRitual5b = GetCurrentScriptDirectory ~ "img/ritual/flowerY.png";
	let imgGlow = GetCurrentScriptDirectory ~ "img/ritual/glow.png";
	
	let frame = 0;
	
	//Cloud global variables
	let ID;
	let speed = 0;
	let angle = 0;
	
	//Tablet global variables
	let obj1;
	let speed1 = 0;
	
	//Back global variables
	let obj2;
	let speed2 = 0;
	let angle2 = 180;
	
	//Wing global variables
	let obj3;
	let speed3 = 0;
	
	//Red flower global variables
	let obj4a;
	let obj4b;
	let speed4 = 0;
	
	//Yellow flower global variables
	let obj5a;
	let obj5b;
	
	//Glow
	let obj6;
	let speed5 = 0;
	let alpha = 255;
	
	let move = 90;
	
	@Initialize
	{
		LoadGraphic(imgRitual1);
		LoadGraphic(imgRitual2);
		LoadGraphic(imgRitual3);
		LoadGraphic(imgRitual4);
		LoadGraphic(imgRitual5a);
		LoadGraphic(imgRitual5b);
		LoadGraphic(imgGlow);
		
		SetLife(1);
		SetTimer(94);
		MagicCircle(false);
		
		SetMovePosition02(GetCenterX, GetCenterY - 60, 0);
	}

	@MainLoop
	{
		//FLOODGATES DO NOT ENTER
		//DROWNING HAZARD
		
		frame++; //Don't fuck with this
		
		//Tablet controls
		if(frame > 0 && speed1 < 1)
		{speed1 += 0.1;}
		
		//Cloud controls
		angle += 2;
		if(frame > 30 && speed < 1)
		{
			if(speed < 0.25){speed += 0.005;}
			else{speed += 0.1;}
		}
		
		//Back controls
		if(frame == 130){speed2 = 0.05;}
		if(frame > 135 && speed2 < 1){speed2 += 0.035;}
		if(frame > 135 && angle2 < 360){angle2 += 6;}
		
		//Wing controls
		if(frame > 212 && speed3 < 1)
		{
			if(speed3 < 0.25){speed3 += 0.01;}
			else{speed3 += 0.1;}
		}
		
		//Flower controls
		if(frame > 300 && speed4 < 1){speed4 += 0.03;}
		
		//You spin me right round baby right round
		if(frame == 360){laserspin1;}
		if(frame == 440){laserspin2;}
		if(frame == 510){laserspin3;}
		if(frame == 590){laserspin4;}
		
		//pew pew
		if(frame == 700 || frame == 770 || frame == 815 || frame == 860 || frame == 895 || frame == 930 || frame == 975){tabletburst;}
		if(frame == 1034){tabletrhythm;}
		
		//Keine time
		if(frame == 2340){lasercover1;}
		
		//Let's get movin
		if(frame > 1034 && frame < 3500)
		{
			SetMovePosition02(GetCenterX + (30*cos(move)), GetCenterY-90 + (30*sin(move)), 0);
			move++;
		}
		
		//And now we come to a rest~
		if(frame == 3500){SetMovePosition02(GetCenterX, GetCenterY, 100);}
		
		//The lifestreaaaammmmm
		if(frame == 3610){lifestream;}
		
		//POWER UP
		if(frame == 4300){absorbtion;}
		
		//When you see the flash, DUCK. AND COVER!
		if(frame > 4960 && speed <= 500){speed5 += 10;}
		if(frame == 5000)
		{
			Obj_Delete(ID);
			Obj_Delete(obj1);
			Obj_Delete(obj2);
			Obj_Delete(obj3);
			Obj_Delete(obj4a);
			Obj_Delete(obj4b);
			Obj_Delete(obj5a);
			Obj_Delete(obj5b);
		}
		if(frame > 5000 && alpha > 0){alpha -=0.5;}

		yield; //I yield only to awesomeness~
	}

	@DrawLoop
	{
		if(frame == 1)
		{
			//Tablet
			obj1 = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj1, 2);
			ObjEffect_SetTexture(obj1, imgRitual2);
			ObjEffect_SetPrimitiveType(obj1, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj1, 4);
			ObjEffect_SetVertexUV(obj1, 0, 0, 0);
			ObjEffect_SetVertexUV(obj1, 1, 147, 0);
			ObjEffect_SetVertexUV(obj1, 2, 147, 179);
			ObjEffect_SetVertexUV(obj1, 3, 0, 179);
			ObjEffect_SetScale(obj1, 0.5, 0.5);
			
			//Cloud thing
			ID = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(ID, 1);
			ObjEffect_SetTexture(ID, imgRitual1);
			ObjEffect_SetPrimitiveType(ID, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(ID, 4);
			ObjEffect_SetVertexUV(ID, 0, 0, 0);
			ObjEffect_SetVertexUV(ID, 1, 255, 0);
			ObjEffect_SetVertexUV(ID, 2, 255, 255);
			ObjEffect_SetVertexUV(ID, 3, 0, 255);
			
			//Byakuren wings
			obj3 = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj3, 1);
			ObjEffect_SetTexture(obj3, imgRitual4);
			ObjEffect_SetPrimitiveType(obj3, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj3, 4);
			ObjEffect_SetVertexUV(obj3, 0, 0, 0);
			ObjEffect_SetVertexUV(obj3, 1, 388, 0);
			ObjEffect_SetVertexUV(obj3, 2, 388, 224);
			ObjEffect_SetVertexUV(obj3, 3, 0, 224);
			
			//Byakuren back thing
			obj2 = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj2, 1);
			ObjEffect_SetTexture(obj2, imgRitual3);
			ObjEffect_SetPrimitiveType(obj2, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj2, 4);
			ObjEffect_SetVertexUV(obj2, 0, 0, 0);
			ObjEffect_SetVertexUV(obj2, 1, 255, 0);
			ObjEffect_SetVertexUV(obj2, 2, 255, 255);
			ObjEffect_SetVertexUV(obj2, 3, 0, 255);
			
			//Byakuren red flowers
			obj4a = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj4a, 1);
			ObjEffect_SetTexture(obj4a, imgRitual5a);
			ObjEffect_SetPrimitiveType(obj4a, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj4a, 4);
			ObjEffect_SetVertexUV(obj4a, 0, 0, 0);
			ObjEffect_SetVertexUV(obj4a, 1, 69, 0);
			ObjEffect_SetVertexUV(obj4a, 2, 69, 76);
			ObjEffect_SetVertexUV(obj4a, 3, 0, 76);
			
			obj4b = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj4b, 1);
			ObjEffect_SetTexture(obj4b, imgRitual5a);
			ObjEffect_SetPrimitiveType(obj4b, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj4b, 4);
			ObjEffect_SetVertexUV(obj4b, 0, 0, 0);
			ObjEffect_SetVertexUV(obj4b, 1, 69, 0);
			ObjEffect_SetVertexUV(obj4b, 2, 69, 76);
			ObjEffect_SetVertexUV(obj4b, 3, 0, 76);
			
			//Byakuren yellow flowers
			obj5a = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj5a, 1);
			ObjEffect_SetTexture(obj5a, imgRitual5b);
			ObjEffect_SetPrimitiveType(obj5a, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj5a, 4);
			ObjEffect_SetVertexUV(obj5a, 0, 0, 0);
			ObjEffect_SetVertexUV(obj5a, 1, 69, 0);
			ObjEffect_SetVertexUV(obj5a, 2, 69, 76);
			ObjEffect_SetVertexUV(obj5a, 3, 0, 76);
			
			obj5b = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj5b, 1);
			ObjEffect_SetTexture(obj5b, imgRitual5b);
			ObjEffect_SetPrimitiveType(obj5b, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj5b, 4);
			ObjEffect_SetVertexUV(obj5b, 0, 0, 0);
			ObjEffect_SetVertexUV(obj5b, 1, 69, 0);
			ObjEffect_SetVertexUV(obj5b, 2, 69, 76);
			ObjEffect_SetVertexUV(obj5b, 3, 0, 76);
			
			//Glow
			obj6 = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj6, 5);
			ObjEffect_SetTexture(obj6, imgGlow);
			ObjEffect_SetPrimitiveType(obj6, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj6, 4);
			ObjEffect_SetVertexUV(obj6, 0, 0, 0);
			ObjEffect_SetVertexUV(obj6, 1, 3, 0);
			ObjEffect_SetVertexUV(obj6, 2, 3, 3);
			ObjEffect_SetVertexUV(obj6, 3, 0, 3);
		}
		
		//Object controls
		//Authorized personel only
		if(frame > 1)
		{
			//Tablet
			Obj_SetX(obj1, GetX);
			Obj_SetY(obj1, GetY+(8*sin(frame)));
			ObjEffect_SetVertexXY(obj1, 0, -147/2*speed1, -179/2*speed1);
			ObjEffect_SetVertexXY(obj1, 1, 147/2*speed1, -179/2*speed1);
			ObjEffect_SetVertexXY(obj1, 2, 147/2*speed1, 179/2*speed1);
			ObjEffect_SetVertexXY(obj1, 3, -147/2*speed1, 179/2*speed1);
			
			//Cloud thing
			Obj_SetX(ID, GetX);
			Obj_SetY(ID, GetY+(1*sin(frame)));
			ObjEffect_SetVertexXY(ID, 0, -255/2*speed, -255/2*speed);
			ObjEffect_SetVertexXY(ID, 1, 255/2*speed, -255/2*speed);
			ObjEffect_SetVertexXY(ID, 2, 255/2*speed, 255/2*speed);
			ObjEffect_SetVertexXY(ID, 3, -255/2*speed, 255/2*speed);
			if(speed > 0.25){ObjEffect_SetAngle(ID, 0, 0, angle);}
			
			//Byakuren back thing
			Obj_SetX(obj2, GetX);
			Obj_SetY(obj2, GetY+(5*sin(frame)));
			ObjEffect_SetVertexXY(obj2, 0, -255/2*speed2, -255/2*speed2);
			ObjEffect_SetVertexXY(obj2, 1, 255/2*speed2, -255/2*speed2);
			ObjEffect_SetVertexXY(obj2, 2, 255/2*speed2, 255/2*speed2);
			ObjEffect_SetVertexXY(obj2, 3, -255/2*speed2, 255/2*speed2);
			ObjEffect_SetAngle(obj2, 0, 0, angle2);
			
			//Byakuren wings.
			Obj_SetX(obj3, GetX+2);
			Obj_SetY(obj3, GetY+(3*sin(frame)));
			ObjEffect_SetVertexXY(obj3, 0, -388/2*speed3, -224/2);
			ObjEffect_SetVertexXY(obj3, 1, 388/2*speed3, -224/2);
			ObjEffect_SetVertexXY(obj3, 2, 388/2*speed3, 224/2);
			ObjEffect_SetVertexXY(obj3, 3, -388/2*speed3, 224/2);
			
			//Red flowers
			Obj_SetX(obj4a, GetX-70);
			Obj_SetY(obj4a, GetY-75+(2*sin(frame)));
			ObjEffect_SetVertexXY(obj4a, 0, -69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj4a, 1, 69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj4a, 2, 69/2*speed4, 76/2*speed4);
			ObjEffect_SetVertexXY(obj4a, 3, -69/2*speed4, 76/2*speed4);
			Obj_SetX(obj4b, GetX+70);
			Obj_SetY(obj4b, GetY-75+(2*sin(frame)));
			ObjEffect_SetVertexXY(obj4b, 0, -69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj4b, 1, 69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj4b, 2, 69/2*speed4, 76/2*speed4);
			ObjEffect_SetVertexXY(obj4b, 3, -69/2*speed4, 76/2*speed4);
			
			//Yellow flowers
			Obj_SetX(obj5a, GetX-120);
			Obj_SetY(obj5a, GetY+50+(2*sin(frame)));
			ObjEffect_SetVertexXY(obj5a, 0, -69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj5a, 1, 69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj5a, 2, 69/2*speed4, 76/2*speed4);
			ObjEffect_SetVertexXY(obj5a, 3, -69/2*speed4, 76/2*speed4);
			Obj_SetX(obj5b, GetX+120);
			Obj_SetY(obj5b, GetY+50+(2*sin(frame)));
			ObjEffect_SetVertexXY(obj5b, 0, -69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj5b, 1, 69/2*speed4, -76/2*speed4);
			ObjEffect_SetVertexXY(obj5b, 2, 69/2*speed4, 76/2*speed4);
			ObjEffect_SetVertexXY(obj5b, 3, -69/2*speed4, 76/2*speed4);
			
			//Glow
			Obj_SetX(obj6, GetX);
			Obj_SetY(obj6, GetY);
			ObjEffect_SetVertexXY(obj6, 0, -2*speed5, -2*speed5);
			ObjEffect_SetVertexXY(obj6, 1, 2*speed5, -2*speed5);
			ObjEffect_SetVertexXY(obj6, 2, 2*speed5, 2*speed5);
			ObjEffect_SetVertexXY(obj6, 3, -2*speed5, 2*speed5);
			ObjEffect_SetVertexColor(obj6, 0, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj6, 1, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj6, 2, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj6, 3, alpha, 255, 255, 255);
			
		}
	}

	@Finalize
	{
		DeleteGraphic(imgRitual1);
		DeleteGraphic(imgRitual2);
		DeleteGraphic(imgRitual3);
		DeleteGraphic(imgRitual4);
		DeleteGraphic(imgRitual5a);
		DeleteGraphic(imgRitual5b);
		DeleteGraphic(imgGlow);
	}
	
	function Wait(frames) //Everyone needs this badboy
	{
		loop(frames){yield;}
	}
	
	task laserspin1
	{
		let r = rand(0, 12);
		ascent(i in 0..50)
		{
			CreateLaser01(GetX-70, GetY-75, 3, 360/50*i+r, 100, 9, RED01, 10);
			Wait(3);
		}
		if(frame<3300){laserspin1;}
	}
	
	task laserspin2
	{
		let r = rand(0, 12);
		ascent(i in 0..50)
		{
			CreateLaser01(GetX+70, GetY-75, 3, 360/50*i+r, 100, 9, RED01, 10);
			Wait(3);
		}
		if(frame<3400){laserspin2;}
	}
	
	task laserspin3
	{
		let r = rand(0, 12);
		ascent(i in 0..50)
		{
			CreateLaser01(GetX-120, GetY+50, 3, 360/50*i+r, 100, 9, YELLOW01, 10);
			Wait(3);
		}
		if(frame<3350){laserspin3;}
	}
	
	task laserspin4
	{
		let r = rand(0, 12);
		ascent(i in 0..50)
		{
			CreateLaser01(GetX+120, GetY+50, 3, 360/50*i+r, 100, 9, YELLOW01, 10);
			Wait(3);
		}
		if(frame<3400){laserspin4;}
	}
	
	task tabletburst
	{
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer+40, 69, 11, WHITE21, 5);
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer+20, 69, 11, WHITE21, 5);
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer, 69, 11, WHITE21, 5);
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer-20, 69, 11, WHITE21, 5);
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer-40, 69, 11, WHITE21, 5);
	}
	
	task tabletrhythm
	{
		tabletburst;
		Wait(30);
		tabletburst;
		Wait(30);
		tabletburst;
		Wait(30);
		tabletburst;
		Wait(30);
		tabletburst;
		Wait(21);
		tabletburst;
		Wait(21);
		if(frame<3400){tabletrhythm;}
	}
	
	task lasercover1
	{
		let r = rand(0, 30);
		let curX = GetX;
		let curY = GetY;
		if(frame > 3000){
			ascent(i in 0..20)
			{
				CreateLaserA(0, curX, curY, 500, 10, BLUE01, 60-5*i);
				SetLaserDataA(0, 0, 360/20*i+r, 0, 0, 0, 0);
				SetShotKillTime(0, 115);
				FireShot(0);
				Wait(3);
			}
			ascent(i in 0..20)
			{
				CreateLaserA(0, curX, curY, 500, 10, PURPLE01, 60-5*i);
				SetLaserDataA(0, 0, 360/20*i+r+10, 0, 0, 0, 0);
				SetShotKillTime(0, 115);
				FireShot(0);
				Wait(3);
			}
			Wait(25);
		}
		else{
			ascent(i in 0..20)
			{
				CreateLaserA(0, curX, curY, 500, 10, BLUE01, 60-5*i);
				SetLaserDataA(0, 0, 360/20*i+r, 0, 0, 0, 0);
				SetShotKillTime(0, 115);
				FireShot(0);
				Wait(3);
			}
		Wait(110);
		}

		if(frame<3350){lasercover1;}
	}
	
	task lifestream
	{
		CreateLaserC(0, rand(-50, 0), rand(0, 530), 7, 60, GREEN01, 5);
		SetLaserDataC(0, 0, 4.5, -45, 0.7, 0, 1);
		FireShot(0);
		CreateLaserC(1, rand(448, 498), rand(-50, 480), 7, 60, GREEN01, 5);
		SetLaserDataC(1, 0, -4.5, -45, 0.7, 0, 1);
		FireShot(1);
		Wait(9);
		if(frame<4250){lifestream;}
	}
	
	task absorbtion
	{
		Wait(4);
		if(frame<4800){absorbtion;}
		let l = Obj_Create(OBJ_SINUATE_LASER);
		Obj_SetPosition(l, rand(-50, 0), rand(0, 530));
		Obj_SetSpeed(l, 4);
		ObjShot_SetGraphic(l, GREEN01);
		ObjSinuateLaser_SetWidth(l, 7);
		ObjSinuateLaser_SetLength(l, 60);
		let r = rand(1.5, 2.5);
		ascent(i in 0..400)
		{
			Obj_SetAngle(l, -45*cos(frame*r));
			Wait(1);
		}
		Obj_Delete(l);
	}
	
}//OH DESIRE