#TouhouDanmakufu
#Title[Subterranean Grimoire "Core Star -Maniac-"]
#Text[Marisa conducted research of Nuclear Fusion once. She had to rebuild the whole human village, the SDM and the entirety of the Magic Forest in one night.]
#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 bossflip = 0;
let ani = 0;
let spin = 0;
let size = 48;
let size2 = 32;
let imgWarning=csd~"img\stg6enm2.png";
let Explosion =csd~"img/Explode.png";
let explosionalpha = 255;
let explosionsize = 0;
@Initialize{
	LoadStuff;
	LoadGraphic(imgWarning);
	LoadGraphic(Explosion);
	SetLife(5000);
	SetInvincibility(180);
	SetTimer(90);
	SetScore(1000000);
	cutin("NAZRIN","Subterranean Grimoire "\""Core Star -Maniac-"\",Maricutin,0,0,256,512);
	SetEffectForZeroLife(60,0,0);
	SetMovePosition02(GetCenterX,GetCenterY-60,60);
	LoadUserShotData(GetCurrentScriptDirectory~"ShotKai.txt");
	MainTask;
	Timer;
	MoveAnimation;
	}
task MainTask{
	Wait(60);
	SetColor(255,0,0);
	Concentration01(120);
	SetColor(255,255,255);
	PlaySE(Alert);
	Warning;
	Wait(150);
	Star;
	}
function CreateEffect(tex, layer){
    let obj=Obj_Create(OBJ_EFFECT);
    ObjEffect_SetTexture(obj, tex);
    ObjEffect_SetLayer(obj, layer);
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_CreateVertex(obj, 4);
    return obj;
	}
function EffectXY(id, left, top, right, bottom){
    ObjEffect_SetVertexXY(id, 0, left, top);
    ObjEffect_SetVertexXY(id, 1, right, top);
    ObjEffect_SetVertexXY(id, 2, left, bottom);
    ObjEffect_SetVertexXY(id, 3, right, bottom);
	}
function EffectUV(id, left, top, right, bottom){
    ObjEffect_SetVertexUV(id, 0, left, top);
    ObjEffect_SetVertexUV(id, 1, right, top);
    ObjEffect_SetVertexUV(id, 2, left, bottom);
    ObjEffect_SetVertexUV(id, 3, right, bottom);
	}
function EffectColor(id, vertex, alpha, r, g, b){
    ascent(i in 0..vertex){ObjEffect_SetVertexColor(id, i, alpha, r, g, b);}
	}
task Warning {
    let symbol=CreateEffect(imgWarning, 7);
    EffectXY(symbol, -256, -64, 256, 64);
    Obj_SetPosition(symbol, GetCenterX, GetCenterY);
    
    let warning1=CreateEffect(imgWarning, 7);
    EffectXY(warning1, -256, -20, 256, 20);
    Obj_SetPosition(warning1, GetCenterX, GetCenterY+80);
    
    let warning2=CreateEffect(imgWarning, 7);
    EffectXY(warning2, -256, -20, 256, 20);
    Obj_SetPosition(warning2, GetCenterX, GetCenterY-80);
    
    let counter = 0;
    ascent(i in 0..31){
      EffectUV(symbol, counter, 0, counter+512, 128);
      EffectUV(warning1, -counter, 216, -counter+512, 256);
      EffectUV(warning2, -counter, 216, -counter+512, 256);
      EffectColor(symbol, 4, 255/30*i, 255, 255, 255);
      EffectColor(warning1, 4, 255/30*i, 255, 255, 255);
      EffectColor(warning2, 4, 255/30*i, 255, 255, 255);
      counter++;
      yield;
    }
    loop(88){
      EffectUV(symbol, counter, 0, counter+512, 128);
      EffectUV(warning1, -counter, 216, -counter+512, 256);
      EffectUV(warning2, -counter, 216, -counter+512, 256);
      counter++;
      yield;
    }
    descent(i in 0..31){
      EffectUV(symbol, counter, 0, counter+512, 128);
      EffectUV(warning1, -counter, 216, -counter+512, 256);
      EffectUV(warning2, -counter, 216, -counter+512, 256);
      EffectColor(symbol, 4, 255/30*i, 255, 255, 255);
      EffectColor(warning1, 4, 255/30*i, 255, 255, 255);
      EffectColor(warning2, 4, 255/30*i, 255, 255, 255);
      counter++;
      yield;
    }
	}
task Star{
	let angle = 0;
	SpawnStar;
	ExplosionCreate;
	loop{loop(4){
      CreateShot01(GetX + 98*cos(angle), GetY + 98*sin(angle), 4, angle, 147, 12);
      angle += 360/4;
		}
		angle += 12+rand(1,6);
		yield;
		}
	}
task ExplosionCreate{
	explosionsize= 3;
	while(explosionalpha>0){
		explosionalpha-=5;
		explosionsize+=0.1;
		yield;
		}
	}
task SpawnStar{
	size = 100; size2 = 100;
	PlaySE(SunSummon);
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, GetX, GetY);
    Obj_SetAngle(obj, 90);
    Obj_SetSpeed(obj, 0);
    ObjShot_SetGraphic(obj, 156);
    ObjShot_SetDelay  (obj, 0);
    ObjShot_SetBombResist (obj, true);
	while(Obj_BeDeleted(obj)==false) {
		Obj_SetAngle(obj, 90+spin);
		yield;
		}
	}
@MainLoop{
	SetCollisionA(GetX,GetY,size);
	SetCollisionB(GetX,GetY,size2);
	spin++;
	yield;
	}
@DrawLoop{
	DrawName("Marisa Kirisame");
	SetAlpha(255);
	if (bossflip==0){SetGraphicScale(1,1);}
	if (bossflip==1){SetGraphicScale(-1,1);}
	SetColor(255,255,255);
	SetGraphicAngle(0,0,0);
	SetTexture(Marisprite);
	SetGraphicRect(BR[0],BR[1],BR[2],BR[3]);
	DrawGraphic(GetX,GetY);
		
	SetAlpha(explosionalpha);
	SetGraphicScale(explosionsize,explosionsize);
	SetColor(255,255,255);
	SetGraphicAngle(0,0,0);
	SetTexture(Explosion);
	SetGraphicRect(0,0,62,62);
	DrawGraphic(GetX,GetY);
	}

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