Exemplo n.º 1
0
 private void DoActions(BasicStateMachine controller)
 {
     for (int i = 0; i < actions.Length; i++)
     {
         actions [i].Act(controller);
     }
 }
Exemplo n.º 2
0
    private void Move(BasicStateMachine controller)
    {
        Bounds b = controller.moveBounds.bounds;

        if (controller.moveToPoint == new Vector2(-999, -999))
        {
            float xpos = Random.Range(b.min.x, b.max.x);
            float ypos = Random.Range(b.min.y, b.max.y);
            controller.moveToPoint = new Vector2(xpos, ypos);
        }

        controller.movement = Vector2.MoveTowards(controller.thisTransform.position, controller.moveToPoint, controller.moveSpeed * Time.fixedDeltaTime);

        controller.movement = b.ClosestPoint(controller.movement);
        controller.rigidBody.MovePosition(controller.movement);

        if (controller.thisTransform.position.x < controller.moveToPoint.x)
        {
            controller.moveDirection = 1;
        }
        else
        {
            controller.moveDirection = -1;
        }
    }
Exemplo n.º 3
0
    private void Move(BasicStateMachine controller)
    {
        SStateController scon = (SStateController)controller;

        scon.thisTransform.position = scon.GetRandomLocation();
        scon.startPosition          = scon.thisTransform.position;
    }
Exemplo n.º 4
0
    private void Flee(BasicStateMachine controller)
    {
        AStateController ncon = (AStateController)controller;

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

        if (ncon.useSlowTime.value && !ncon.slowSoldierSide.value)
        {
            speed *= ncon.slowAmount.value;
        }

        Vector2 direction = ncon.thisTransform.position - ncon.aPlayer.position;

        ncon.movement = new Vector2(ncon.thisTransform.position.x, ncon.thisTransform.position.y)
                        + (new Vector2(direction.normalized.x * ncon.values.speed.x,
                                       direction.normalized.y * ncon.values.speed.y) * speed);

        ncon.movement = ncon.moveBounds.bounds.ClosestPoint(ncon.movement);
        ncon.rigidBody.MovePosition(ncon.movement);

        if (ncon.thisTransform.position.x < ncon.aPlayer.position.x)
        {
            ncon.moveDirection = -1;
        }
        else
        {
            ncon.moveDirection = 1;
        }
    }
Exemplo n.º 5
0
    private void Chase(BasicStateMachine controller)
    {
        AStateController ncon = (AStateController)controller;

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

        if (ncon.useSlowTime.value && !ncon.slowSoldierSide.value)
        {
            speed *= ncon.slowAmount.value;
        }

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


        ncon.movement = ncon.moveBounds.bounds.ClosestPoint(ncon.movement);
        ncon.rigidBody.MovePosition(ncon.movement);

        if (ncon.thisTransform.position.x < ncon.aPlayer.position.x)
        {
            ncon.moveDirection = 1;
        }
        else
        {
            ncon.moveDirection = -1;
        }
    }
    public override bool Decide(BasicStateMachine controller)
    {
        AStateController ncon = (AStateController)controller;

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

        return(false);
    }
Exemplo n.º 7
0
    public override bool Decide(BasicStateMachine controller)
    {
        float dist = Vector2.Distance(controller.moveToPoint, controller.thisTransform.position);

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

        return(false);
    }
    public override bool Decide(BasicStateMachine controller)
    {
        StateController con = (StateController)controller;

        if (con.stateTimeElapsed >= con.values.meleeTimeStartup)
        {
            return(true);
        }

        return(false);
    }
    public override bool Decide(BasicStateMachine controller)
    {
        AStateController acon = (AStateController)controller;
        float            dist = Vector2.Distance(acon.aPlayer.position, acon.thisTransform.position);

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

        return(false);
    }
Exemplo n.º 10
0
    public override bool Decide(BasicStateMachine controller)
    {
        AStateController acon = (AStateController)controller;
        float            dist = Vector2.Distance(acon.aPlayer.position, acon.thisTransform.position);

        if (dist <= acon.thisTransform.localScale.x / 2 + 0.1f)
        {
//			Debug.Log("Hit the player");
            return(true);
        }

        return(false);
    }
    public override bool Decide(BasicStateMachine controller)
    {
        AStateController ncon = (AStateController)controller;
        float            dist = Vector2.Distance(ncon.aPlayer.position, ncon.thisTransform.position);

        if (dist > 3.0f)
        {
            controller.hasAttacked = false;
            return(true);
        }

        return(false);
    }
Exemplo n.º 12
0
    private bool Wait(BasicStateMachine controller)
    {
        if (controller.waitTime == 0)
        {
            controller.waitTime         = Random.Range(controller.waitTimeLimits.minValue, controller.waitTimeLimits.maxValue);
            controller.currentWaitState = controller.GetRandomWaitState();
        }

        if (controller.stateTimeElapsed >= controller.waitTime && controller.currentWaitState == waitAction)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 13
0
    private void CheckTransitions(BasicStateMachine controller)
    {
        for (int i = 0; i < transitions.Length; i++)
        {
            bool decisionSucceeded = transitions[i].decision.Decide(controller);

            if (decisionSucceeded)
            {
                controller.TransitionToState(transitions[i].trueState);
            }
            else
            {
                controller.TransitionToState(transitions[i].falseState);
            }
        }
    }
Exemplo n.º 14
0
 public override bool Decide(BasicStateMachine controller)
 {
     return(true);
 }
Exemplo n.º 15
0
 public override void Act(BasicStateMachine controller)
 {
     PlaySfx((StateController)controller);
 }
Exemplo n.º 16
0
 public abstract void Act(BasicStateMachine controller);
Exemplo n.º 17
0
 protected override void StateChange(State currentState, State lastState, BasicStateMachine <State> stateMachine)
 {
     Debug.Log($"StateChanged to {currentState}");
 }
Exemplo n.º 18
0
 protected override void StateUpdate(State state, BasicStateMachine <State> stateMachine)
 {
 }
Exemplo n.º 19
0
 public override void Act(BasicStateMachine controller)
 {
     Flee(controller);
 }
Exemplo n.º 20
0
 public void UpdateState(BasicStateMachine controller)
 {
     DoActions(controller);
     CheckTransitions(controller);
 }
Exemplo n.º 21
0
 private void Move(BasicStateMachine controller)
 {
     controller.thisTransform.position = controller.moveBounds.bounds.ClosestPoint(controller.thisTransform.position);
     // controller.rigidBody.MovePosition(controller.movement);
 }
Exemplo n.º 22
0
 public override bool Decide(BasicStateMachine controller)
 {
     controller.finishedWaiting = Wait(controller);
     return(controller.finishedWaiting);
 }
Exemplo n.º 23
0
 public override void Act(BasicStateMachine controller)
 {
     Attack((StateController)controller);
 }
Exemplo n.º 24
0
 public abstract bool Decide(BasicStateMachine controller);