Ejemplo n.º 1
0
 public override State HandleInput(Player player, StateInput input)
 {
     if (input == StateInput.KeyUp)
     {
         hDir = HorizDir.Null;
         vDir = VertDir.Null;
     }
     switch (input)
     {
         case StateInput.LeftKeyPress:
             hDir = HorizDir.Left;
             break;
         case StateInput.RightKeyPress:
             hDir = HorizDir.Right;
             break;
         case StateInput.UpKeyPress:
             vDir = VertDir.Up;
             break;
         case StateInput.DownKeyPress:
             vDir = VertDir.Down;
             break;
         case StateInput.Hit:
             player.TakeHit(1);
             break;
         case StateInput.Null:
             return new Idle();
         default:
             break;
     }
     if (player.velocity == Vector2.Zero)
         animState = AnimState.Idle;
     else
         animState = AnimState.Walking;
     return base.HandleInput(player, input, this);
 }
Ejemplo n.º 2
0
    public bool UpdateStateInput(Transform objectPosition, ref StateInput objectInput)
    {
        if (postponeMoveActions)
        {
            return(false);
        }

        for (int i = 0; i < pointMoveActions.Length; i++)
        {
            pointMoveActions[i].ApplyToObject(objectPosition, ref objectInput);
        }

        if (nextPoint == null)
        {
            return(false);
        }

        bool result = false;

        if (pointMoveActions.Length != 0)
        {
            if (pointMoveActions.All(a => a.ChangePoint(objectPosition)))
            {
                result = pointWeaponAction == null || pointWeaponAction.ChangePoint();
            }
        }
        else
        {
            result = pointWeaponAction != null && pointWeaponAction.ChangePoint();
        }

        return(result);
    }
Ejemplo n.º 3
0
 public override State HandleInput(Player player, StateInput input)
 {
     switch (input)
     {
         case StateInput.LeftKeyPress:
             if (Math.Abs(player.velocity.X) >= (player.maxSpeed * 0.75f))
                 return new Running(-1);
             direction = Direction.Left;
             player.flip = SpriteEffects.FlipHorizontally;
             break;
         case StateInput.RightKeyPress:
             if (Math.Abs(player.velocity.X) >= (player.maxSpeed * 0.75f))
                 return new Running(1);
             direction = Direction.Right;
             player.flip = SpriteEffects.None;
             break;
         case StateInput.AttackKeyPress:
             return new Attacking(this);
         case StateInput.AnimEnd:
             break;
         case StateInput.UpKeyPress:
             player.Jump(1);
             return new Jumping((int)direction);
         default:
             break;
     }
     if (direction == Direction.Null && player.velocity.X == 0)
         return new Idle();
     return base.HandleInput(player, input, this);
 }
    public void ApplyToObject(Transform objectPosition, ref StateInput objectInput)
    {
        if (!actionCompleted)
        {
            if (!NextPointReached(objectPosition))
            {
                if (moveDirection == MoveAxis.Horizontal)
                {
                    UpdateAxisInput(objectPosition, 1.0f, ref objectInput.horizontal);
                }
                else
                {
                    UpdateAxisInput(objectPosition, 1.0f, ref objectInput.vertical);
                }
                return;
            }

            if (waitBeforeChangePoint && moveDirection == MoveAxis.Horizontal)
            {
                if (turnToNextPointOnWait)
                {
                    UpdateAxisInput(objectPosition, -0.02f, ref objectInput.horizontal);
                }
                StartCoroutine(WaitToMove());
            }
            else
            {
                changePoint = true;
            }
            actionCompleted = true;
        }
    }
Ejemplo n.º 5
0
 public State HandleInput(Player player, StateInput input, ActionState state)
 {
     if (input == StateInput.KeyUp)
         state.direction = Direction.Null;
     switch (input)
     {
         case StateInput.LeftKeyPress:
             state.direction = Direction.Left;
             break;
         case StateInput.RightKeyPress:
             state.direction = Direction.Right;
             break;
         case StateInput.Hit:
             return player.TakeHit(1);
         case StateInput.GroundCollision:
             player.velocity.Y = 0;
             break;
         case StateInput.WallCollision:
             player.velocity.X = 0;
             break;
         case StateInput.Victory:
             return new Victory();
         case StateInput.LadderCollision:
             if (Managers.User.kState.IsKeyDown(Keys.Up) || Math.Abs(player.velocity.Y) > (player.gravityAcceleration * 2))
                 return new Climbing();
             break;
         default:
             break;
     }
     return state;
 }
Ejemplo n.º 6
0
 public void ApplyToObject(Transform objectPosition, ref StateInput stateInput)
 {
     if (!actionCompleted)
     {
         stateInput.jump = true;
         actionCompleted = true;
     }
 }
Ejemplo n.º 7
0
    void Awake()
    {
        stateInput = new StateInput();

        controller   = GetComponent <CharacterController2D>();
        currentPoint = firstNavigationPoint;

        controller.SetFacingDirection(initialFacingDirection != FacingDirection.Left);
    }
Ejemplo n.º 8
0
 protected ACommand(string name, StateInput state)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     Name  = name;
     State = state;
 }
Ejemplo n.º 9
0
 public void Populate(StateInput input)
 {
     grounded        = input.grounded;
     inClimbArea     = input.inClimbArea;
     climbTopReached = input.climbTopReached;
     horizontal      = input.horizontal;
     vertical        = input.vertical;
     jump            = input.jump;
     climbPosition   = input.climbPosition;
 }
Ejemplo n.º 10
0
 public override State HandleInput(Player player, StateInput input)
 {
     switch (input)
     {
         case StateInput.AnimEnd:
             Main.ChangeState(Main.GameState.Menu);
             break;
         default:
             break;
     }
     return this;
 }
Ejemplo n.º 11
0
 public override State HandleInput(Player player, StateInput input)
 {
     
     switch(input)
     {
         case StateInput.AnimEnd:
             oldState.HandleInput(player, StateInput.KeyUp);
             return oldState;
         default:
             break;
     }
     return base.HandleInput(player, input, this);
 }
Ejemplo n.º 12
0
        private void Update()
        {
            stateInput = UpdateStateInput();
            switch (controller)
            {
            case ControllerEnum.PC:
                UpdateKeyboard();
                break;

            case ControllerEnum.JOYSTICK:
                UpdateJoystick();
                break;
            }
        }
Ejemplo n.º 13
0
        static KeyCode GetKeyCode(TheKeysButtons btn, StateInput state)
        {
            //Se pregunta por el estado actual del boton
            if (state == StateInput.Default)
            {
                //Estado normal, devuelve el la asignación de la acción al estado correspondiente
                switch (btn)
                {
                case TheKeysButtons.GoRight: return(KeyCode.D);

                case TheKeysButtons.GoLeft: return(KeyCode.A);

                case TheKeysButtons.CreateGap: return(KeyCode.Mouse0);

                case TheKeysButtons.InteractionObjs: return(KeyCode.Mouse1);
                }
            }
            else if (state == StateInput.Inverted_1)
            {
                //Estado invertido 1, devuelve el la asignación de la acción al estado correspondiente
                switch (btn)
                {
                case TheKeysButtons.GoRight: return(KeyCode.Mouse1);

                case TheKeysButtons.GoLeft: return(KeyCode.Mouse0);

                case TheKeysButtons.CreateGap: return(KeyCode.A);

                case TheKeysButtons.InteractionObjs: return(KeyCode.D);
                }
            }
            else if (state == StateInput.Inverted_2)
            {
                //Estado invertido 2, devuelve el la asignación de la acción al estado correspondiente
                switch (btn)
                {
                case TheKeysButtons.GoRight: return(KeyCode.D);

                case TheKeysButtons.GoLeft: return(KeyCode.Mouse0);

                case TheKeysButtons.CreateGap: return(KeyCode.A);

                case TheKeysButtons.InteractionObjs: return(KeyCode.Mouse1);
                }
            }


            return(KeyCode.None);
        }
Ejemplo n.º 14
0
        private void UpdateFSM(StateInput input)
        {
            // Utils.Log("KVR_Switch UpdateFSM, fsm = " + fsmState + ", state = " + CurrentState + ", input = " + input);
            switch (fsmState)
            {
            case FSMState.IsDown:
                if (input == StateInput.ColliderEnter)
                {
                    fsmState = FSMState.IsSwitchingUp;
                    PlayToState(State.Up);
                }
                break;

            case FSMState.IsSwitchingUp:
                if (input == StateInput.ColliderExit)
                {
                    fsmState = FSMState.IsSwitchingDown;
                    PlayToState(State.Down);
                }
                else if (input == StateInput.FinishedAction)
                {
                    ExecuteSignal();
                    fsmState = FSMState.IsUp;
                }
                break;

            case FSMState.IsUp:
                if (input == StateInput.ColliderExit)
                {
                    fsmState = FSMState.IsSwitchingDown;
                    PlayToState(State.Down);
                }
                break;

            case FSMState.IsSwitchingDown:
                if (input == StateInput.FinishedAction)
                {
                    ExecuteSignal();
                    fsmState = FSMState.IsDown;
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 15
0
 public override State HandleInput(Player player, StateInput input)
 {
     switch (input)
     {
         case StateInput.AnimEnd:
             if (Managers.Executive.levels.Count > player.Level.Index + 1)
             {
                 Managers.Executive.LoadLevel(Managers.Executive.level.Index + 1);
             }
             else
                 Main.ChangeState(Main.GameState.Menu);
             break;
         default:
             break;
     }
     return this;
 }
Ejemplo n.º 16
0
        private void UpdateFSM(StateInput colliderInput)
        {
            switch (fsmState)
            {
            case FSMState.IsUp:
                if (colliderInput == StateInput.ColliderUpEnter)
                {
                    fsmState = FSMState.IsWaitingForDown;
                }
                break;

            case FSMState.IsWaitingForDown:
                if (colliderInput == StateInput.ColliderUpExit)
                {
                    fsmState = FSMState.IsUp;
                }
                else if (colliderInput == StateInput.ColliderDownEnter)
                {
                    fsmState = FSMState.IsDown;
                    PlayToState(State.Down);
                }
                break;

            case FSMState.IsDown:
                if (colliderInput == StateInput.ColliderDownEnter)
                {
                    fsmState = FSMState.IsWaitingForUp;
                }
                break;

            case FSMState.IsWaitingForUp:
                if (colliderInput == StateInput.ColliderDownExit)
                {
                    fsmState = FSMState.IsDown;
                }
                else if (colliderInput == StateInput.ColliderUpEnter)
                {
                    fsmState = FSMState.IsUp;
                    PlayToState(State.Up);
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 17
0
        private void UpdateFSM(StateInput input)
        {
            // Utils.Log("KVR_Button UpdateFSM, fsm = " + fsmState + ", state = " + CurrentState + ", input = " + input);
            switch (fsmState)
            {
            case FSMState.IsUnpressed:
                if (input == StateInput.ColliderEnter)
                {
                    fsmState = FSMState.IsPressing;
                    PlayToState(State.Pressed);
                }
                break;

            case FSMState.IsPressing:
                if (input == StateInput.FinishedAction)
                {
                    fsmState = FSMState.IsPressed;
                    ExecuteSignal();
                }
                break;

            case FSMState.IsPressed:
                if ((Type == ActuationType.Latching && input == StateInput.ColliderEnter) ||
                    (Type == ActuationType.Momentary && input == StateInput.ColliderExit))
                {
                    fsmState = FSMState.IsUnpressing;
                    PlayToState(State.Unpressed);
                }
                break;

            case FSMState.IsUnpressing:
                if (input == StateInput.FinishedAction)
                {
                    fsmState = FSMState.IsUnpressed;
                    ExecuteSignal();
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 18
0
 public override State HandleInput(Player player, StateInput input)
 {
     switch(input)
     {
         case StateInput.LeftKeyPress:
             return new Walking(-1);
         case StateInput.RightKeyPress:
             return new Walking(1);
         case StateInput.UpKeyPress:
             player.Jump(1);
             return new Jumping(0);
         case StateInput.Hit:
             player.TakeHit(1);
             break;
         case StateInput.AttackKeyPress:
             return new Attacking(this);
         default:
             break;
     }
     return base.HandleInput(player, input, this);
 }
Ejemplo n.º 19
0
 public override State HandleInput(Player player, StateInput input)
 {
     switch (input)
     {
         case StateInput.UpKeyPress:
             player.Jump(1);
             return new Jumping(0);
         case StateInput.AnimEnd:
             if (player.velocity.X > 9)
                 return new Running(0);
             else if (player.velocity.X != 0)
                 return new Walking(0);
             else
                 return new Idle();
         case StateInput.AttackKeyPress:
             return new Attacking(this);
         default:
             break;
     }
     return base.HandleInput(player, input, this);
 }
Ejemplo n.º 20
0
 public override State HandleInput(Player player, StateInput input)
 {
     switch (input)
     {
         case StateInput.KeyUp:
             if (Managers.User.kState.IsKeyUp(Keys.Up))
                 return new Falling(direction);
             break;
         case StateInput.UpKeyPress:
             return this;
         case StateInput.AnimEnd:
             return new Falling(direction);
         case StateInput.WallCollision:
             return base.HandleInput(player, StateInput.Null, this);
         case StateInput.GroundCollision:
             return new Landing();
         default:
             break;
     }
     return base.HandleInput(player, input, this);
 }
Ejemplo n.º 21
0
        private void UpdateFSM(StateInput input)
        {
            switch (fsmState)
            {
            case FSMState.IsClosed:
                if (input == StateInput.ColliderEnter)
                {
                    fsmState = FSMState.IsOpening;
                    PlayToState(State.Open);
                }
                break;

            case FSMState.IsOpening:
                if (input == StateInput.FinishedAction)
                {
                    fsmState = FSMState.IsOpen;
                }
                break;

            case FSMState.IsOpen:
                if (input == StateInput.ColliderEnter)
                {
                    fsmState = FSMState.IsClosing;
                    PlayToState(State.Closed);
                }
                break;

            case FSMState.IsClosing:
                if (input == StateInput.FinishedAction)
                {
                    fsmState = FSMState.IsClosed;
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 22
0
        private void DecodeState()
        {
            StateInput.SafeCopyToHost();

            for (int i = 0; i < StateInput.Host.Length; i++)
            {
                if ((int)StateInput.Host[i] != (int)MyTicTacToeWorld.TALES.EMPTY &&
                    (int)StateInput.Host[i] != (int)MyTicTacToeWorld.TALES.PLAYER_O &&
                    (int)StateInput.Host[i] != (int)MyTicTacToeWorld.TALES.PLAYER_X)
                {
                    MyLog.DEBUG.WriteLine("Unexpected state value, expected only these: " +
                                          (int)MyTicTacToeWorld.TALES.EMPTY + ", " +
                                          (int)MyTicTacToeWorld.PLAYERS.PLAYER_X + ", " +
                                          (int)MyTicTacToeWorld.PLAYERS.PLAYER_O);

                    m_currentState[i] = (int)MyTicTacToeWorld.TALES.EMPTY;
                }
                else
                {
                    m_currentState[i] = (int)StateInput.Host[i];
                }
            }
        }
Ejemplo n.º 23
0
        public override State HandleInput(Player player, StateInput input)
        {
            switch (input)
            {
                case StateInput.UpKeyPress:
                    player.Jump(1);
                    return new Jumping((int)direction);
                case StateInput.AnimEnd:
                    break;
                case StateInput.AttackKeyPress:
                    return new Attacking(this);
                default:
                    break;
            }
            if (direction == Direction.Null && player.velocity.X == 0)
            {
                return new Idle();
            }

            if (player.velocity.Y > player.gravityAcceleration * 4)
                return new Falling(direction);

            return base.HandleInput(player, input, this);
        }
Ejemplo n.º 24
0
 public abstract State HandleInput(Player player, StateInput input);
Ejemplo n.º 25
0
        //Metodo para saber la asignación de los botones
        public static string ShowButtons(TheKeysButtons btn, StateInput state)
        {
            KeyCode code = GetKeyCode(btn, state);

            return(code.ToString());
        }
Ejemplo n.º 26
0
        //Si se esta presionando una tecla
        public static bool GetKeyButton(TheKeysButtons btn, StateInput state)
        {
            KeyCode code = GetKeyCode(btn, state);

            return(Input.GetKey(code));
        }
Ejemplo n.º 27
0
        private void UpdateFSM(StateInput colliderInput)
        {
            Utils.Log("UpdateFSM, state = " + CurrentState + ", fsm = " + fsmState + ", input = " + colliderInput);
            switch (fsmState)
            {
            case FSMState.IsDown:
                if (colliderInput == StateInput.ColliderDownEnter)
                {
                    fsmState = FSMState.IsWaitingForMiddle;
                }
                break;

            case FSMState.IsWaitingForMiddle:
                if (colliderInput == StateInput.ColliderDownExit)
                {
                    fsmState = FSMState.IsDown;
                }
                else if (colliderInput == StateInput.ColliderUpExit)
                {
                    fsmState = FSMState.IsUp;
                }
                else if (colliderInput == StateInput.ColliderMiddleEnter)
                {
                    fsmState = FSMState.IsMiddle;
                    PlayToState(State.Middle);
                }
                break;

            case FSMState.IsMiddle:
                if (colliderInput == StateInput.ColliderMiddleEnter)
                {
                    fsmState = FSMState.IsWaitingForUpOrDown;
                }
                break;

            case FSMState.IsWaitingForUpOrDown:
                if (colliderInput == StateInput.ColliderMiddleExit)
                {
                    fsmState = FSMState.IsMiddle;
                }
                else if (colliderInput == StateInput.ColliderUpEnter)
                {
                    fsmState = FSMState.IsUp;
                    PlayToState(State.Up);
                }
                else if (colliderInput == StateInput.ColliderDownEnter)
                {
                    fsmState = FSMState.IsDown;
                    PlayToState(State.Down);
                }
                break;

            case FSMState.IsUp:
                if (colliderInput == StateInput.ColliderUpEnter)
                {
                    fsmState = FSMState.IsWaitingForMiddle;
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 28
0
 public override State HandleInput(Player player, StateInput input)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 29
0
 public StateInput(StateInput input) : this()
 {
     Populate(input);
 }
Ejemplo n.º 30
0
 void Awake()
 {
     stateInput = new StateInput();
 }
Ejemplo n.º 31
0
 // Use this for initialization
 void Awake()
 {
     body  = GetComponent <Rigidbody>();
     input = GetComponent <StateInput>();
     trans = GetComponent <Transform>();
 }