#TouhouDanmakufu
#Title[Contest Spell 1]
#Text[reimuuuu]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{

        let CSD = GetCurrentScriptDirectory;
	#include_function ".\AnimationLib.dnh";
	let spritereimu = CSD ~ ".\Reimu2.png";
	let ShotData = CSD ~ "lib\supershot.txt";
        let imgBoss = CSD ~ "img\Sprite.png";
        let cut = CSD ~ "img\Swr_reimu.jpg";
        let bg = CSD ~ "img\IMG_0517-520x520.jpg";
        let bgm = CSD ~ "bmg\09 - Maiden's Capriccio ~ Dream Battle";
	let shot3 = CSD ~"SE\shot3.wav";
	let Laser3 = CSD ~"SE\Laser3.wav";
	let frame = 0;	
	let angle = 0;
	let angle1 = 360/36;
	let timer1 = 0;
	let speed = 1;
	let angle2 = 360/5;
	let angle3 = 360/7;
	let angle4 = 360/12;
	
	@Initialize{
		
		SetLife(1400);
		SetDamageRate(10, 10);
                SetTimer(95);
		SetInvincibility(240);
                SetScore(200000);
		SetMovePosition01(GetCenterX,180,5);
		SetEnemyMarker(true);
        	SetDurableSpellCard;
		Concentration01(120);
		MagicCircle(true);
		SetEffectForZeroLife(180, 100, 1);
                LoadGraphic(imgBoss);
                LoadGraphic(cut);
                LoadGraphic(bg);
                LoadMusic(bgm);
                PlayMusic(bgm);
		LoadSE(shot3);
		LoadSE(Laser3);
		LoadUserShotData(ShotData);
		LoadGraphic(spritereimu);
CutIn(YOUMU," Heaven's feel - Paranoia Cage",cut,0,0,192,256);
		CreateAnimation("reimu", "idle", 4);
  SetAnimationFrame("reimu", "idle", 0, spritereimu, 10, 0, 0, 64, 76);
  SetAnimationFrame("reimu", "idle", 1, spritereimu, 10, 64, 0, 128, 76);
  SetAnimationFrame("reimu", "idle", 2, spritereimu, 10, 128, 0, 192, 76);
  SetAnimationFrame("reimu", "idle", 3, spritereimu, 10, 192, 0, 256, 76);

  CreateAnimation("reimu", "move left", 4);
  SetAnimationFrame("reimu", "move left", 0, spritereimu, 6, 0, 78, 64, 152);
  SetAnimationFrame("reimu", "move left", 1, spritereimu, 6, 64, 78, 128, 151);
  SetAnimationFrame("reimu", "move left", 2, spritereimu, 6, 128, 78, 192, 150);
  SetAnimationFrame("reimu", "move left", 3, spritereimu, 6, 192, 78, 256, 148);
  
  CreateAnimation("reimu", "shoot", 4);
  SetAnimationFrame("reimu", "shoot", 0, spritereimu, 12, 0, 158, 64, 250);
  SetAnimationFrame("reimu", "shoot", 1, spritereimu, 12, 64, 158, 128, 250);
  SetAnimationFrame("reimu", "shoot", 2, spritereimu, 12, 128, 158, 192, 250);
  SetAnimationFrame("reimu", "shoot", 3, spritereimu, 12, 192, 158, 256, 250);
  
  Animate("reimu", "idle", true);
                
 		Maintask;
		
	}

	@MainLoop{
                SetCollisionA(GetX,GetY,32);
                SetCollisionB(GetX,GetY,16);
		yield;
	}
		let float = 0;
	@DrawLoop{
		SetTexture(spritereimu);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
			if(GetSpeedX<0){
			SetGraphicAngle(180,0,0);
			}
		
			DrawAnimatedSprite("reimu",GetX,GetY+5*sin(float));

		float+=5;
   }
  
  

	@BackGround{

                SetTexture(bg);
                SetRenderState(ALPHA);
                SetAlpha(255);
                SetGraphicRect(0,0,520,520);
                SetGraphicScale(1,1);
                SetGraphicAngle(0,0,0);
                DrawGraphic(GetCenterX,GetCenterY);

	}

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

	}

	task Maintask {
		SetColor(255,255,255);
		Concentration01(120);
		PlaySE(CSD ~ "SE\se_ch00.wav");
		wait(120);
		attack;
		attack2;
		attack3;
		countdown1;
	}

task attack{
	loop{
		fire;
		wait(60);
		fire2;
		wait(60);
		fire3;
		}
}

task attack2{
	loop{
		stream;
		wait(180);
		}
}

task attack3{
	loop{
	stream2;
	PlaySE(CSD ~ "SE\se_tan00.wav");
	CreateShot01(46,16,5,90,95,10);
	CreateShot01(46,26,5, 0 ,95,10);
	CreateShot01(406,450,5,180,95,10);
	CreateShot01(402,464,5,-90,95,10);
	CreateShot01(56,16,4,90,95,10);
	CreateShot01(46,36,4, 0 ,95,10);
	CreateShot01(396,440,4,180,95,10);
	CreateShot01(392,464,4,-90,95,10);	
	wait(30);
	}
}
task stream2{
	PlaySE(CSD ~ "SE\se_tan00.wav");
	CreateShot01(36,16,3,90,95,10);
	CreateShot01(32,20,3, 0 ,95,10);
	CreateShot01(416,460,3,180,95,10);
	CreateShot01(412,464,3,-90,95,10);
	wait(30);
	}

task stream{
	let speed = 1;
	loop(8){ PlaySE(CSD ~ "SE\se_tan00.wav");
	ascent(i in -4..5){
	CreateShot01(GetX,GetY,speed,GetAngleToPlayer+i*30,95,10);
	CreateShot01(GetX,GetY,speed,-(GetAngleToPlayer+i*30),95,10);
	}
	speed+=0.2; wait(2);}	
}

function fire{
	let dir = 0;
	let angle = 0;
	loop(8){
		loop(36){
		PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01(GetEnemyX + dir, GetEnemyY -100, 2 ,  angle , 96 , 10);
		CreateShot01(GetEnemyX - dir, GetEnemyY -100, 2 ,  angle , 96 , 10);
		angle += 360/36;
		}
		dir+=20; wait(60);
		}
		dir=0;
}

function fire2{
	let dir = 0;
	let angle = 0;
		loop(20){
		loop(16){
		PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01(GetEnemyX + 160, (GetEnemyY -100) + dir, 2 ,  angle , 97 , 10);
		CreateShot01(GetEnemyX - 160, (GetEnemyY + 270) - dir, 2 ,  angle , 97 , 10);
		angle += 360/16;
		}
		dir+=20; wait(60);
		}
		dir=0;
	}
function fire3{
		let dir = 0;
		let angle = 0;
		loop(20){
		loop(16){
		PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01((GetEnemyX - 200) + dir, (GetEnemyY +270), 2 ,  angle , 98 , 10);
		CreateShot01((GetEnemyX + 200) - dir, (GetEnemyY -100), 2 ,  angle , 98 , 10);
		angle += 360/16;
		}
		dir+=20; wait(60);
		}

		dir = 0;
}

task countdown1{
 loop{
  if(GetTimer<11){
   wait(60);
   PlaySE(CSD ~ "SE\se_timeout.wav");
    }
  yield;}
 }

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

	

	
		
}