#TouhouDanmakufu
#Title[Non Spell 01 -Normal-]
#Text[]
#Image[.\image.jpg]
#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 ImgBoss = "script\Yui\Img\yui.png";
	let bg = "script\Yui\Img\back.png";
        let dis = "script\Yui\SE\Shot4.wav";
let laugh ="script\Yui\SE\laugh.wav";
	@Initialize{
		SetLife(4500);
		SetTimer(100);
		//SetScore(100000);
                SetEnemyMarker(true);
                MagicCircle(true);
		SetMovePosition01(GetCenterX,GetCenterY,50);
		LoadGraphic(imgBoss);
                LoadGraphic(bg);
                shotinit;
                LoadSE(dis);
                LoadSE(laugh);
	
		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(bg);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicRect(0,0,600,800);
		SetGraphicScale(0.7,0.6);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY);
	}

	@Finalize{
		DeleteGraphic(imgBoss);
		DeleteGraphic(cut);
		DeleteGraphic(bg);
	}

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

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

	task movement{
		loop{
	                SetMovePositionRandom01(50,rand(0,0),7,GetCenterX-100,100,GetCenterX+100,130);
			wait(200);
			yield;
		}
	}

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

		loop{
			//while loop, executes while x<36
			while(x<36){
	            CreateShotA(5, GetX, GetY, 10);
            CreateShotA(3, GetX, GetY, 10);
            SetShotDataA(3, 0, 5, 180, -5, 0, 5, RED59);
            SetShotDataA(3, 60, 5, 48, 0, 1, 8, RED59);
            ascent(i in 1..20){
                CreateShotA(4, 0, 0, 30);
                SetShotDataA_XY(4, 0, rand(-1, 1), rand(-3, -10), 0, 0.1, 0, 3, SP01);
                AddShot(i*2, 3, 4, 0);
            }
            FireShot(3);

            CreateShotA(5, GetX, GetY, 10);
            SetShotDataA(5, 0, 5, 0, 5, 0, 5, BLUE59);
            SetShotDataA(5, 60, 5, 132, 0, 1, 8, BLUE59);
            ascent(i in 1..20){
                CreateShotA(6, 0, 0, 30);
                SetShotDataA_XY(6, 0, rand(-1, 1), rand(-3, -10), 0, 0.1, 0, 3, SP02);
                AddShot(i*2, 5, 6, 0);

            }
            FireShot(5);

	            CreateShotA(5, GetX, GetY, 10);
            CreateShotA(3, GetX, GetY, 10);
            SetShotDataA(3, 0, 5, 180, -5, 0, 5, RED59);
            SetShotDataA(3, 60, 5, 48, 0, 1, 8, RED59);
            ascent(i in 1..20){
                CreateShotA(4, 0, 0, 30);
                SetShotDataA_XY(4, 0, rand(-1, 1), rand(-3, -10), 0, 0.1, 0, 3, SP01);
                AddShot(i*2, 3, 4, 0);
            }
            FireShot(3);
            PlaySE(dis);

            CreateShotA(5, GetX, GetY, 10);
            SetShotDataA(5, 0, 5, 0, 5, 0, 5, BLUE59);
            SetShotDataA(5, 60, 5, 132, 0, 1, 8, BLUE59);
            ascent(i in 1..20){
                CreateShotA(6, 0, 0, 30);
                SetShotDataA_XY(6, 0, rand(-1, 1), rand(-3, -10), 0, 0.1, 0, 3, SP02);
                AddShot(i*2, 5, 6, 0);

            }
            FireShot(5);
			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;}
	}
}

