#TouhouDanmakufu
#Title[Flower Sign - Flower Field]
#Text[Flores que no desaparecen llenaran toda la pantalla]
#Image[.\image.jpg]
#PlayLevel[Survival]
#Player[FREE]
#ScriptVersion[2]
#BGM[.\yuugi.mp3]

script_enemy_main{

	let CSD	= GetCurrentScriptDirectory;
        #include_function "script\Yui\SHOT_REPLACE\shot_replace.dnh"
	#include_function"script\Yui\CharacterRect.txt"
        #include_function "script\Yui\CutIn\function_cutin.txt"
        let cut = "script\Yui\Img\Yui2.png";
        LoadGraphic(cut);
	let bg = "script\yui\back.png";
let img_bg= "script\Yui\Img\yuibacka.png";
let img_bgb= "script\Yui\Img\yuibackc.png";
let black= "script\Yui\Img\black.png";
let anim=0;
let type=0;
let bgdist=0;
let rot=0;
let alpha=255;
let drawangle=0;
let flor = "script\Yui\SE\elec.wav";
let laugh ="script\Yui\SE\laugh.wav";
let ss ="script\Yui\SE\spell.wav";
	let to1 = "script\Yui\SE\se_timeout1.wav";
	let to2 = "script\Yui\SE\se_timeout2.wav";


	@Initialize{
		SetLife(7000);
		SetTimer(94);
		SetScore(200000);
                SetDurableSpellCard;
                SetEnemyMarker(true);
                MagicCircle(false);
		SetMovePosition01(GetCenterX,GetCenterY,50);
                //SetEffectForZeroLife(180, 100, 1);
		//LoadGraphic(imgBoss);
                LoadGraphic(bg);
                shotinit;
LoadGraphic(black);
LoadGraphic(img_bg);
LoadGraphic(img_bgb);
LoadSE(flor);
LoadSE(laugh);
LoadSE(ss);
LoadSE(to1);
LoadSE(to2);

		cutin("NAZRIN", "Flower Sign "\""Flower Field"\",cut, 0, 0, 210, 470);
	        PlaySE(ss);
		mainTask;
	}

	@MainLoop{
		//SetCollisionA(GetX,GetY,32);
		//SetCollisionB(GetX,GetY,16);
		yield;
	}

	@DrawLoop{
  
	if(GetSpeedX()<0){SetGraphicRect(GraphicRectLeft[0],GraphicRectLeft[1],GraphicRectLeft[2],GraphicRectLeft[3]);}
	else if(GetSpeedX()>0){SetGraphicRect(GraphicRectRight[0],GraphicRectRight[1],GraphicRectRight[2],GraphicRectRight[3]);}
	else {SetGraphicRect(GraphicRectCenter[0],GraphicRectCenter[1],GraphicRectCenter[2],GraphicRectCenter[3]);}
	SetAlpha(255);
	SetGraphicExpansion(GraphicScale,GraphicScale);
	SetColor(255,255,255);
	SetGraphicAngle(0,0,0);
	SetTexture(imgBoss);	
	DrawGraphic(GetX(),GetY());	

        DrawText("Yui-chan", 40, 35, 12, 255);
        DrawGraphic(GetX, GetY);
	
	}

	@BackGround{
	SetTexture(black);
	SetGraphicRect(-1024, -1024, 1024, 1024);
	SetGraphicAngle(0, 0, 0);
    SetRenderState(ALPHA);
	SetAlpha(255);
	DrawGraphic(GetCenterX, GetCenterY);
	SetTexture(img_bg);
	SetGraphicRect(0, 0, 256, 256);
	SetGraphicAngle(0, 0, rot);
	SetGraphicScale(3, 3);
	SetAlpha(175);
	DrawGraphic(GetCenterX, GetCenterY);
	SetTexture(img_bgb);
	SetGraphicRect(0, 0, 256, 256);
	SetGraphicAngle(0, 0, -rot);
	SetGraphicScale(3, 3);
	SetAlpha(100);
	DrawGraphic(GetCenterX, GetCenterY);
	rot+=0.5;
	}

	@Finalize{
		DeleteGraphic(imgBoss);
		DeleteGraphic(cut);
		DeleteGraphic(bg);
            loop(30){
                CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
	}
	}

	// main task, activates stuff.
	task mainTask{
                timeout;
                deathLaugh;
		yield;
		fire;
		movement;

	}

	task timeout(){
		loop{
			if (GetTimer > 4 && GetTimer <= 10){
				PlaySE(to1);
				wait(60);
			}
			else if (GetTimer <= 4){
				PlaySE(to2);
				wait(60);
			}
			
			yield;
		
		}
	}
task deathLaugh(){
		loop{
		if(GetTimeOfPlayerInvincibility()>0){
			PlaySE(laugh);
			wait(300);
		}		
		wait(5);
			yield;
		}
	
	}

	task movement{
		loop{
	                //SetMovePositionRandom01(GetCenterX,GetCenterY,3,60,100,408,200);
			wait(200);
			yield;
		}
	}

	task fire{
		let x = 0;
		let dir = 0;

		loop{
			//while loop, executes while x<36
			while(x<36){
                        //CreateLaserA (id, posicion x, posicion y, ??,??,grafico, retraso)
			CreateLaserA(1, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(1, 0, -90, 12, 0, 0, 0);
			//SetShotKillTime(1, 120);
			FireShot(1);


			CreateLaserA(2, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(2, 10, 90, 12, 0, 0, 0);
			//SetShotKillTime(2, 120);
			FireShot(2);


			CreateLaserA(1, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(1, 20, 90, 12, 0, 0, 0);
			//SetShotKillTime(1, 120);
			FireShot(1);

			CreateLaserA(1, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(1, 30, -90, 12, 0, 0, 0);
			//SetShotKillTime(1, 120);
			FireShot(1);

			CreateLaserA(1, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(1, 40, 90, 12, 0, 0, 0);
			SetShotKillTime(1, 120);
			FireShot(1);

			CreateLaserA(1, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(1, 50, -90, 12, 0, 0, 0);
			//SetShotKillTime(1, 120);
			FireShot(1);

			CreateLaserA(1, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(1, 60, 90, 12, 0, 0, 0);
			//SetShotKillTime(1, 120);
			FireShot(1);

			CreateLaserA(1, GetPlayerX, GetPlayerY, 100, 72, SP01, 60);
			SetLaserDataA(1, 70, -90, 12, 0, 0, 0);
			//SetShotKillTime(1, 120);
			FireShot(1);
                        PlaySE(flor);

			loop(240){yield;}

				//adjust the angle of the next bullet to complete a circle
				dir+=360/36;
				x++;
			}
			x = 0;
			dir = 0;
			wait(60);

		}
	}

	// wait function
	function wait(w){
		loop(w){yield;}
	}
}

