#TouhouDanmakufu
#Title[RAN_Sp02]
#Text[Starter]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {

let frame1 = 0;
let frame2 = 0;
let frame3 = 0;
let frame4 = 0;
let frame5 = 0;
let frame6 = 0;
let a1 = 0;
let a2 = 0;
let a3 = 0;
let a4 = 0;
let acc1 = 0;
let acc2 = 0;
let acc3 = 0;
let acc4 = 0;
let acc5 = 0;
let acc6 = 0;
let random1 = 0;
let random2 = 0;
let random3 = 0;

let BossImage = GetCurrentScriptDirectory~"RanSpeed0.png";
let BossImage2 = GetCurrentScriptDirectory~"RanSpin.png";
let MC = GetCurrentScriptDirectory~"magiccircle.png";
let ShotSE = GetCurrentScriptDirectory~"ShotSE.wav";
let ShotSE2 = GetCurrentScriptDirectory~"ShotSE2.wav";
let ShotSE3 = GetCurrentScriptDirectory~"ShotSE3.wav";
let ShotSE4 = GetCurrentScriptDirectory~"ChimeSE.wav";
let ShotSE5 = GetCurrentScriptDirectory~"ChargeSE.wav";
let Death = GetCurrentScriptDirectory~"se_enep01.wav";
let Custom = GetCurrentScriptDirectory~"supershot.txt";
let BG = GetCurrentScriptDirectory~"bg.png";
let BG2 = GetCurrentScriptDirectory~"bg2.png";
let Cut = GetCurrentScriptDirectory~"cut.png";
	#include_function ".\function_cutin.txt";
	#include_function ".\maple.txt";

    @Initialize {

SetMovePosition02(GetCenterX, GetCenterY - 100, 10);
LoadGraphic(BossImage);
LoadGraphic(BossImage2);
LoadGraphic(BG);
LoadGraphic(BG2);
LoadGraphic(MC);
LoadGraphic(Cut);
LoadSE(ShotSE);
LoadSE(ShotSE2);
LoadSE(ShotSE3);
LoadSE(ShotSE4);
LoadSE(ShotSE5);
LoadSE(Death);
SetLife(1000);
SetDamageRate(30, 0);
SetTimer(60);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(12,12,12,12);
cutin("NAZRIN", "Boundary - Crushing Ruins", Cut, 0, 0, 256, 512);
SetScore(50000);
    }

    @MainLoop {
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 24);
LoadUserShotData(Custom);
yield;
task BulletA(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_GetX(obj) >= GetClipMaxX || Obj_GetX(obj) <= GetClipMinX || Obj_GetY(obj) <= GetClipMinY) {
		
            CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 1, GetAngleToPlayer, 0.05, rand(2,3), graphic, 0);
	PlaySE(ShotSE4);
	Obj_Delete(obj)
             }

             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(frame1 >= 100) {
     		Obj_SetAngle(obj, Obj_GetAngle(obj) + 1.5);
             }

             if(frame1 <= 100) {
     		Obj_SetAngle(obj, Obj_GetAngle(obj) - 1.5);
             }

             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) {

            CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, rand(0,360), 5, 5, 94, 20);
       

             yield;
      }
}
	if (frame1 == 100)
        { 
        loop(1)
        {
            CreateShot01(GetX, GetY, 5, GetAngleToPlayer, 229, 10);
            CreateShot01(GetX, GetY, 5, GetAngleToPlayer - 45, 229, 10);
            CreateShot01(GetX, GetY, 5, GetAngleToPlayer + 45, 229, 10);
        }
        loop(8)
        {
            CreateShot01(GetX, GetY, rand(3,4), GetAngleToPlayer + rand(-10,10), 202, 10);
            CreateShot01(GetX, GetY, rand(3,4), GetAngleToPlayer + rand(-10,10) - 45, 202, 10);
            CreateShot01(GetX, GetY, rand(3,4), GetAngleToPlayer + rand(-10,10) + 45, 202, 10);
        }
        loop(24)
        {
            CreateShot01(GetX, GetY, rand(2,3), GetAngleToPlayer + rand(-10,10), 38, 10);
            CreateShot01(GetX, GetY, rand(2,3), GetAngleToPlayer + rand(-10,10) - 45, 38, 10);
            CreateShot01(GetX, GetY, rand(2,3), GetAngleToPlayer + rand(-10,10) + 45, 38, 10);
        }
	frame1 = -400;
	PlaySE(ShotSE3);
	}

	if (frame1 == 30)
        { 
	StartMapleConcentrate;
	PlaySE(ShotSE5)
	}

	if (frame2 == 150)
        { 
	random1 = rand(-30,30);
        loop(15)
        {
            BulletA(GetX, GetY, rand(3,5), a1 + 180 + random1, 94, 20);
            a1 += 360/30;
        }
	a1 = 0;
	frame2 = 100;
	PlaySE(ShotSE);
	}
        frame1++;
        frame2++;
        frame3++;
	frame4++;
    }

    @DrawLoop {


SetTexture(MC);
SetRenderState(ADD);
SetGraphicAngle(0,0,acc4);
SetGraphicRect(0, 0, 128, 128);
SetGraphicScale(1+acc5,1+acc5);
SetAlpha(255);
DrawGraphic(GetX, GetY);

SetTexture(BG);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicRect(0, 0, 1000000, 1000000);
SetGraphicScale(2,2.2);
DrawGraphic(0, 0);

SetTexture(BG2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,-acc4);
SetGraphicRect(0, 0, 10000, 10000);
SetGraphicScale(1,1);
DrawGraphic(GetCenterX, GetCenterY);
acc4 += 0.5;

SetRenderState(ALPHA);
SetGraphicScale(1,1);
SetAlpha(255);
SetGraphicRect(0, 0, 64, 83);
if (GetSpeedX == 0 && GetSpeedY == 0)
{
SetTexture(BossImage);
SetGraphicAngle(0,0,0);
}
if (GetSpeedX > 0 || GetSpeedY > 0 || GetSpeedX < 0 || GetSpeedY < 0)
{
SetTexture(BossImage2);
SetGraphicAngle(0,0,acc6);
}
DrawGraphic(GetX, GetY);
frame5++;
if (frame5 <= 50)
{
acc5 += 0.01;
}
if (frame5 >= 50)
{
acc5 -= 0.01;
}
if (frame5 == 100)
{
frame5 = 0;
}

acc6 += 23;

    }

    @Finalize {
    }
}
