e@u#vĉ
#Title[ev[g]
#Text[ev[gp̃t@CȂ̂ŎsȂŉ]
#ScriptVersion[2]

script_enemy_main {
    //ʏݒ
    #include_function ".\INCLUDE\BOSS_INI.txt"

    let name        = "XyJ";

    let wIni    = 100;

    //TMain^XNOɂ镔͊{IɕҏWȂ
    @Initialize {
        SetMovePosition02(GetCenterX, GetClipMinY + 120, wIni);
        SetX(GetCenterX);
        SetY(GetClipMinY + 120);

        thMCutIn(1,name);
        SetLife(2000);			//CtiύXj
        SetTimer(99);			//^C}[iύXj
        SetScore(4000000);		//XRAiύXj

        LoadGraphicthM;
        SetTexture(imgBoss);

        SetInvincibility(wIni);
        SetDamageRate(50, 0);

        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 24);
        SetCollisionB(GetX, GetY, 24);

        yield; 
    }

    @DrawLoop {
        BossDraw(1);
    }

    @Finalize {
	SpellClear;
        DeleteGraphic(imgBoss);
    }

    @BackGround {
	BgDraw;
    }


//==========================================================================================

    // C^XNiʂ͂ȍ~ҏWĂj
    task TMain {
        yield;
        loop(wIni) { yield; }

	//ɒe^XNƂݒu
	Bom;		//{ɂ_[W

	tShot01;
        //tShot02;
	//tShot03;	//ݒuĂnj
    }

    task tShot01{
	//ɕϐ錾Ƃ
	let f = 25;	//ˊԊu

	//yieldĂ܂
	yield;
	
	loop{
		//ɋ̓IȒee
		
		wait(f);
	}
    }

    // ړ
    task move { 
        yield;

        //loop {
         //   loop(200) { yield; }
            moveToPlayer(rand(40, 80), rand(-40, 40), 60,
                         GetClipMinX + 32, GetClipMinY + 32,
                         GetClipMaxX - 32, GetClipMinY + 160);
        //}
    }


//==========================================================================================-


    // ȂׂvC[̕Ɉړ
    //   xMove  : x ̈ړʁi̐j
    //   yAdd   : y ̈ړ
    //   frame  : ړɗvt[
    //   left   : ȉA͈
    //   top    :
    //   right  :
    //   bottom :
    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;

        if(GetPlayerX < GetX) {
            // vC[EɓG΁AG͍ɓ܂B
            x = GetX - xMove;

            // AAG̈̍[ɂ悤ȂAEɓ܂B
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            // Ȃ΁AG͉Eɓ܂B
            x = GetX + xMove;

            // AAG̈̉E[Eɂ悤ȂAɓ܂B
            if(right < x) {
                x = GetX - xMove;
            }
        }

        // ̈̊Oɍsꍇ́A[Ŏ~߂܂B
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }

    // w t[҂
    function wait(w) {
        loop(w) { yield; }
    }

}