#TouhouDanmakufu
#Title[Reimu s1]
#Text[Danmaku from another world.
A short space trip.
However,unknown objects and lights are to be seen.It dosen't bear any meaning.Except for the one using it.]
#BackGround[User(.\img\BG.png,0,0)]
#PlayLevel[Normal]
#Player[FREE]
#BGM[.\bgm.mp3]
#ScriptVersion[2]



script_enemy_main{
let csd = GetCurrentScriptDirectory;

let bgangle=0;

let Enemy = csd~"img/sprites/whitereimu.png";
let EnemyCutin = csd~"img/cut/ReimuWS.png";
let SpellBG1 = csd~"img/sprites/BG1.png";
let SpellBG2 = csd~"img/sprites/BG2.png";

let laser1 = csd~"se/laser1.wav";
let shot6 = csd~"se/shot6.wav";
let Charge = csd~"se/Charge.wav";
let time01 = csd~"se/timeout0.wav";
let time02 = csd~"se/timeout1.wav";
let angle=0;
let acc=0;
let x=0;
let y=0;

#include_function ".\shots\MS_Shot_Name.txt"


@Initialize
{
LoadGraphic(Enemy);	//The CutIn function will automatically load and delete the cutin later.
LoadGraphic(SpellBG1);
LoadGraphic(SpellBG2);
LoadSE(shot6);
LoadSE(laser1);
LoadSE(time01);
LoadSE(time02);

SetLife(2000);		//Spell cards tend to have low health, but high resistance to damage until a certain amount of time passes.
SetDamageRate(10,5);	//This spell will take 10% damage from shots, and 5% from bombs (to prevent bombing through a card quickly).
SetTimer(60);

SetScore(100000);	//Sets the spell card bonus.


CutIn(YOUMU,"Sealed World"\""Danmaku From a Simple Mind"\",EnemyCutin,0,0,256,512);

SetEffectForZeroLife(60,0,0);
	
SetMovePosition02(GetCenterX,GetCenterY-120,60);

LoadUserShotData(GetCurrentScriptDirectory~".\shots\newshots9c.txt");

MainTask;
Vulnerable;
Timer;
}


task Move{SetMovePosition02(GetCenterX+rand(-100,100),GetCenterY-rand(80,130),60);}




task Vulnerable
{
Wait(1200);
SetDamageRate(50,50);	//Becomes more vulnerable after 20 seconds.
}


task MainTask{
Wait(60);

SetColor(255,64,64);
Concentration01(120);
SetColor(255,255,255);
Concentration01(120);

SetColor(255,255,255);	//Sets color back to normal.
PlaySE(Charge);
Wait(120);

loop{
loop(10){
PlaySE(shot6);
Comet(rand(GetClipMinX,GetClipMaxX),GetClipMinY,6,HEX_RED,90);
Wait(60);}

Wait(120);

let num=6;
loop(num){
PlaySE(shot6);
Comet(GetEnemyX,GetEnemyY,3,HEX_WHITE,angle);
angle+=360/num;
}

Wait(120);





	}
}



task Comet(x,y,s,graphic,angle){
yield;
 
let obj= Obj_Create(OBJ_SHOT);
Obj_SetPosition(obj,x,y);
Obj_SetAngle(obj,angle);
Obj_SetSpeed(obj,s);
ObjShot_SetGraphic(obj,graphic);
ObjShot_SetDelay(obj,0);
 
		

while(!Obj_BeDeleted(obj)){
yield;

CreateLaser01(Obj_GetX(obj),Obj_GetY(obj),rand(2,3),rand(0,359),100,7,graphic-135,20);
PlaySE(laser1);

		Wait(2);

if(Obj_GetX(obj)>GetClipMaxX+30||Obj_GetX(obj)<GetClipMinX-30||Obj_GetY(obj)>GetClipMaxY+30 ||Obj_GetY(obj)<GetClipMinY){Obj_Delete(obj); yield;}
                        
                }
 
 
}




task Timer{
loop{
	if (GetTimer > 5 && GetTimer <= 11){PlaySE(time01);}
	if (GetTimer >= 1 && GetTimer <= 5){PlaySE(time02);}
	Wait(60);
	}
}

function Wait(t){loop(t){yield;}}



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



@DrawLoop
{
SetAlpha(255);
SetGraphicScale(1,1);
SetColor(255,255,255);
SetGraphicAngle(0,0,0);
SetTexture(Enemy);
SetGraphicRect(44,34,87,95);

DrawGraphic(GetX,GetY);
}


let bgalpha1 = 0;
let bgalpha2 = 0;

@BackGround{
bgangle+=0.3;
if (bgalpha1 < 255){bgalpha1 += 5;}
if (bgalpha2 < 255){bgalpha2 += 5;}

SetAlpha(bgalpha1);
SetGraphicScale(2.5,2.5);	//The background is scaled up so it can fill the whole screen.
SetColor(255,255,255);
SetGraphicRect(0,0,256,256);
SetGraphicAngle(0,0,bgangle);
SetTexture(SpellBG1);
DrawGraphic(GetCenterX,GetCenterY);

SetAlpha(bgalpha2);
SetGraphicScale(2.5,2.5);	//The background is scaled up so it can fill the whole screen.
SetColor(255,255,255);
SetGraphicRect(0,0,256,256);
SetGraphicAngle(0,0,-bgangle);
SetTexture(SpellBG2);
DrawGraphic(GetCenterX,GetCenterY);


//Remember to set everything back to default before drawing something else 
}


@Finalize
{
DeleteGraphic(Enemy);
DeleteGraphic(SpellBG1);
DeleteGraphic(SpellBG2);
}

}

