Exemple #1
0
        private void Move()
        {
            float verticalAxis   = Input.GetAxisRaw("Vertical");
            float horizontalAxis = Input.GetAxisRaw("Horizontal");

            if (verticalAxis != 0 || horizontalAxis != 0)
            {
                if (IsMoving == false)
                {
                    StartedMoving?.Invoke();
                    player.ChangeState((int)PlayerState.Moving);
                }
                IsMoving = true;

                var     transformCache = transform;
                Vector3 forward        = transformCache.forward;
                Vector3 right          = transformCache.right;

                Vector3 movementVector = (forward * verticalAxis) + (right * horizontalAxis);

                movementVector.Normalize();
                movementDirection = movementVector;
                rigidbody.AddForce(movementVector * currentSpeed, ForceMode.Impulse);
            }
            else
            {
                if (IsMoving)
                {
                    StoppedMoving?.Invoke();
                    player.ChangeState(-(int)PlayerState.Moving);
                }
                IsMoving = false;
            }
        }
Exemple #2
0
 public void Move()
 {
     if (StartStructure == null || DestinationStructure == null)
     {
         throw new InvalidOperationException("The start and destination structures have to be set before the package can start moving");
     }
     if (ResourceRequestState != ResourceRequestState.Pending)
     {
         throw new InvalidOperationException($"{nameof(Move)} can only be called, if the the {nameof(Game.ResourceRequestState)} is still {nameof(ResourceRequestState.Pending)}");
     }
     Path                 = PathFinder.GetPath(StartStructure.Position, DestinationStructure.Position);
     Path.Invalidated    += PathsChanged;
     CurrentNode          = Path.Start;
     NextNode             = Path.AllHops.Count > 1 ? Path.AllHops[1] : Path.AllHops[0];
     ResourceRequestState = ResourceRequestState.OnItsWay;
     StartedMoving?.Invoke(this);
 }
Exemple #3
0
        /// <summary>
        /// Moves the Falling Block based on the Key Pressed
        /// </summary>
        /// <param name="keyPressed">The Key that was pressed on the KeyBoard</param>
        public void MovePiece(Keys keyPressed)
        {
            List <Cells> oldCells = null;

            try
            {
                //Tell the game that we are starting to move the Piece and it should surpress any and all Key Events
                StartedMoving?.Invoke();
                //No need if the space bar is pressed.
                if (keyPressed != Keys.Space)
                {
                    oldCells = GetOldCellsData();
                }
                switch (keyPressed)
                {
                case Keys.Right:
                    if (CheckRightSideForBlocks())
                    {
                        BlockThatsFalling.MoveRight();
                    }
                    break;

                case Keys.Left:
                    if (CheckLeftSideForBlocksAndWalls())
                    {
                        BlockThatsFalling.MoveLeft();
                    }
                    break;

                case Keys.Up:
                    if (IsItOkayToMove())
                    {
                        BlockThatsFalling.RotateRight();
                        CheckRotateRight();
                    }
                    break;

                case Keys.Down:
                    if (IsItOkayToMove())
                    {
                        BlockThatsFalling.RotateLeft();
                        CheckRotateLeft();
                    }
                    break;

                case Keys.Space:
                    if (BlockThatsFalling.IsItFalling)
                    {
                        DropBlockToTheBottom();
                    }
                    break;

                case Keys.V:
                    MoveFallingBlock();
                    break;

                case Keys.C:
                    if (_allowBlockToBeHeld)
                    {
                        _allowBlockToBeHeld = false;
                        HoldFallingBlock();
                    }
                    break;

                default:
                    break;
                }
            }
            finally
            {
                if (keyPressed != Keys.Space)
                {
                    DrawOutTheBlocks(oldCells);
                }
                //Signal the game that the piece is done moving
                DoneMoving?.Invoke();
            }
        }