/// <summary>
        /// Deploys one of the links
        /// </summary>
        private void FireLink()
        {
            //Creates copy of link prefab
            GameObject visualPrefab = MonoBehaviour.Instantiate(abilityData.visualPrefab, SpawnTransform.position, abilityData.visualPrefab.transform.rotation);

            //Get the movement script attached and add it to a list
            Movement.GridMovementBehaviour gridMovement = visualPrefab.GetComponent <Movement.GridMovementBehaviour>();
            gridMovement.Position = _ownerMoveScript.Position;
            gridMovement.Speed    = abilityData.GetCustomStatValue("Speed");
            _linkMoveScripts.Add(gridMovement);

            //Makes the link move until it runs into an obstacle
            for (int i = (int)_maxTravelDistance; i >= 0; i--)
            {
                Vector2 moveOffset = new Vector2(i, 0);
                if (gridMovement.MoveToPanel(_ownerMoveScript.CurrentPanel.Position + moveOffset * owner.transform.forward.x, false, GridScripts.GridAlignment.ANY))
                {
                    break;
                }
            }
        }
        // Update is called once per frame
        void Update()
        {
            _playerState = BlackBoardBehaviour.Instance.GetPlayerStateFromID(PlayerID);

            //Checks to see if input can be enabled
            if (_inputEnableCondition != null)
            {
                if (_inputEnableCondition.Invoke())
                {
                    _playerControls.Player.Enable();
                    _inputDisabled        = false;
                    _inputEnableCondition = null;
                }
            }


            //Move if there is a movement stored and movement is allowed
            if (_storedMoveInput.magnitude > 0 && !_gridMovement.IsMoving && _canMove && _gridMovement.CanMove)
            {
                _gridMovement.MoveToPanel(_storedMoveInput + _gridMovement.Position);
                _onPlayerMove?.Invoke();
                _onPlayeMoveTemp?.Invoke();
                _onPlayeMoveTemp = null;
                _storedMoveInput = Vector2.zero;
            }
            //Checks to see if move input can be enabled

            if (_moveInputEnableCondition != null)
            {
                if (_moveInputEnableCondition.Invoke())
                {
                    if (EnableMovement())
                    {
                        _moveInputEnableCondition = null;
                    }
                }
            }
            //If player isn't doing anything, enable movement
            else if (!_attackButtonDown && !_canMove && !_moveset.AbilityInUse && _bufferedAction != null)
            {
                if (!_bufferedAction.HasAction())
                {
                    EnableMovement();
                }
            }

            //Stores the current attack direction input
            Vector3 attackDirInput = _playerControls.Player.AttackDirection.ReadValue <Vector2>();

            //If there is a direction input, update the attack direction buffer and the time of input
            if (attackDirInput.magnitude > 0)
            {
                _attackDirection          = attackDirInput;
                _timeOfLastDirectionInput = Time.time;
            }

            //Clear the buffer if its exceeded the alotted time
            if (Time.time - _timeOfLastDirectionInput > _attackDirectionBufferClearTime)
            {
                _attackDirection = Vector2.zero;
            }

            if (_bufferedAction != null)
            {
                _bufferedAction.UseAction();
            }
            else
            {
                _abilityBuffered = false;
            }

            //Temp quit buttom for first prototype build
            if (Keyboard.current.escapeKey.isPressed)
            {
                Application.Quit();
            }

            if (Keyboard.current.enterKey.wasPressedThisFrame)
            {
                EditorApplication.isPaused = true;
            }
        }
示例#3
0
        // Start is called before the first frame update
        void Start()
        {
            InputDevice[] devices = { Keyboard.current, Mouse.current };
            //Spawn player 1
            _inputManager.JoinPlayer(0, 0, "Player", devices);
            _player1            = PlayerInput.GetPlayerByIndex(0);
            _player1.name       = _player1.name + "(P1)";
            _ringBarrierL.owner = _player1.name;

            //Get reference to player 1 components
            _p1Movement     = _player1.GetComponent <Movement.GridMovementBehaviour>();
            _p1StateManager = _player1.GetComponent <CharacterStateMachineBehaviour>();
            _p1Input        = _player1.GetComponent <Input.InputBehaviour>();
            _player1Moveset = _player1.GetComponent <MovesetBehaviour>();
            BlackBoardBehaviour.Instance.Player1 = _player1.gameObject;
            //Assign ID
            _p1Input.PlayerID = 0;

            //Initialize base UI stats
            _p1HealthBar.HealthComponent = _player1.GetComponent <Movement.KnockbackBehaviour>();
            _p1HealthBar.MaxValue        = 200;
            _abilityTextP1.MoveSet       = _player1Moveset;

            //Move player to spawn
            _p1Movement.MoveToPanel(_grid.LhsSpawnPanel, true, GridScripts.GridAlignment.ANY);
            _p1Movement.Alignment      = GridScripts.GridAlignment.LEFT;
            _player1.transform.forward = Vector3.right;

            //Spawns player 2 if the game mode is set to multiplayer
            if (_mode == GameMode.MULTIPLAYER)
            {
                //Spawn player 2
                _inputManager.JoinPlayer(1, 1, "Player", InputSystem.devices[3]);
                _player2                             = PlayerInput.GetPlayerByIndex(1);
                _player2.name                        = _player2.name + "(P2)";
                _ringBarrierR.owner                  = _player2.name;
                _player2.transform.forward           = Vector3.left;
                BlackBoardBehaviour.Instance.Player2 = _player2.gameObject;
                //Get reference to player 2 components
                _p2Movement     = _player2.GetComponent <Movement.GridMovementBehaviour>();
                _p2StateManager = _player2.GetComponent <CharacterStateMachineBehaviour>();
                _p2Input        = _player2.GetComponent <Input.InputBehaviour>();
                _player2Moveset = _player2.GetComponent <MovesetBehaviour>();

                //Initialize base UI stats
                _p2HealthBar.HealthComponent = _player2.GetComponent <Movement.KnockbackBehaviour>();
                _p2HealthBar.MaxValue        = 200;
                _abilityTextP2.MoveSet       = _player2Moveset;

                //Move player to spawn
                _p2Input.PlayerID = 1;
                _p2Movement.MoveToPanel(_grid.RhsSpawnPanel, true, GridScripts.GridAlignment.ANY);
                _p2Movement.Alignment = GridScripts.GridAlignment.RIGHT;
                _grid.AssignOwners(_player1.name, _player2.name);
                return;
            }
            else if (_mode == GameMode.PRACTICE)
            {
                _inputManager.playerPrefab = _dummy.gameObject;

                _cpu                   = Instantiate(_inputManager.playerPrefab);
                _cpu.name              = _inputManager.playerPrefab.name + "(Dummy)";
                _ringBarrierR.owner    = _cpu.name;
                _cpu.transform.forward = Vector3.left;
                BlackBoardBehaviour.Instance.Player2 = _cpu.gameObject;
                //Get reference to player 2 components
                _p2Movement     = _cpu.GetComponent <Movement.GridMovementBehaviour>();
                _p2StateManager = _cpu.GetComponent <CharacterStateMachineBehaviour>();
                _player2Moveset = _cpu.GetComponent <MovesetBehaviour>();

                //Initialize base UI stats
                _p2HealthBar.HealthComponent = _cpu.GetComponent <Movement.KnockbackBehaviour>();
                _p2HealthBar.MaxValue        = 200;
                _abilityTextP2.MoveSet       = _player2Moveset;

                //Find spawn point for dummy
                GridScripts.PanelBehaviour spawnPanel = null;
                if (_grid.GetPanel(_dummySpawnLocation, out spawnPanel, false))
                {
                    _p2Movement.MoveToPanel(spawnPanel, true, GridScripts.GridAlignment.ANY);
                }
                else
                {
                    Debug.LogError("Invalid spawn point for dummy. Spawn was " + _dummySpawnLocation);
                }

                _p2Movement.Alignment = GridScripts.GridAlignment.RIGHT;
                _grid.AssignOwners(_player1.name, _cpu.name);
                return;
            }

            _grid.AssignOwners(_player1.name);
        }