


script_enemy_main {
	let imgBoss     = "script\l\img\dot_yuyuko.png";
	#include_function ".\lib\lib_anime_Yuyuko.txt"
	let cx=GetCenterX();
	@Initialize {
		SetX(GetCenterX);
        SetY(GetClipMinY + 120);
        SetLife(5000);
        SetTimer(50);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
        SetGraphicRect(0, 0, 128, 128);
        InitializeAction();
        
		TMain;
	}
		@MainLoop {
        SetCollisionA(GetX, GetY, 24);
        SetCollisionB(GetX, GetY, 24);

        yield;
       }
       @DrawLoop {
        DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
        loop(8)
		{
			CreateItem(ITEM_SCORE,cx+rand(-100,100),rand(20,100));
		}
    }
    task TMain {
        yield;
        BossShotNA;
        RandomShotNA;
	    loop{    
        TMove;
      }
      }

sub TMove {
        
        loop(50) { 

        moveToPlayer(rand(40, 80), rand(-40, 40), 60,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
        SetAction( ACT_MOVE, 50 );
        wait(60)
      }
      }
      
      task BossShotNA {
		loop{
		let ntx = 0;
		loop(24) {
		let NB = 1;
		let angle = GetAngleToPlayer + ntx;
		CreateShotA(NB, GetX, GetY, 0);
		SetShotDataA(NB, 0, 2, angle, 5, 0, 2, RED22);
		SetShotDataA(NB, 60, 0, NULL, 0, 0, 0, RED22);
		SetShotDataA(NB, 61, 3.5, NULL, 0, 0, 3.5, RED22);		
		FireShot(NB);
		SetAction( ACT_SHOT_A, 40 );
		ntx += 15;
	}
		wait(30);
	}
}
	task RandomShotNA {
		loop{
		let ntx = 0;
		let rX = rand(GetClipMinX, GetClipMaxX);
		let rY = rand(GetClipMinY, GetClipMinY + 200);
		loop(24) {
		let NB = 2;
		let angle = GetAngleToPlayer + ntx;
		CreateShotA(NB, rX, rY, 0);
		SetShotDataA(NB, 0, 2, angle, 5, 0, 2, BLUE22);
		SetShotDataA(NB, 60, 0, NULL, 0, 0, 0, BLUE22);
		SetShotDataA(NB, 61, 3.5, NULL, 0, 0, 3.5, BLUE22);		
		FireShot(NB);
		ntx += 15;
	}
		wait(40);
	}
}


      
      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);
        
    }
      sub setGraphicMove {
        if(GetSpeedX < 0) {
            SetAction( ACT_MOVE_L, 1 );
        } else {
            SetAction( ACT_MOVE_R, 1 );
        } 
       }
       function wait(w) {
        loop(w) { yield; }
    }
}