Ejemplo n.º 1
0
    private void Chase(StateController controller)
    {
        NStateController ncon = (NStateController)controller;

        float speed = ncon.values.speed.x * Time.fixedDeltaTime;      // * ncon.moveDirection;

        if (ncon.canBeSlowed.value && !ncon.slowLeftSide.value)
        {
            speed *= ncon.slowAmount.value;
        }

        ncon.movement = Vector2.MoveTowards(ncon.thisTransform.position, ncon.nPlayer.position, speed);

        ncon.movement.Set(
            Mathf.Clamp(ncon.movement.x, Constants.NormalStartX - Constants.NormalBorderWidth, Constants.NormalStartX + Constants.NormalBorderWidth),
            Mathf.Clamp(ncon.movement.y, Constants.NormalStartY - Constants.NormalBorderWidth, Constants.NormalStartY + Constants.NormalBorderWidth));

        ncon.rigidBody.MovePosition(ncon.movement);


        if (ncon.thisTransform.position.x < ncon.nPlayer.position.x)
        {
            ncon.moveDirection = 1;
        }
        else
        {
            ncon.moveDirection = -1;
        }
    }
    public override void Attack(StateController controller, AttackScript attackScript)
    {
        if (!(controller is NStateController))
        {
            Debug.LogError("Wrong controller user!");
            return;
        }

        NStateController ncon = (NStateController)controller;

        var        shotTransform = Instantiate(attackScript.projectile) as Transform;
        Projectile projectile    = shotTransform.GetComponent <Projectile>();

        shotTransform.position = ncon.thisTransform.position;
        MouseInformation info = new MouseInformation();

        info.position1 = controller.thisTransform.position;
        info.setPosition2(controller.nPlayer.position);
        if (setRotation)
        {
            float rotation = info.rotationInternal * 180 / Mathf.PI;
            shotTransform.localRotation = Quaternion.AngleAxis(rotation, Vector3.forward);
        }

        projectile.isEnemy  = true;
        projectile.multiHit = attackScript.multihit;
        projectile.lifeTime = attackScript.lifeTime;
        projectile.SetDamage(attackScript.damage, 0, 1);
        projectile.SetMovement(attackScript.speed, info.rotationInternal);

        attackScript.bgui.effectList.Add(projectile);
    }
Ejemplo n.º 3
0
    private void Move(StateController controller)
    {
        NStateController ncon = (NStateController)controller;

        if (ncon.moveToPoint == new Vector2(-5 * Constants.NormalBorderWidth, -5 * Constants.NormalBorderHeight))
        {
            float xpos = Random.Range(Constants.NormalStartX - Constants.NormalBorderWidth, Constants.NormalStartX + Constants.NormalBorderWidth);
            float ypos = Random.Range(Constants.NormalStartY - Constants.NormalBorderHeight, Constants.NormalStartY + Constants.NormalBorderHeight);
            ncon.moveToPoint = new Vector2(xpos, ypos);
        }

        ncon.movement = Vector2.MoveTowards(ncon.thisTransform.position, ncon.moveToPoint, ncon.values.speed.x * Time.fixedDeltaTime);

        ncon.movement.Set(
            Mathf.Clamp(ncon.movement.x, Constants.NormalStartX - Constants.NormalBorderWidth, Constants.NormalStartX + Constants.NormalBorderWidth),
            Mathf.Clamp(ncon.movement.y, Constants.NormalStartY - Constants.NormalBorderWidth, Constants.NormalStartY + Constants.NormalBorderWidth));

        ncon.rigidBody.MovePosition(ncon.movement);

        if (ncon.thisTransform.position.x < ncon.moveToPoint.x)
        {
            ncon.moveDirection = 1;
        }
        else
        {
            ncon.moveDirection = -1;
        }
    }
Ejemplo n.º 4
0
    private void Move(StateController controller)
    {
        NStateController ncon = (NStateController)controller;

        ncon.movement.Set(
            Mathf.Clamp(ncon.thisTransform.position.x, Constants.NormalStartX - Constants.NormalBorderWidth, Constants.NormalStartX + Constants.NormalBorderWidth),
            Mathf.Clamp(ncon.thisTransform.position.y, Constants.NormalStartY - Constants.NormalBorderWidth, Constants.NormalStartY + Constants.NormalBorderWidth));

        ncon.rigidBody.MovePosition(ncon.movement);
    }
    public override bool Decide(StateController controller)
    {
        NStateController ncon = (NStateController)controller;

        if (controller.stateTimeElapsed >= ncon.values.chaseTimeLimit)
        {
            return(true);
        }

        return(false);
    }
    public override bool Decide(StateController controller)
    {
        NStateController ncon = (NStateController)controller;
        float            dist = Vector2.Distance(ncon.moveToPoint, controller.thisTransform.position);

        if (dist <= 0.1f)
        {
            return(true);
        }

        return(false);
    }
    public override bool Decide(StateController controller)
    {
        NStateController ncon = (NStateController)controller;
        float            dist = Vector2.Distance(controller.nPlayer.position, controller.thisTransform.position);

        if (dist <= ncon.values.meleeRange)
        {
            ncon.hasAttacked = false;
            return(true);
        }

        return(false);
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Creates an enemy for the normal side of the battlefield.
    /// </summary>
    /// <param name="values"></param>
    /// <param name="group"></param>
    /// <param name="index"></param>
    private void CreateN(EnemyEntry values, EnemyGroup group)
    {
        if (!spawnBottom)
        {
            return;
        }
        ggobjN = Instantiate(values.enemyModelN) as Transform;
        NStateController    state  = ggobjN.GetComponent <NStateController>();
        HurtableEnemyScript hurt   = ggobjN.GetComponent <HurtableEnemyScript>();
        AttackScript        attack = ggobjN.GetComponent <AttackScript>();

        ggobjN.position = state.GetRandomLocation();
        hurt.group      = group;
        state.enemyid   = enemyId;
        state.values    = ScriptableObject.CreateInstance <EnemyEntry>();
        state.values.CopyValues(values);

        group.bot = hurt;
        group.nStateController = state;
        group.nTransform       = ggobjN;
        group.nAttackScript    = attack;
    }