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

script_enemy_main {

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 animationframe = 0;
let adir = 1;
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 a9 = 0;
let lifeamt = 0;
let lifetot = 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 scorecir = 0;

let SP = GetCurrentScriptDirectory~"sp\Sprite.png";
let Custom = GetCurrentScriptDirectory~"sup\supershot.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 life = GetCurrentScriptDirectory~"ef\lifebar.png";
let imgNumber = GetCurrentScriptDirectory~"ef\TNUMBER.png";
let charge = GetCurrentScriptDirectory~"se\Charge2.wav";
let sh1 = GetCurrentScriptDirectory~"se\Shot1.wav";
let sh2 = GetCurrentScriptDirectory~"se\BulletWave.wav";
let sh3 = GetCurrentScriptDirectory~"se\Shot4.wav";
let timer = GetTimer;
let time1 = GetCurrentScriptDirectory~"se\time1.wav";
let time2 = GetCurrentScriptDirectory~"se\time2.wav";
let Cut = GetCurrentScriptDirectory~"ef\Cut.png";
MagicCircle(false);
	#include_function ".\blossom.txt";
#include_function ".\AnimationLib.dnh";
	#include_function ".\lifebar.txt";



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

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

LoadUserShotData(Custom);
LoadGraphic(SP);
LoadGraphic(MC);
LoadGraphic(Cut);
LoadGraphic(CBG1);
LoadGraphic(CBG2);
LoadGraphic(NBG1);
LoadGraphic(life);
LoadGraphic(imgNumber);
LoadSE(charge);
LoadSE(sh1);
LoadSE(sh2);
LoadSE(sh3);
SetLife(360);
SetDamageRate(11, 1);
SetTimer(60);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(128,128,128,128);
InitializeAnimationData;
Animate("mima", "idle", true);
    }

    @MainLoop {
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 == 30)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}
        if (frame1 == 80 && adir == 1)
        { 
	SetMimaMoveAnimation("left");
	SetMovePosition03(GetCenterX - 50, GetCenterY - rand(100,150), 10, 5);
        }
        if (frame1 == 80 && adir == -1)
        { 
	SetMimaMoveAnimation("right");
	SetMovePosition03(GetCenterX + 50, GetCenterY - rand(100,150), 10, 5);
        }
        if (frame2 == 150)
        { 
        loop(10)
        {
            CreateShot01(GetX+30*cos(a2), GetY+30*sin(a2),3.35,a2+a3,206,10);
            a2 += 360/10;
        }
	a2 = 0;
	PlaySE(sh1);
	a3 += 17;
	frame2 = 145;
        }
        if (frame3 == 300)
        { 
        loop(10)
        {
            CreateShot01(GetX+30*cos(a2), GetY+30*sin(a2),3.35,a2-a3,207,10);
            a2 += 360/10;
        }
	a2 = 0;
	PlaySE(sh1);
	a3 += 17;
	frame2 = 0;
	frame3 = 295;
        }

        if (frame4 == 150)
        { 
        loop(10)
        {
            CreateShot01(GetX,GetY,5,GetAngleToPlayer+a5,230,10);
            a5 += 360/10;
        }
	PlaySE(sh3);
	frame4 = 60;
        }

        if (frame5 == 450)
        { 
	adir = adir*-1;
	a5+=0.4;
	frame1 = 0;
	frame2 = 0;
	frame3 = 0;
	frame4 = 0;
	frame5 = 0;
        }
if(GetLife <= 60 && GetLife > 0){
SetDamageRate(1000, 1000);}
        frame1++;
        frame2++;
        frame3++;
        frame4++;
        frame5++;
        animationframe++;
    }

    @DrawLoop {

DrawAnimatedSprite("mima",GetX,GetY);


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);
Lifebar;
SetGraphicAngle(0,0,0);



acc1 += 8;
acc2 += 2;
anim1 += 7;
anim2 += 0.4;
anim3++;
acc5 += 2;
acc3 = 0.3*cos(acc2);
a9++;
}
    @Finalize {

    }

  sub InitializeAnimationData {
    CreateAnimation("mima", "idle", 4);
    SetAnimationFrame("mima", "idle", 0, SP, 12, 0, 0, 96, 112);
    SetAnimationFrame("mima", "idle", 1, SP, 12, 96, 0, 192, 112);
    SetAnimationFrame("mima", "idle", 2, SP, 12, 192, 0, 288, 112);
    SetAnimationFrame("mima", "idle", 3, SP, 12, 288, 0, 384, 112);
    
    CreateAnimation("mima", "start move right", 4);
    SetAnimationFrame("mima", "start move right", 0, SP, 8, 0, 112, 96, 224);
    SetAnimationFrame("mima", "start move right", 1, SP, 8, 96, 112, 192, 224);
    SetAnimationFrame("mima", "start move right", 2, SP, 8, 192, 112, 288, 224);
    SetAnimationFrame("mima", "start move right", 3, SP, 8, 288, 112, 384, 224);
    
    CreateAnimation("mima", "stop move right", 3);
    SetAnimationFrame("mima", "stop move right", 0, SP, 4, 288, 112, 384, 224);
    SetAnimationFrame("mima", "stop move right", 1, SP, 4, 192, 112, 288, 224);
    SetAnimationFrame("mima", "stop move right", 2, SP, 4, 96, 112, 192, 224);
    
    CreateAnimation("mima", "start move left", 4);
    SetAnimationFrame("mima", "start move left", 0, SP, 8, 0, 224, 96, 336);
    SetAnimationFrame("mima", "start move left", 1, SP, 8, 96, 224, 192, 336);
    SetAnimationFrame("mima", "start move left", 2, SP, 8, 192, 224, 288, 336);
    SetAnimationFrame("mima", "start move left", 3, SP, 8, 288, 224, 384, 336);
    
    CreateAnimation("mima", "stop move left", 3);
    SetAnimationFrame("mima", "stop move left", 0, SP, 4, 288, 224, 384, 336);
    SetAnimationFrame("mima", "stop move left", 1, SP, 4, 192, 224, 288, 336);
    SetAnimationFrame("mima", "stop move left", 2, SP, 4, 96, 224, 192, 336);
    
    CreateAnimation("mima", "start cast", 5);
    SetAnimationFrame("mima", "start cast", 0, SP, 4, 0,336,96,448);
    SetAnimationFrame("mima", "start cast", 1, SP, 4, 96,336,192,448);
    SetAnimationFrame("mima", "start cast", 2, SP, 4, 192,336,288,448);
    SetAnimationFrame("mima", "start cast", 3, SP, 4, 288,336,384,448);
    SetAnimationFrame("mima", "start cast", 4, SP, 4, 384,336,480,448);
    
    CreateAnimation("mima", "stop cast", 4);
    SetAnimationFrame("mima", "stop cast", 0, SP, 4, 384,336,480,448);
    SetAnimationFrame("mima", "stop cast", 1, SP, 4, 288,336,384,448);
    SetAnimationFrame("mima", "stop cast", 2, SP, 4, 192,336,288,448);
    SetAnimationFrame("mima", "stop cast", 3, SP, 4, 96,336,192,448);
  }
  function Wait(t){
    loop(t){yield;}
  }
  task SetMimaMoveAnimation(direction) {
    if(direction == "left"){
      Animate("mima", "start move left", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("mima", "stop move left", false);
    }
    if(direction == "right"){
      Animate("mima", "start move right", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("mima", "stop move right", false);
    }
    Wait(12);
    Animate("mima", "idle", true);
  }







}
