#TouhouDanmakufu
#Title[Divine Grimoire "Faithful Star"]
#Text[That annoying goddess has been bothering Marisa to teach her shrine maiden about magic. This was one of her practical lessons.]
#BackGround[User(.\img\BG.png,0,0)]
#PlayLevel[Normal]
#Player[FREE]
#BGM[.\bgm.mp3]
#ScriptVersion[2]
script_enemy_main	
{
#include_function ".\function_cutin.txt"
#include_function ".\lib.txt"
let bgalpha = 0;	
let bgangle = 0;	
let NakoCircle1 = csd~ "img/kanako.png";
let NakoCircle2 = csd~ "img/kanako.png";
let NakoCircle3 = csd~ "img/kanako.png";
let bossflip = 0;
let ani = 0;
let RainPosition = DividePlayingFieldX (5,50);
let StarAngle1 = 0;
let StarAngle3 = 360;
let s1 = 0; let s2 = 0;
let x1 = 0; let x2 = 0; let x3 = 0;
let y1 = 0; let y2 = 0; let y3 = 0;
let angle1 = 90; let angle2 = 306.5; let angle3 = 232.5;
let b1 = 1; let b2 = 1; let b3 = 1;
let g1 = 1; let g2 = 1; let g3 = 1;
let r1 = 1; let r2 = 1; let r3 = 1;

@Initialize{
	LoadStuff;
	LoadGraphic(NakoCircle1);
	LoadGraphic(NakoCircle2);
	LoadGraphic(NakoCircle3);
	SetLife(3500);
	SetInvincibility(180);
	SetTimer(90);
	SetScore(1000000);
	cutin("NAZRIN","Divine Grimoire "\""Faithful Star"\",Maricutin,0,0,256,512);
	SetEffectForZeroLife(60,0,0);
	SetMovePosition02(GetCenterX,GetCenterY-120,60);
	LoadUserShotData(GetCurrentScriptDirectory~"Shot.txt");
	MainTask;
	Timer;
	MoveAnimation;
	}
task MainTask{
	Wait(60);
	SetColor(145,5,158);
	Concentration01(120);
	SetColor(255,255,255);
	PlaySE(Charge);
	Wait(120);
	CircleMove;
	ColorChange;
	s1=1; s2=1;
	StarRain(RainPosition[0],1, 4);
	StarRain(RainPosition[1],2, 12);
	StarRain(RainPosition[2],2, 12);
	StarRain(RainPosition[3],2, 12);
	StarRain(RainPosition[4],3, 4);	
	}
task CircleMove{loop{
	x1=GetX+100*cos(angle1); x2=GetX+100*cos(angle2) - 60; x3=GetX+100*cos(angle3) + 60;
	y1=GetY+100*sin(angle1)-100; y2=GetY+100*sin(angle2)+80; y3=GetY+100*sin(angle3)+80;
	yield;
	}}
task ColorChange{
	loop{
		b1 = 255; b2 = 1; b3 = 1;
		g1 = 1; g2 = 255; g3 = 1;
		r1 = 1; r2 = 1; r3 = 255;
		Wait(60);
		b1 = 1; b2 = 255; b3 = 1;
		g1 = 1; g2 = 1; g3 = 255;
		r1 = 255; r2 = 1; r3 = 1;
		Wait(60);
		b1 = 1; b2 = 1; b3 = 255;
		g1 = 255; g2 = 1; g3 = 1;
		r1 = 1; r2 = 255; r3 = 1;
		Wait(60);
		}
	}
task StarRain(rainwhere, rainwhat, raindelay){
	loop{
		Bullet(rainwhere, rainwhat);
		Wait(raindelay);
		}
	}
task Bullet (rainwhere, rainwhat){
	let obj=Obj_Create(OBJ_SHOT);
	let change = 0;
	Obj_SetPosition(obj, rand(rainwhere-5, rainwhere+5), GetClipMinY);
    Obj_SetAngle(obj, 90);
    Obj_SetSpeed(obj, 5);
    ObjShot_SetGraphic(obj, 149);
    ObjShot_SetDelay  (obj, 0);
    ObjShot_SetBombResist (obj, false);
	while(Obj_BeDeleted(obj)==false){
		if (Obj_GetY(obj)>=GetClipMaxY-200){
			ObjShot_SetGraphic(obj, 147);
			if (rainwhat==1 && change==0){
				Obj_SetAngle(obj, StarAngle1);
				Obj_SetSpeed(obj, 2);
				change = 1;
				}
			else if (rainwhat==3 && change==0){
				Obj_SetAngle(obj, StarAngle3);
				Obj_SetSpeed(obj, 2);
				change = 1;
				}
			else if (rainwhat==2 && change==0){
				Obj_SetAngle(obj, GetRelativeAngleToPlayer(Obj_GetX(obj),Obj_GetY(obj)));
				Obj_SetSpeed(obj, 1);
				change = 1;
				}
			}
		yield;
		}
	}
@MainLoop{
	SetCollisionA(GetX,GetY,48);
	SetCollisionB(GetX,GetY,32);
	StarAngle1++;
	StarAngle3--;
	angle1+=6; angle2+=6; angle3+=6;
	yield;
	}
@DrawLoop{
	DrawName("Marisa Kirisame");
	SetAlpha(255);
	if (bossflip==0){SetGraphicScale(1,1);}
	if (bossflip==1){SetGraphicScale(-1,1);}
	
	SetTexture(NakoCircle1);
	SetColor(b1,g1, r1);
	SetGraphicAngle(0,0,0);
	SetGraphicRect(0,0,256,256);
	SetRenderState(ADD);
	SetGraphicScale(s1,s2);
	DrawGraphic(x1,y1);
	
	SetTexture(NakoCircle2);
	SetColor(b3,g3,r3);
	SetGraphicAngle(0,0,0);
	SetGraphicRect(0,0,256,256);
	SetRenderState(ADD);
	SetGraphicScale(s1,s2);
	DrawGraphic(x2,y2);
	
	SetTexture(NakoCircle3);
	SetColor(b2,g2,r2);
	SetGraphicAngle(0,0,0);
	SetGraphicRect(0,0,256,256);
	SetRenderState(ADD);
	SetGraphicScale(s1,s2);
	DrawGraphic(x3,y3);
	
	SetTexture(Marisprite);
	SetColor(255,255,255);
	SetGraphicAngle(0,0,0);
	SetRenderState(ALPHA);
	SetGraphicScale(1,1);
	SetGraphicRect(BR[0],BR[1],BR[2],BR[3]);
	DrawGraphic(GetX,GetY);
	}

@BackGround{
	SpellBG;
	}
@Finalize{
	DeleteStuff;
	CaptureBonus;
	}
}