#TouhouDanmakufu
#Title[Bounce Sign - Illusion Star -Hard-]
#Text[Muchas estrellas. En verdad algo confuso]
#Image[.\image.jpg]
#PlayLevel[Hard]
#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\MCircle.txt";
	#include_function"script\Yui\CharacterRect.txt"
        #include_function "script\Yui\CutIn\function_cutin.txt"
        let cut = "script\Yui\Img\yui2.png";
        LoadGraphic(cut);
        let dis = "script\Yui\SE\Shot1.wav";
        let laugh ="script\Yui\SE\laugh.wav";
let ss ="script\Yui\SE\spell.wav";

	let imgBoss = "script\Yui\Img\yui.png";
	let bg = "script\Yui\Img\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;


	@Initialize{
		SetLife(5000);
		SetTimer(120);
		SetScore(100000);
                SetInvincibility(70);
                SetEnemyMarker(false);
                MagicCircle(false);
                SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
		LoadGraphic(imgBoss);
                LoadGraphic(bg);
                LoadSE(dis);
                LoadSE(laugh);
                LoadSE(ss);
                shotinit;
LoadGraphic(black);
LoadGraphic(img_bg);
LoadGraphic(img_bgb);

		cutin("BYAKUREN", "Bounce Sign "\""Illusion Stars"\",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);

Circle;
	
	}

	@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{
		PlaySE("script\Yui\SE\se_charge01.wav");
		SetColor(100,100,100);
		Concentration01(80);
		SetColor(255,255,255);
		wait(80);
                deathLaugh;
		yield;
		fire;
		movement;

	}
task deathLaugh(){
		loop{
		if(GetTimeOfPlayerInvincibility()>0){
			PlaySE(laugh);
			wait(300);
		}		
		wait(5);
			yield;
		}
	
	}

	task movement{
		loop{
	                SetMovePositionRandom01(GetCenterX,GetCenterY,2,60,100,400,100);
			wait(200);
			yield;
		}
	}

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

		loop{
			//while loop, executes while x<36
			while(x<36){
								//CreateShotA(id,x,y,delay);
				CreateShotA(0,GetEnemyX+40*cos(dir),GetEnemyY+40*sin(dir),10);
				CreateShotA(1,GetEnemyX+40*cos(dir),GetEnemyY+40*sin(dir),10);
				CreateShotA(2,GetEnemyX+40*cos(dir),GetEnemyY+40*sin(dir),10);
				CreateShotA(3,GetEnemyX+40*cos(dir),GetEnemyY+40*sin(dir),10);
                               //CreateShotA(4,GetEnemyX+40*cos(dir),GetEnemyY+40*sin(dir),10); 
                                //CreateShotA(5,GetEnemyX+40*cos(dir),GetEnemyY+40*sin(dir),10);

				//SetShotDataA(id,time,speed,dir,dir-velocity,acceleration,maxspeed,graphic);

				//Holds bullet still
				//SetShotDataA(0,0,0,dir,0,0,0,BLUE59);
				//SetShotDataA(1,0,0,dir,0,0,0,RED59);
                               //SetShotDataA(2,0,0,dir,0,0,0,BLUE59);
                                //SetShotDataA(3,0,0,dir,0,0,0,RED59);
                                PlaySE(dis);

				//Moves Bullet
		                SetShotDataA(0,0,0,dir,0.0,3,6,BLUE59);
                                SetShotDataA_XY(0, 30, 1, -2.5, 0, 0.1, 1, 4, BLUE58);

				SetShotDataA(1,2,0,dir,0.0,3,6,RED59);
                                SetShotDataA_XY(1, 30, -1, -2.5, 0, 0.1, 1, 4, RED58);

				SetShotDataA(2,4,0,dir,0.0,3,6,BLUE59);
                                SetShotDataA_XY(2, 30, 1, -2.5, 0, 0.1, 1, 4, BLUE58); 
                               
                                SetShotDataA(3,6,0,dir,0.0,3,6,RED59);
                                SetShotDataA_XY(3, 30, -1, -2.5, 0, 0.1, 1, 4, RED58);

                                //SetShotDataA(4,8,0,dir,0.0,3,6,BLUE59);
                                //SetShotDataA_XY(4, 30, 1, -2.5, 0, 0.1, 1, 4, BLUE58);

                                //SetShotDataA(5,10,0,dir,0.0,3,6,RED59);
                               //SetShotDataA_XY(5, 30, -1, -2.5, 0, 0.1, 1, 4, RED58);


				//SetShotKillTime(id,value) optional
 

				//FireShot(id) fires bullet
		                FireShot(0);
				FireShot(1);
                                FireShot(2);
                                FireShot(3);
                                //FireShot(4);
                                //FireShot(5);
				//adjust the angle of the next bullet to complete a circle
				dir+=360/36;
				x++;
			}
			x = 0;
			dir = 0;
			wait(60);
			//regular shot
			//CreateShot01(GetEnemyX,GetEnemyY,6,GetAngleToPlayer,SP05,0);

			//wait 60 frames (1sec)
			wait(10);
			yield;
			//CreateShot01(x,y,speed,dir,graphic,delay);

		}
	}

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

