#TouhouDanmakufu
#Title[Animation Lib Test]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
  #include_function ".\AnimationLib.dnh"
  let imgNue = GetCurrentScriptDirectory ~ "Nue.png";
  let imgNazrin = GetCurrentScriptDirectory ~ "Nazrin.png";
  @Initialize {
    SetLife(1);
    SetY(-120);
    LoadGraphic(imgNue);
    LoadGraphic(imgNazrin);
    InitializeAnimationData;
    PlayMusic(GetCurrentScriptDirectory ~ "Nue.mp3");
    Animate("nue", "idle", true);
   
    ShowOffNueAnimation;
    
  }
  
  @MainLoop {
    yield ;
  }
  
  @DrawLoop {
    DrawAnimatedSprite("nue", GetX, GetY);
   
  }
  
  @Finalize {
    DeleteGraphic(imgNue);
   
  }
  
 
  
  task ShowOffNueAnimation {
  
    Wait(120);
    loop {
      SetMovePosition03(GetClipMinX+75, GetClipMinY+rand(80, 120), 20, 4);
      SetNueMoveAnimation("left");
      yield ;
      while(GetSpeed>0.1){yield;}
      Wait(30);
      Animate("nue", "start cast", false);
      Wait(120);
      Animate("nue", "stop cast", false);
      Wait(16);
      Animate("nue", "idle", true);
      Wait(60);
      SetMovePosition03(GetClipMaxX-75, GetClipMinY+rand(80, 120), 20, 4);
      SetNueMoveAnimation("right");
      yield ;
      while(GetSpeed>0.1){yield;}
      Wait(30);
      Animate("nue", "start cast", false);
      Wait(120);
      Animate("nue", "stop cast", false);
      Wait(16);
      Animate("nue", "idle", true);
      Wait(60);
    }
  }
  
  task SetNueMoveAnimation(direction) {
    if(direction == "left"){
      Animate("nue", "start move left", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("nue", "stop move left", false);
    }
    if(direction == "right"){
      Animate("nue", "start move right", false);
      yield ;
      while(GetSpeed>0.1){
        yield ;
      }
      Animate("nue", "stop move right", false);
    }
    Wait(12);
    Animate("nue", "idle", true);
  }
  
  function Wait(t){
    loop(t){yield;}
  }
  
  sub InitializeAnimationData {
    CreateAnimation("nue", "idle", 4);
    SetAnimationFrame("nue", "idle", 0, imgNue, 12, 0, 0, 96, 112);
    SetAnimationFrame("nue", "idle", 1, imgNue, 12, 96, 0, 192, 112);
    SetAnimationFrame("nue", "idle", 2, imgNue, 12, 192, 0, 288, 112);
    SetAnimationFrame("nue", "idle", 3, imgNue, 12, 288, 0, 384, 112);
    
    CreateAnimation("nue", "start move right", 4);
    SetAnimationFrame("nue", "start move right", 0, imgNue, 8, 0, 112, 96, 224);
    SetAnimationFrame("nue", "start move right", 1, imgNue, 8, 96, 112, 192, 224);
    SetAnimationFrame("nue", "start move right", 2, imgNue, 8, 192, 112, 288, 224);
    SetAnimationFrame("nue", "start move right", 3, imgNue, 8, 288, 112, 384, 224);
    
    CreateAnimation("nue", "stop move right", 3);
    SetAnimationFrame("nue", "stop move right", 0, imgNue, 4, 288, 112, 384, 224);
    SetAnimationFrame("nue", "stop move right", 1, imgNue, 4, 192, 112, 288, 224);
    SetAnimationFrame("nue", "stop move right", 2, imgNue, 4, 96, 112, 192, 224);
    
    CreateAnimation("nue", "start move left", 4);
    SetAnimationFrame("nue", "start move left", 0, imgNue, 8, 0, 224, 96, 336);
    SetAnimationFrame("nue", "start move left", 1, imgNue, 8, 96, 224, 192, 336);
    SetAnimationFrame("nue", "start move left", 2, imgNue, 8, 192, 224, 288, 336);
    SetAnimationFrame("nue", "start move left", 3, imgNue, 8, 288, 224, 384, 336);
    
    CreateAnimation("nue", "stop move left", 3);
    SetAnimationFrame("nue", "stop move left", 0, imgNue, 4, 288, 224, 384, 336);
    SetAnimationFrame("nue", "stop move left", 1, imgNue, 4, 192, 224, 288, 336);
    SetAnimationFrame("nue", "stop move left", 2, imgNue, 4, 96, 224, 192, 336);
    
    CreateAnimation("nue", "start cast", 5);
    SetAnimationFrame("nue", "start cast", 0, imgNue, 4, 0,336,96,448);
    SetAnimationFrame("nue", "start cast", 1, imgNue, 4, 96,336,192,448);
    SetAnimationFrame("nue", "start cast", 2, imgNue, 4, 192,336,288,448);
    SetAnimationFrame("nue", "start cast", 3, imgNue, 4, 288,336,384,448);
    SetAnimationFrame("nue", "start cast", 4, imgNue, 4, 384,336,480,448);
    
    CreateAnimation("nue", "stop cast", 4);
    SetAnimationFrame("nue", "stop cast", 0, imgNue, 4, 384,336,480,448);
    SetAnimationFrame("nue", "stop cast", 1, imgNue, 4, 288,336,384,448);
    SetAnimationFrame("nue", "stop cast", 2, imgNue, 4, 192,336,288,448);
    SetAnimationFrame("nue", "stop cast", 3, imgNue, 4, 96,336,192,448);
 
  }
}