#TouhouDanmakufu
#Title[Spell 1]
#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 w = 1;
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\supershot.txt";
let MC = GetCurrentScriptDirectory~"ef\MC.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\Shot5.wav";
let timer = GetTimer;
let time1 = GetCurrentScriptDirectory~"se\time1.wav";
let time2 = GetCurrentScriptDirectory~"se\time2.wav";
let Cut = GetCurrentScriptDirectory~"ef\Cut.png";
	#include_function ".\cutin.dnh";
	#include_function ".\blossom.txt";

 function Wait(let frames){
   loop(frames*2){yield;}
 }

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

SetMovePosition03(GetCenterX, GetCenterY - 100, 10, 10);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
LoadUserShotData(Custom);
LoadGraphic(SP);
LoadGraphic(MC);
LoadGraphic(Cut);
LoadGraphic(CBG1);
LoadGraphic(CBG2);
LoadGraphic(NBG1);
LoadSE(charge);
LoadSE(sh1);
LoadSE(sh2);
LoadSE(sh3);

SetLife(300);
SetDamageRate(7, 18);
SetTimer(60);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(128,128,128,128);

cutin("Strange Magic "\""Prediction of Disaster"\", Cut, 0, 0, 359, 512);
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 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);
}
             }

             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 (frame2 == 60)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}
        if (frame1 == 80)
        { 
	SetMovePosition03(GetCenterX + rand(-50,50), GetCenterY - rand(100,130), 10, 2);
        }
        if (frame1 == 150 || frame1 == 165 || frame1 == 180 || frame1 == 195 || frame1==135)
        { 
        loop(10)
        {
            CreateShot02(GetX+50, GetY-50,5,atan2(GetY-50-90, GetX+50-90)+180+a3,-0.07,1,218,10);
            CreateShot02(GetX+50, GetY+50,5,atan2(GetY+50-90, GetX+50-90)+180+a3,-0.07,1,218,10);
            CreateShot02(GetX-50, GetY+50,5,atan2(GetY+50-90, GetX-50-90)+180+a3,-0.07,1,218,10);
            CreateShot02(GetX-50, GetY-50,5,atan2(GetY-50-90, GetX-50-90)+180+a3,-0.07,1,218,10);
            a3 += 360/10;
        }
	PlaySE(sh2);
	a2 += 26;
	a3 += -37;
        }
        if (frame1 == 210 || frame1==280)
        { 
        loop(20)
        {
            CreateShot02(GetX+50, GetY-50,5,a3+GetAngleToPlayer,-0.15,1,203,10);
            CreateShot02(GetX+50, GetY+50,5,a3+GetAngleToPlayer,-0.15,1,203,10);
            CreateShot02(GetX-50, GetY+50,5,a3+GetAngleToPlayer,-0.15,1,203,10);
            CreateShot02(GetX-50, GetY-50,5,a3+GetAngleToPlayer,-0.15,1,203,10);
            a3 += 360/20;
        }
	PlaySE(sh3);
	a2 += 26;
	a3 += -34;
        }
        if (frame1 == 280)
        { 
	frame1 = 61;
        }
        frame1++;
        frame2++;
        frame3++;
        frame4++;
    }

    @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, 512, 512+anim2);
SetAlpha(255);
DrawGraphic(GetCenterX, GetCenterY);

SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,anim3);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 512, 512);
SetAlpha(255);
DrawGraphic(GetCenterX, GetCenterY);

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, 96, 128);
SetAlpha(255);
DrawGraphic(GetX+5, GetY+3*sin(anim1));
}
if (GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(285, 136, 380, 264);
SetAlpha(255);
DrawGraphic(GetX, GetY+3*sin(anim1));
}
if (GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(285, 258, 380, 386);
SetAlpha(255);
DrawGraphic(GetX - 10, GetY+3*sin(anim1));
}
acc1 += 5;
acc2 += 2;
anim1 += 7;
anim2 += 0.6;
anim3 += 0.3;
acc5 += 2;
acc6 += 0.5;
acc3 = 0.2*cos(acc2);
acc4 = 55*cos(acc6);
acc7 = 100*cos(acc2);
}
    @Finalize {
SetMovePosition03(GetClipMinX-300, GetCenterY - 100, 10, 4);
    }
}
