script_enemy_main
{
	#include_function ".\System\CommonFunctions.dnh"
	#include_function ".\System\EnemyFunctions.dnh"
	SetDamageRate(0, 0);
	let frame = -200;
	let petalcolour = [RED21, BLUE21, PURPLE21, YELLOW21, ORANGE21, AQUA21];
	let centercolour = [YELLOW04, ORANGE04, RED04];
	MaxLife = 1300;
	
	@Initialize
	{
		Init;
		leafSplode;
		SetLife(1300);
		SetMovePosition01(GetCenterX, GetCenterY - 120, 5);
		SetDamageRate(20, 10);
		SetScore(300000);
		CutIn(YOUMU, "Plant Growth : Climber Vines", CutinImg, 0, 0, 256, 512);
		MagicCircle(false);
		SetEnemyMarker(true);
	}
	
	@MainLoop
	{
		if(frame == -121)
		{
			Concentration01(60);
			PlaySE(charge);
		}
		if(frame >= -60 && frame % 10 == 0 && frame < 0)
		{
			if(frame == -50)
			{
				PlaySE(shot2);
				PlaySE(wave);
			}
			leafSplode;
			SetCommonData("SpellActivate", true);
		}
		if(xscale > 0.1 && yscale > 0)
		{
			SetCollisionA(GetX, GetY, 24);
			SetCollisionB(GetX, GetY, 12);
		}
		if(frame == 180)
		{
			SetDamageRate(30, 30);
			SetMovePositionRandom01(40, 30, 1, upper(GetPlayerX - 80, GetClipMinX + 80), GetClipMinY + 50, lower(GetClipMaxX - 80, GetPlayerX + 80), GetClipMinY + 100);
		}
		if(frame >= 260)
		{
			FakeLaser;
			PlaySE(laser);
			frame = 0 + delaydecrease;
		}
		
		CheckForDamage;
		PlayTimerSound;
		
		frame ++;
		yield;
	}
	
	@DrawLoop
	{
		DrawLilyBlack;
	}
	
	@Finalize
	{
		Final;
	}
	
	task Vine(let X, let Y)
	{
		let count = 1;
		let flowersprout = rand_int(10, 20)*2;
		let vinetop = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(vinetop, X, Y);
		ObjShot_SetGraphic(vinetop, RED01);
		ObjShot_SetBombResist(vinetop, true);
		Obj_SetSpeed(vinetop, 2);
		Obj_SetAlpha(vinetop, 0);
		Obj_SetCollisionToPlayer(vinetop, false);
		let fly = false;
		while(Obj_GetY(vinetop) > GetClipMinY - 20)
		{
			if(count % 4 == 0)
			{
				CreateShotA(1, Obj_GetX(vinetop), Obj_GetY(vinetop), 50);
				SetShotDataA(1, 0, 0, Obj_GetAngle(vinetop), 0, 0, 0, GREEN21);
				SetShotDataA(1, 90, 0, Obj_GetAngle(vinetop), 0, 0, 0, GREEN05);
				SetShotDataA(1, 140, 0, Obj_GetAngle(vinetop), 0, 0, 0, ORANGE05);
				if(fly)
				{
					SetShotDataA(1, 190, 0, rand(0, 360), 0, 0.04, 2, ORANGE05);
				} else
				{
					SetShotKillTime(1, 190);
				}
				FireShot(1);
				fly = !fly;
				if(count % 6 == 0)
				{
					PlaySE(wave);
					Obj_SetAngle(vinetop, rand(240, 300));
				}
			}
			if(count % flowersprout == 0)
			{
				PlaySE(wave2);
				Flower(Obj_GetX(vinetop) + rand(8, -8), Obj_GetY(vinetop), rand_int(4,8));
				if(rand_int(0, 32) == 0){
					Vine(Obj_GetX(vinetop), Obj_GetY(vinetop));
				}
			}
			count ++;
			yield;
		}
	}
	
	function FakeLaser
	{
		CreateLaserB(2, GetClipMaxY - GetClipMinY, 10, GREEN01, 80);
		SetLaserDataB(2, 0, 0, 0, 0, 90, 0, 90, 0);
		SetShotKillTime(2, 90);
		FireShot(2);
		Laser2;
	}
	
	task Laser2
	{
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, GetX, GetY);
		ObjLaser_SetLength(obj, 60);
		ObjLaser_SetWidth(obj, 30);
		Obj_SetAngle(obj, 90);
		ObjShot_SetGraphic(obj, GREEN01);
		ObjLaser_SetSource(obj, false);
		Obj_SetAlpha(obj, 0);
		loop(80)
		{
			yield;
		}
		Obj_SetAlpha(obj, 255);
		while(Obj_GetY(obj) < GetClipMaxY + 10)
		{
			Obj_SetY(obj, Obj_GetY(obj) + 14);
			yield;
		}
		Obj_Delete(obj);
		Vine(Obj_GetX(obj), Obj_GetY(obj));
		if(delaydecrease < 90){
			delaydecrease += 90/4;
		}
	}
}