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

script_enemy_main {

let y = 0;
let x = 0;
let m = 0;
let b = 0;

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 taska1 = 0;
let adir = 1;
let adir2 = 1;
let anim1 = 0;
let anim2 = 0;
let anim3 = 0;
let anim4 = 0;
let anim5 = 0;
let anim6 = 0;
let a1 = 90;
let a2 = 0;
let a3 = 2;
let a4 = 0;
let a5 = 195;
let a6 = 0;
let a7 = 0;
let a8 = 0;
let a9 = 0;
let a10 = 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\supershot2.txt";
let MC = GetCurrentScriptDirectory~"ef\MC.png";
let CBG1 = GetCurrentScriptDirectory~"ef\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"ef\CBG2.png";
let CBG3 = GetCurrentScriptDirectory~"ef\CBG3.png";
let NBG1 = GetCurrentScriptDirectory~"ef\nbg1.png";
let life = GetCurrentScriptDirectory~"ef\lifebar.png";
let MC2 = GetCurrentScriptDirectory~"ef\Flower.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\Laser1.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 ".\cutin.txt";
	#include_function ".\AnimationLib.dnh";



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

SetMovePosition03(GetCenterX, GetCenterY - 100, 10, 10);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");

LoadUserShotData(Custom);
LoadGraphic(SP);
LoadGraphic(MC);
LoadGraphic(MC2);
LoadGraphic(Cut);
LoadGraphic(CBG1);
LoadGraphic(CBG2);
LoadGraphic(CBG3);
LoadGraphic(NBG1);
LoadGraphic(life);
LoadGraphic(imgNumber);
LoadSE(charge);
LoadSE(sh1);
LoadSE(sh2);
LoadSE(sh3);
SetLife(60);
SetDamageRate(1.8, 0);
SetTimer(60);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(500,500,500,500);
InitializeAnimationData;
Animate("mima", "idle", true);


cutin("NAZRIN", "Death Sign 'Bloody Knife'", Cut, 0, 0, 300, 450);
SetScore(50000);
    }

    @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 BulletA(x,y,v,angle,graphic,delay) {
     let obj=Obj_Create(OBJ_SHOT);
     let taskf = 0;
     let taskf2 = 0;
     let taska2 = 0;

     Obj_SetPosition(obj, x, y);
     Obj_SetAngle(obj, angle);
     Obj_SetSpeed(obj, v);
     //Obj_SetAlpha(obj,100);
     ObjShot_SetGraphic(obj, graphic);
     ObjShot_SetDelay  (obj, delay);

     while(Obj_BeDeleted(obj)==false) {

if (taskf2 <= 150){
     //Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj)));
}

if (taskf == 5){
            CreateShot02(Obj_GetX(obj),Obj_GetY(obj),0,Obj_GetAngle(obj)-180,0.03,NULL,150,20);

taskf = 0;
}
taskf++;
taskf2++;
             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_GetX(obj)<GetClipMinX){
		loop(1){
CreateShot01(Obj_GetX(obj)+0.1, Obj_GetY(obj), 1, rand(0,360), graphic + 1, 0);
}
Obj_Delete(obj);
             }
             if(Obj_GetX(obj)>GetClipMaxX){
		loop(1){
CreateShot01(Obj_GetX(obj)-0.1, Obj_GetY(obj), 1, rand(0,360), graphic + 1, 0);
}
Obj_Delete(obj);
             }
             if(Obj_GetY(obj)<GetClipMinY){
		loop(1){
CreateShot01(Obj_GetX(obj), Obj_GetY(obj)+0.1, 1, rand(0,360), graphic + 1, 0);
}
Obj_Delete(obj);
             }
             if(Obj_GetY(obj)>GetClipMaxY){
		loop(1){
CreateShot01(Obj_GetX(obj), Obj_GetY(obj)-0.1, 1, rand(0,360), graphic + 1, 0);
}
Obj_Delete(obj);
             }

             yield;
      }
}
        if (frame5 == 30)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}
        if (frame3 == 120)
        { 
        loop(3)
        {
            CreateShot02(GetPlayerX+60*cos(a8), GetPlayerY+60*sin(a8),3,a8,-0.05,-2,147,10);
	a8 += 360/3;
        }
	PlaySE(sh1);
	frame3 = 114;
        }
        if (frame4 == 120)
        { 
	a1 += 1;
	a4 = 30*cos(a1);

	a2 += 3;
	a3 = 60*cos(a2);

            CreateLaser01(GetX, GetY-50,5,a3+a4,200,20,2,10);
            CreateLaser01(GetX, GetY-50,5,-a3-180+a4,200,20,2,10);

	PlaySE(sh2);
	frame4 = 117;
        }
        frame1++;
        frame2++;
        frame3++;
        frame4++;
        frame5++;
        animationframe++;
    }



	@DrawLoop{


let SP = GetCurrentScriptDirectory~"sp\Sprite.png";
let MC = GetCurrentScriptDirectory~"ef\MC.png";
let CBG1 = GetCurrentScriptDirectory~"ef\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"ef\CBG2.png";




SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(0, anim2, 416, 1024+anim2);
SetAlpha(255);
SetColor(150+acc7,30,120+acc4);
DrawGraphic(GetCenterX, GetCenterY);

SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1);
SetGraphicRect(0, -anim2, 416, 1024-anim2);
SetAlpha(100);
SetColor(150+acc7,130,120+acc4);
DrawGraphic(GetCenterX, GetCenterY+10);

SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(0.5+acc8,0.5+acc8);
SetGraphicRect(0, 0, 480, 480);
SetAlpha(100);
SetColor(100+acc4,0,255);
DrawGraphic(GetCenterX, GetCenterY);

SetTexture(CBG3);
SetRenderState(ADD);
SetGraphicAngle(0,0,45);
SetGraphicScale(0.8*cos(acc9),0.8*sin(acc9));
SetGraphicRect(0, 0, 480, 480);
SetAlpha(255);
SetColor(255,255,255);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG3);
SetRenderState(ADD);
SetGraphicAngle(0,0,45);
SetGraphicScale(0.8*cos(acc9-5),0.8*sin(acc9-5));
SetGraphicRect(0, 0, 480, 480);
SetAlpha(255);
SetColor(0,100,255);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG3);
SetRenderState(ADD);
SetGraphicAngle(0,0,45);
SetGraphicScale(0.8*cos(acc9-10),0.8*sin(acc9-10));
SetGraphicRect(0, 0, 480, 480);
SetAlpha(255);
SetColor(0,100,255);
DrawGraphic(GetCenterX, GetCenterY);

SetTexture(MC2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,a9);
SetGraphicScale(0.7,0.7);
SetGraphicRect(0, 0, 342, 333);
SetAlpha(200);
SetColor(100,0,255);
DrawGraphic(GetX, GetY);

SetTexture(MC2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,-a9);
SetGraphicScale(0.5,0.5);
SetGraphicRect(0, 0, 342, 333);
SetAlpha(250);
SetColor(100,0,255);
DrawGraphic(GetX, GetY);

loop(3){
SetTexture(MC2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,a9);
SetGraphicScale(0.1,0.1);
SetGraphicRect(0, 0, 342, 333);
SetAlpha(230);
SetColor(100,0,255);
DrawGraphic(GetPlayerX+60*cos(a8), GetPlayerY+60*sin(a8));
a8 += 360/3;
}
loop(10){
SetTexture(MC2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,a9);
SetGraphicScale(0.3,0.3);
SetGraphicRect(0, 0, 342, 333);
SetAlpha(230);
SetColor(100,0,255);
DrawGraphic(GetX+140*cos(a10), GetY+140*sin(a10));
a10 += 360/10;
}
a8 -= 1;
a9++;
a10 -= 1;

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


acc1 += 5;
acc2 += 2;
anim1 += 7;
anim2 += 0.6;
anim3++;
acc5 += 2;
acc6 += 0.5;
acc3 = 0.2*cos(acc2);
acc4 = 55*cos(acc6);
acc7 = 0.5*cos(acc2);
acc8 = 0.06*cos(acc2);
acc9 += 0.7;

SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
DrawAnimatedSprite("mima",GetX,GetY);
}
    @Finalize {
	if(GotSpellCardBonus==true){ PlaySE(GetCurrentScriptDirectory~".\se\capture.wav");
CreateItem(ITEM_BOMB,GetX,GetY); }
	if(GotSpellCardBonus==false){ PlaySE(GetCurrentScriptDirectory~".\se\fail.wav"); }

loop(20){
CreateItem(ITEM_SCORE,GetX + 20*cos(scorecir+20),GetY + 20*sin(scorecir+20));
CreateItem(ITEM_SCORE,GetX + 30*cos(scorecir+30),GetY + 30*sin(scorecir+30));
CreateItem(ITEM_SCORE,GetX + 40*cos(scorecir+40),GetY + 40*sin(scorecir+40));
CreateItem(ITEM_SCORE,GetX + 50*cos(scorecir+50),GetY + 50*sin(scorecir+50));
scorecir += 360/20;
}
    }

  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);
  }







}
