#“Œ•û’e–‹•—
#Title[Everybody Clap Your Hands]
#Text[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\lib_anime_tewi.txt"
	#include_function ".\boss.txt"
	let csd		=GetCurrentScriptDirectory;
	let shotData	=csd ~ ".\shot.txt";
	let imgBoss	=csd ~ "img\dot_tewi.png";
	let imgBG1	=csd ~ "img\maho1.png";
	let imgBG2	=csd ~ "img\maho2.png";
	let BGn		=0;
	let xIni	=GetCenterX;
	let yIni	=GetClipMinY + 100;
	@Initialize {
        CutIn(YOUMU,"Everybody Clap Your Hands", "", 0, 0, 0, 0);
        SetLife(2800);
	SetTimer(40);
	SetScore(100000);
	SetDamageRate(5, 5);
	InitializeAction();
	LoadUserShotData(shotData);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBG1);
	LoadGraphic(imgBG2);
        TMain;
	}

	@MainLoop {
	BGn++;
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	yield;
	}

	@DrawLoop {
	SetColor(255,255,255);
	SetGraphicScale(1,1);
	SetAlpha(255);
	SetGraphicAngle(0,0,0);
	DrawBoss(imgBoss);
	BG;
	}

	@Finalize{
	}

function wait(w) {
    loop(w) { yield; }
}
    task TMain {
        yield;
standBy;
SetDamageRate(100,100);
moveA;
loop{
shotA;
wait(25);
shotB;
wait(230);
shotC;
shotD;
wait(30);
shotE;
}
}

task shotA {
loop(4){
let C=0;
loop(12){
let A=40;
let B=0;
loop(360/A){
let D=6;
loop(2){
CreateShot01(GetX+cos(B)*30,GetY+sin(B)*30,D,B+C,46,0);
CreateShot01(GetX+cos(B)*30,GetY+sin(B)*30,D,B-C,46,0);
D+=1.2;
}
B+=A;
}
C+=0.8;
wait(2);
}
wait(20);
}
}

task shotB {
loop(4){
let C=0;
loop(12){
let A=40;
let B=-20;
loop(360/A){
let D=6;
loop(2){
CreateShot01(GetX+cos(B)*30,GetY+sin(B)*30,D,B+C,46,0);
CreateShot01(GetX+cos(B)*30,GetY+sin(B)*30,D,B-C,46,0);
D+=1.2;
}
B+=A;
}
C-=0.8;
wait(2);
}
wait(20);
}
}

task shotC {
let A=3;
let B=270;
loop(720/A){
let C=0;
let D1=rand(10,-10);
let D2=rand(1,6);
loop(6){
let angleA=-20;
while(angleA<21){
CreateShot01(GetX+cos(B)*30,GetY+sin(B)*30,D2+C,angleA+B+D1,62,0);
angleA+=40;
}
C+=0.2;
}
wait(1);
B+=A;
}
}

sub shotD {
let A=3;
let B=270;
loop(720/A){
let C=0;
let D1=rand(10,-10);
let D2=rand(1,6);
loop(6){
let angleA=-20;
while(angleA<21){
CreateShot01(GetX+cos(B)*30,GetY+sin(B)*30,D2+C,angleA+B+D1,62,0);
angleA+=40;
}
C+=0.22;
}
wait(1);
B-=A;
}
}

sub shotE {
let A=0;
let B=0;
loop(24){
wait(6);
A=rand(0,360);
let angleA=0;
while(angleA<360){
CreateShot01(GetX,GetY,7+B,angleA+A,22,0);
angleA+=10;
}
B-=0.2;
}
}


   task moveA {
	let wMove =240;
	loop{	
	SetAction(ACT_MOVE,wMove);
	moveToPlayer(rand(40, 120), rand(-40, 40), wMove,
		GetClipMinX + 48, GetClipMinY +  50,
		GetClipMaxX - 48, GetClipMinY + 120);
	wait(wMove);
	}
	}


    sub standBy {
        let wIni = 120;

        SetMovePosition02(xIni, yIni, wIni);

        SetInvincibility(wIni);
        wait(wIni);
    }

function GetGapAngle(
	let x1,
	let y1,
	let x2,
	let y2
){
	return atan2(y2-y1,x2-x1);
}

    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;
        if(GetPlayerX < GetX) {
            x = GetX - xMove;
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            x = GetX + xMove;
            if(right < x) {
                x = GetX - xMove;
            }
        }
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }
}

}