Ejemplo n.º 1
0
 public ToRetreat(StateMachine sm_)
 {
     sm          = sm_;
     targetState = sm_.retreatState;
     condition   = new RetreatCondition(sm);
     actions     = new IAction[1];
     actions[0]  = new RetreatAction(sm);
 }
Ejemplo n.º 2
0
 public RetreatState(StateMachine sm_)
 {
     sm              = sm_;
     exitActions     = new IAction[1];
     exitActions[0]  = new RetreatAction(sm);
     entryActions    = new IAction[1];
     entryActions[0] = new RetreatAction(sm);
     actions         = new IAction[1];
     actions[0]      = new RetreatAction(sm);
     transitions     = new ITransition[4];
     transitions[1]  = new ToInitial(sm);
     transitions[0]  = new ToProjectile(sm_);
     transitions[2]  = new ToJump(sm_);
     transitions[3]  = new ToAntiAir(sm_);
 }
Ejemplo n.º 3
0
    void Start()
    {
        fsm = new FSM("Boss Ai");

        standState      = fsm.AddState("StandState");
        moveTargetState = fsm.AddState("MoveTargetState");
        retreatState    = fsm.AddState("RetreatState");
        runTargetState  = fsm.AddState("RunTargetState");
        jumpState       = fsm.AddState("JumpState");


        standAction      = new StandAction(standState);
        moveTargetAction = new MoveTargetAction(moveTargetState);
        retreatAction    = new RetreatAction(retreatState);
        runTargetAction  = new MoveTargetAction(runTargetState);
        jumpAction       = new JumpAction(jumpState);


        finishEventRun = new List <string>
        {
            "to move target",
            "to retreat",
            "to stand",
            "to jump"
        };

        finishEventStand = new List <string>
        {
            "to move target",
            "to retreat",
            "to run",
            "to jump"
        };

        finishEventMoveTarget = new List <string>
        {
            "to move target",
            "to stand",
            "to retreat",
            "to jump"
        };
        finishEventRetreat = new List <string>
        {
            "to stand",
            "to run"
        };
        finishEventJump = new List <string>
        {
            "to stand"
        };


        standState.AddAction(standAction);

        runTargetState.AddAction(runTargetAction);

        moveTargetState.AddAction(moveTargetAction);

        retreatState.AddAction(retreatAction);

        jumpState.AddAction(jumpAction);

        standState.AddTransition("to move target", moveTargetState);
        standState.AddTransition("to retreat", retreatState);
        standState.AddTransition("to run", runTargetState);
        standState.AddTransition("to jump", jumpState);

        moveTargetState.AddTransition("to move target", moveTargetState);
        moveTargetState.AddTransition("to stand", standState);
        moveTargetState.AddTransition("to retreat", retreatState);
        moveTargetState.AddTransition("to jump", jumpState);

        retreatState.AddTransition("to stand", standState);
        retreatState.AddTransition("to run", runTargetState);

        runTargetState.AddTransition("to move target", moveTargetState);
        runTargetState.AddTransition("to stand", standState);
        runTargetState.AddTransition("to retreat", retreatState);
        runTargetState.AddTransition("to jump", jumpState);

        jumpState.AddTransition("to stand", standState);



        vecPos     = GameObject.Find("Boss").transform.position;
        vecEnnemis = new Vector3(0.1f, 0, 0);
        vecJump    = new Vector3(0f, 0.15f, 0);


        moveTargetAction.init(this.transform, vecEnnemis, 2.0f, finishEventMoveTarget);
        retreatAction.init(this.transform, vecEnnemis, 0.5f, finishEventRetreat);
        runTargetAction.init(this.transform, new Vector3(0.3f, 0, 0), 1.0f, finishEventRun);
        jumpAction.init(this.transform, vecJump, 2f, finishEventJump);

        standAction.init(1.0f, finishEventStand);

        fsm.Start("StandState");
    }