#TouhouDanmakufu
#Title[Contest nonspell 1]
#Text[reimuuuuu]
#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(500);
		SetDamageRate(10, 10);
                SetTimer(70);
		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);

		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;
		attack4;
		countdown1;
		
	}



	task attack{
		loop{
		angle = 0;
		let speed = 2;
		loop(128){
		CreateShot01(GetX,GetY,speed, 0 + angle ,99,10);
		CreateShot01(GetX,GetY,speed, 180 - angle ,99,10);
		angle += 5;
		wait(5);
		}
		angle = 0;
		loop(128){
		CreateShot01(GetX,GetY,speed, 0 + angle ,103,10);
		CreateShot01(GetX,GetY,speed, 180 - angle ,103,10);
		angle += 2.5;
		wait(5);
		}
		}
		}
	task attack2{
		loop{
		let speed2 = 2;
		loop(128){
		CreateShot01(GetX,GetY,speed2, 0 - angle1 ,98,10);
		CreateShot01(GetX,GetY,speed2, 180 + angle1 ,98,10);
		angle1 += 10;
		wait(5);
		}
		loop(128){
		CreateShot01(GetX,GetY,speed2, 0 - angle1 ,97,10);
		CreateShot01(GetX,GetY,speed2, 180 + angle1 ,97,10);
		angle1 += 7.5;
		wait(5);
		}
		}
		}
	task attack3{
		loop{
		angle = 0;
		let speed = 2;
		loop(128){
		CreateShot01(GetX - 50,GetY,speed, 0 + angle ,101,10);
		CreateShot01(GetX + 50,GetY,speed, 180 - angle ,101,10);
		angle += 5;
		wait(5);
		}
		angle = 0;
		loop(128){
		CreateShot01(GetX - 100,GetY,speed, 0 + angle ,102,10);
		CreateShot01(GetX + 100,GetY,speed, 180 - angle ,102,10);
		angle += 7;
		wait(5);
		}
		}
		}
	task attack4{
 loop{
 loop(3){burst(speed+2); burst2(speed+2); speed+=0.6; wait(5);PlaySE(CSD ~ "SE\se_tan00.wav");}
 speed = 0;
 wait(180);
 }
}

function burst(speed){
 ascent(i in 0..7){
 CreateShot01(GetX,GetY,speed,GetAngleToPlayer+i*2,69,10);
CreateShot01(GetX,GetY,speed, 45+i*2,69,10);
CreateShot01(GetX,GetY,speed, 135+i*2,69,10);
 speed-=0.2;}
}

function burst2(speed){
 ascent(i in 0..7){
 CreateShot01(GetX,GetY,speed,GetAngleToPlayer-i*2,69,10);
CreateShot01(GetX,GetY,speed,  45-i*2,69,10);
CreateShot01(GetX,GetY,speed,  135-i*2,69,10);

 speed-=0.2;}
}

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

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

	

	
		
}