#TouhouDanmakufu
#Title[Nonspell 1]
#Text[By Shockman2.]
#Player[FREE]
#BGM[.\mu\bgm.mp3]
#ScriptVersion[2]

script_enemy_main {
let f = true;
let imglifebar = GetCurrentScriptDirectory~"lifebar_thWW.png";
let frame1 = -30;
let frame2 = 0;
let frame3 = 0;
let frame4 = 0;
let frame5 = 0;
let frame6 = 0;
let frame7 = 0;
let frame8 = 0;
let frame9 = 0;
let frame10 = 0;
let frame11 = 0;
let anim1 = 0;
let anim2 = 0;
let anim3 = 0;
let anim4 = 0;
let anim5 = 0;
let anim6 = 0;
let a1 = 0;
let a2 = 0;
let a3 = 0;
let a4 = 0;
let a5 = 0;
let a6 = 0;
let a7 = 0;
let a8 = 0;
let acc1 = 0;
let acc2 = 0;
let acc3 = 0;
let acc4 = 0;
let acc5 = 0;
let acc6 = 0;
let acc7 = 0;
let acc8 = 0;
let acc9 = 0;
let acc10 = 0;
let acc11 = 0;
let acc12 = 0;
let random1 = 0;
let random2 = 0;
let random3 = 0;
let random4 = 0;

let SP = GetCurrentScriptDirectory~"sp\Sprite.png";
let Custom = GetCurrentScriptDirectory~"sup\shot.txt";
let MC = GetCurrentScriptDirectory~"ef\NMC.png";
let CBG1 = GetCurrentScriptDirectory~"ef\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"ef\CBG2.png";
let NBG1 = GetCurrentScriptDirectory~"ef\nbg1.png";
let charge = GetCurrentScriptDirectory~"se\Charge2.wav";
let sh1 = GetCurrentScriptDirectory~"se\Shot1.wav";
let sh2 = GetCurrentScriptDirectory~"se\BulletWave.wav";
let sh3 = GetCurrentScriptDirectory~"se\Laser1.wav";
let timer = GetTimer;
let time1 = GetCurrentScriptDirectory~"sfx\time1.wav";
let time2 = GetCurrentScriptDirectory~"sfx\time2.wav";
let Cut = GetCurrentScriptDirectory~"ef\Cut.png";
	#include_function ".\blossom.txt";

    @Initialize {
LoadGraphic(imglifebar); 
	LoadSE(time1);
LoadSE(time2);

SetMovePosition03(GetCenterX, GetCenterY - 100, 10, 10);

LoadUserShotData(Custom);
LoadGraphic(SP);
LoadGraphic(MC);
LoadGraphic(Cut);
LoadGraphic(CBG1);
LoadGraphic(CBG2);
LoadGraphic(NBG1);
LoadSE(charge);
LoadSE(sh1);
LoadSE(sh2);
LoadSE(sh3);

SetLife(1000);
SetDamageRate(40, 40);
SetTimer(60);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(128,128,128,128);
    }

    @MainLoop {
if(f){
		 CreateLifebar(0);
	f=false;} 

yield;



if(GetTimer!=timer && (GetTimer < 10 && GetTimer>3)){
	PlaySE(time1);
	}

	if(GetTimer!=timer && GetTimer < 4){
	PlaySE(time2);
	

	
}
timer = GetTimer;

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 24);
yield;
task BulletB(x,y,v,angle,graphic,delay) {
     let obj=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj, x, y);
     Obj_SetAngle(obj, angle);
     Obj_SetSpeed(obj, v);
     ObjShot_SetGraphic(obj, graphic);
     ObjShot_SetDelay  (obj, delay);
     ObjShot_SetBombResist (obj, true);

     while(Obj_BeDeleted(obj)==false) {

             if(Obj_GetY(obj) >= GetCenterY) {
		loop(1){
BulletC(Obj_GetX(obj), Obj_GetY(obj), 2, angle, graphic + 1, 0);
}
Obj_Delete(obj);
             }

             yield;
      }
}
task BulletC(x,y,v,angle,graphic,delay) {
     let obj=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj, x, y);
     Obj_SetAngle(obj, angle);
     Obj_SetSpeed(obj, v);
     ObjShot_SetGraphic(obj, graphic);
     ObjShot_SetDelay  (obj, delay);
     ObjShot_SetBombResist (obj, true);

     while(Obj_BeDeleted(obj)==false) {

             if(Obj_GetY(obj) >= GetCenterY + 100 + acc5) {
		loop(1){
CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 5, rand(0,180), graphic + 1, 0);
}
Obj_Delete(obj);
             }

             yield;
      }
}
        if (frame1 == 60)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}
        if (frame1 == 80)
        { 
	SetMovePosition02(GetCenterX + rand(-50,50), GetCenterY - rand(100,150), 40);
        }
        if (frame1 == 120)
        { 
        loop(20)
        {
            CreateShot02(GetX+10*cos(-a4), GetY+10*sin(-a4),7,-a4,-0.15,1,188,10);
            CreateShot01(GetX+10*cos(a4*3), GetY+10*sin(a4*3),2,a4*3,189,10);
            a4 += 360/20;
        }
	PlaySE(sh2);
	a2 += 3;
	a3 += 12;
	a4+=0.7*cos(a3);
	frame1 = 100;
        }
        frame1++;
        frame2++;
        frame3++;
        frame4++;
    }

    @DrawLoop {

SetTexture(MC);
SetRenderState(ADD);
SetGraphicAngle(0,0,-acc1);
SetGraphicScale(2+acc3,2+acc3);
SetGraphicRect(0, 0, 128, 128);
SetAlpha(255);
SetColor(255,255,255);
DrawGraphic(GetX, GetY);

if (GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 67, 95);
SetAlpha(255);
DrawGraphic(GetX+5, GetY+3*sin(anim1));
}
if (GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(196, 99, 246, 184);
SetAlpha(255);
DrawGraphic(GetX, GetY+3*sin(anim1));
}
if (GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1);
SetGraphicRect(196, 99, 246, 184);
SetAlpha(255);
DrawGraphic(GetX - 10, GetY+3*sin(anim1));
}
acc1 += 8;
acc2 += 2;
anim1 += 7;
anim2 += 0.4;
anim3++;
acc5 += 2;
acc3 = 0.3*cos(acc2);
}
    @Finalize {
	DeleteGraphic(imglifebar);
    }

task CreateLifebar(type) {
	let initlife = GetLife; yield;
	let sides=80;
	let totalradius=64;
	let repeat=2;
	let Z=-90;
	let IN=0;
	let OUT=8;
	task lifeseparation {
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imglifebar);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0, 16, 0);
		ObjEffect_SetVertexUV(obj, 1, 24, 0);
		ObjEffect_SetVertexUV(obj, 2, 24, 11);
		ObjEffect_SetVertexUV(obj, 3, 16, 11);
		ObjEffect_SetVertexXY(obj, 0, -4, -11/2);
		ObjEffect_SetVertexXY(obj, 1, 4, -11/2);
		ObjEffect_SetVertexXY(obj, 2, 4, 11/2);
		ObjEffect_SetVertexXY(obj, 3, -4, 11/2);
		let totalradius_ = totalradius+OUT*3/4;
		ObjEffect_SetScale(obj, 1, 5/4);
		loop { ObjEffect_SetAngle(obj, 0, 0, 90+360*0.15); Obj_SetPosition(obj, GetX+totalradius_*cos(-90-360*0.15), GetY+totalradius_*sin(-90-360*0.15)); yield; }
	}
	let objL = Obj_Create(OBJ_EFFECT);
	let objB = Obj_Create(OBJ_EFFECT);
	if(type == 0 || type == 1) { lifeseparation; }
	ascent(n in 0..2) {
		let d=0;
		let objid = [objB, objL][n];
		Obj_SetX(objid,GetX);
		Obj_SetY(objid,GetY);
		ObjEffect_SetScale(objid,1,1);
		ObjEffect_SetPrimitiveType(objid,PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(objid,ALPHA);
		ObjEffect_SetTexture(objid,imglifebar);
		ObjEffect_CreateVertex(objid,2+sides*2);
		ascent(i in 0..sides+1){
			ObjEffect_SetVertexUV(objid,i*2,8+8*n,d*repeat/sides);
			ObjEffect_SetVertexUV(objid,i*2+1,8*n,d*repeat/sides);
			d+=-256;
		}
	}
	if(type!=0 && type!=1 && type!=2){type=2}
	let expand = [0, 1, 0, 0][type];
	let this = [0.85, 0.15, 1][type];
	let left = [0.15, 0, 0][type];
	loop {
		Obj_SetPosition(objL, GetX, GetY);
		Obj_SetPosition(objB, GetX, GetY);
		let ratio = GetLife/initlife*this+left; if(expand<1){expand+=1/15;}else if(expand>1){expand=1}
		ascent(i in 0..sides+1){
			let radiusINX=(totalradius+IN)*cos(i*360*ratio*expand/sides+Z);
			let radiusINY=(totalradius+IN)*sin(i*360*ratio*expand/sides+Z);
			let radiusOUTX=(totalradius+OUT)*cos(i*360*ratio*expand/sides+Z);
			let radiusOUTY=(totalradius+OUT)*sin(i*360*ratio*expand/sides+Z);
			ObjEffect_SetVertexXY(objL,i*2,-radiusINX,radiusINY);
			ObjEffect_SetVertexXY(objL,i*2+1,-radiusOUTX,radiusOUTY);
			let radiusINX=(totalradius+IN)*cos(i*360*expand/sides+Z);
			let radiusINY=(totalradius+IN)*sin(i*360*expand/sides+Z);
			let radiusOUTX=(totalradius+OUT)*cos(i*360*expand/sides+Z);
			let radiusOUTY=(totalradius+OUT)*sin(i*360*expand/sides+Z);
			ObjEffect_SetVertexXY(objB,i*2,-radiusINX,radiusINY);
			ObjEffect_SetVertexXY(objB,i*2+1,-radiusOUTX,radiusOUTY);
		}
		yield;
	}
}
}
