public void Move(Vector2 velocity, MovingDirections direction, MovingDirections direction2)
        {
            velocity.X = Math.Abs(velocity.X);
            velocity.Y = Math.Abs(velocity.Y);

            if (direction != direction2)
            {
                switch (direction)
                {
                case MovingDirections.Left:
                case MovingDirections.Right:
                    if (direction2 != MovingDirections.Left && direction2 != MovingDirections.Right)
                    {
                        this.Velocity.X = direction == MovingDirections.Left ? -velocity.X : velocity.X;
                        this.Velocity.Y = direction2 == MovingDirections.Up ? -velocity.Y : velocity.Y;
                    }
                    break;

                case MovingDirections.Up:
                case MovingDirections.Down:
                    if (direction2 != MovingDirections.Down && direction2 != MovingDirections.Up)
                    {
                        this.Velocity.X = direction2 == MovingDirections.Left ? -velocity.X : velocity.X;
                        this.Velocity.Y = direction == MovingDirections.Up ? -velocity.Y : velocity.Y;
                    }
                    break;
                }
            }
        }
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);

            float leftThumbX = Controller.Input.GetPadState(this.player).ThumbSticks.Left.X;
            float leftThumbY = Controller.Input.GetPadState(this.player).ThumbSticks.Left.Y;

            Vector2 currentVelocity = new Vector2(0);

            if (Controller.Input.JustPressed(this.player, Microsoft.Xna.Framework.Input.Buttons.A) && OnFloor)
            {
                this.OnFloor = false;
                Jump();
            }

            if (Math.Abs(leftThumbX) > 0.1f)
            {
                this.movingDirection = leftThumbX > 0 ? MovingDirections.Right : MovingDirections.Left;

                currentVelocity.X = MathHelper.Lerp(0, MaxVelocity.X, Math.Abs(leftThumbX));

                this.Move(currentVelocity.X, this.movingDirection);
            }
            else
            {
                this.movingDirection  = MovingDirections.None;
                this.movingDirection2 = MovingDirections.None;
                this.Velocity.X       = 0;
            }

            AddGravitation(5);
            Controller.Collide(this, "tilemap", BloodCellCollides);
        }
Esempio n. 3
0
    public void MoveCharacter(MovingDirections direction)
    {
        if (_canMove)
        {
            _isTurningToLook = false;
            switch (direction)
            {
            case MovingDirections.None:
                _rigidBody.velocity = Vector3.zero;
                if (_animator != null)
                {
                    _animator.SetMovement(false);
                }
                break;

            default:
                Vector3 finalDirection = GetPositionRelativeToCamera(direction);
                _targetDir = gameObject.transform.position + finalDirection;
                _animator.SetMovement(true);

                if (!_isCharging)
                {
                    _rigidBody.velocity = (finalDirection * Speed);
                    _animator.SetCharge(false);
                    _animator.SetSpeed(Speed);
                }
                else
                {
                    _rigidBody.velocity = (finalDirection * ChargeSpeed);
                    _animator.SetCharge(true);
                }
                break;
            }
        }
    }
Esempio n. 4
0
 /// <summary>
 /// Modifica la dirección
 /// </summary>
 /// <param name="movingDirection">Dirección modificada</param>
 public void ChangeDirection(MovingDirections movingDirection)
 {
     if (this.CanChangeDirection)
     {
         this.MovingDirection = movingDirection;
     }
 }
Esempio n. 5
0
    public void UnfreezeObject(MovingDirections direction)
    {
        rb.constraints = RigidbodyConstraints2D.None;
        rb.constraints = RigidbodyConstraints2D.FreezeRotation;

        if (direction == MovingDirections.LeftRight || direction == MovingDirections.RightLeft)
        {
            rb.constraints = RigidbodyConstraints2D.FreezePositionY;
        }
        else if (direction == MovingDirections.UpDown || direction == MovingDirections.DownUp)
        {
            rb.constraints = RigidbodyConstraints2D.FreezePositionX;
        }
    }
        public void Move(float velocity, MovingDirections direction)
        {
            switch (direction)
            {
            case MovingDirections.Left:
            case MovingDirections.Right:
                this.Velocity.X = direction == MovingDirections.Left ? -velocity : velocity;
                break;

            case MovingDirections.Up:
            case MovingDirections.Down:
                this.Velocity.Y = direction == MovingDirections.Up ? -velocity : velocity;
                break;
            }
        }
Esempio n. 7
0
 public void MoveBlock(MovingDirections moveDirection)
 {
     if (moveDirection == MovingDirections.Left)
     {
         this.Left -= TetrisConfig.BlockSize;
     }
     if (moveDirection == MovingDirections.Right)
     {
         this.Left += TetrisConfig.BlockSize;
     }
     if (moveDirection == MovingDirections.Down)
     {
         this.Top += TetrisConfig.BlockSize;
     }
 }
Esempio n. 8
0
    private Vector3 GetPositionRelativeToCamera(MovingDirections originalDirection)
    {
        Vector3 result = Vector3.zero;

        switch (originalDirection)
        {
        case MovingDirections.Up:
            result = CurrentCamera.transform.forward;
            break;

        case MovingDirections.Down:
            result = CurrentCamera.transform.forward * -1;
            break;

        case MovingDirections.Left:
            result = CurrentCamera.transform.right * -1;
            break;

        case MovingDirections.Right:
            result = CurrentCamera.transform.right;
            break;

        case MovingDirections.RightUp:
            result = CurrentCamera.transform.right + CurrentCamera.transform.forward;
            break;

        case MovingDirections.RightDown:
            result = CurrentCamera.transform.right + (CurrentCamera.transform.forward * -1);
            break;

        case MovingDirections.DownLeft:
            result = (CurrentCamera.transform.forward * -1) + (CurrentCamera.transform.right * -1);
            break;

        case MovingDirections.LeftUp:
            result = (CurrentCamera.transform.right * -1) + CurrentCamera.transform.forward;
            break;
        }

        result.y = 0;
        result.Normalize();
        return(result);
    }
Esempio n. 9
0
        /// <summary>
        /// Check if the shape can move in the desinated direction
        /// </summary>
        /// <param name="nextDirection">The direction the shape is going to be moved</param>
        /// <returns>true if it can move, false otherwise</returns>
        public override bool CanMove(MovingDirections nextDirection)
        {
            //The shape can be moved if the cells at the next location are not ButtonCellType
            int nextCenterRowIdx = 0;
            int nextCenterColIdx = 0;

            ICellType nextCenterCellType = null;

            bool canMove = true;

            switch (nextDirection)
            {
                case MovingDirections.Right:
                    nextCenterRowIdx = _centerRowIdx;
                    nextCenterColIdx = _centerColIdx + 1;
                    break;

                case MovingDirections.Left:
                    nextCenterRowIdx = _centerRowIdx;
                    nextCenterColIdx = _centerColIdx - 1;
                    break;

                case MovingDirections.Down:
                    nextCenterRowIdx = _centerRowIdx + 1;
                    nextCenterColIdx = _centerColIdx;
                    break;
            }

            //If any row or col idx of the new locations go over the border, stops
            if (nextCenterRowIdx >= BORDER_BOTTOM || nextCenterColIdx < BORDER_LEFT || nextCenterColIdx >= BORDER_RIGHT)
                return false;

            //The shape can be moved if the cells at the next location are not ButtonCellType
            nextCenterCellType = _sheet.Cells[nextCenterRowIdx, nextCenterColIdx].CellType;

            //Check the new locations based on the moving direction and the current shape direction
            if (nextCenterCellType != null)
                return false;

            return canMove;
        }
Esempio n. 10
0
        public void Move(MovingDirections movDirection)
        {
            switch (movDirection)
            {
            case MovingDirections.Up:
                PositionY -= 1;
                break;

            case MovingDirections.Right:
                PositionX -= 1;
                break;

            case MovingDirections.Down:
                PositionY += 1;
                break;

            case MovingDirections.Left:
                PositionX += 1;
                break;
            }
        }
Esempio n. 11
0
 public void Move(float velocity, MovingDirections direction)
 {
     switch(direction)
     {
         case MovingDirections.Left:
         case MovingDirections.Right:
             this.Velocity.X = direction == MovingDirections.Left ? -velocity : velocity;
             break;
         case MovingDirections.Up:
         case MovingDirections.Down:
             this.Velocity.Y = direction == MovingDirections.Up ? -velocity : velocity;
             break;
     }
 }
Esempio n. 12
0
 public MoveShape(ITetrisShape shape, MovingDirections direction)
 {
     _currentShape = shape;
     _movingDirection = direction;
 }
Esempio n. 13
0
 public void InitEnemey(MovingDirections direction, float speed)
 {
     moveSpeed       = speed;
     movingDirection = direction;
 }
Esempio n. 14
0
        /// <summary>
        /// Check if the shape can move in the desinated direction
        /// </summary>
        /// <param name="nextDirection">The direction the shape is going to be moved</param>
        /// <returns>true if it can move, false otherwise</returns>
        public override bool CanMove(MovingDirections nextDirection)
        {
            //The shape can be moved if the cells at the next location are nulll
            //The shapes are built from 4 cells so we need to check max 4 next locations
            //Locations are from left to right, top to bottom
            int loc1RowIdx = 0;
            int loc1ColIdx = 0;
            int loc2RowIdx = 0;
            int loc2ColIdx = 0;
            int loc3RowIdx = 0;
            int loc3ColIdx = 0;
            int loc4RowIdx = 0;
            int loc4ColIdx = 0;

            ICellType nextCellType1 = null;
            ICellType nextCellType2 = null;
            ICellType nextCellType3 = null;
            ICellType nextCellType4 = null;

            //Compute the original locations
            switch (_currentShapeDirection)
            {
                case ShapeDirections.FaceDown:
                    if (_isLeft)
                    {
                        loc1ColIdx = _leftColIdx;
                        loc1RowIdx = _leftRowIdx;

                        loc2ColIdx = _centerColIdx;
                        loc2RowIdx = _centerRowIdx;

                        loc3ColIdx = _rightColIdx;
                        loc3RowIdx = _rightRowIdx;

                        loc4ColIdx = _bottomRightColIdx;
                        loc4RowIdx = _bottomRightRowIdx;
                    }
                    else
                    {
                        loc1ColIdx = _leftColIdx;
                        loc1RowIdx = _leftRowIdx;

                        loc2ColIdx = _centerColIdx;
                        loc2RowIdx = _centerRowIdx;

                        loc3ColIdx = _rightColIdx;
                        loc3RowIdx = _rightRowIdx;

                        loc4ColIdx = _bottomLeftColIdx;
                        loc4RowIdx = _bottomLeftRowIdx;
                    }

                    break;

                case ShapeDirections.FaceLeft:
                    if (_isLeft)
                    {
                        loc1ColIdx = _topColIdx;
                        loc1RowIdx = _topRowIdx;

                        loc2ColIdx = _centerColIdx;
                        loc2RowIdx = _centerRowIdx;

                        loc3ColIdx = _bottomLeftColIdx;
                        loc3RowIdx = _bottomLeftRowIdx;

                        loc4ColIdx = _bottomColIdx;
                        loc4RowIdx = _bottomRowIdx;
                    }
                    else
                    {
                        loc1ColIdx = _topLeftColIdx;
                        loc1RowIdx = _topLeftRowIdx;

                        loc2ColIdx = _topColIdx;
                        loc2RowIdx = _topRowIdx;

                        loc3ColIdx = _centerColIdx;
                        loc3RowIdx = _centerRowIdx;

                        loc4ColIdx = _bottomColIdx;
                        loc4RowIdx = _bottomRowIdx;
                    }
                    break;

                case ShapeDirections.FaceRight:
                    if (_isLeft)
                    {
                        loc1ColIdx = _topColIdx;
                        loc1RowIdx = _topRowIdx;

                        loc2ColIdx = _topRightColIdx;
                        loc2RowIdx = _topRightRowIdx;

                        loc3ColIdx = _centerColIdx;
                        loc3RowIdx = _centerRowIdx;

                        loc4ColIdx = _bottomColIdx;
                        loc4RowIdx = _bottomRowIdx;
                    }
                    else
                    {
                        loc1ColIdx = _topColIdx;
                        loc1RowIdx = _topRowIdx;

                        loc2ColIdx = _centerColIdx;
                        loc2RowIdx = _centerRowIdx;

                        loc3ColIdx = _bottomColIdx;
                        loc3RowIdx = _bottomRowIdx;

                        loc4ColIdx = _bottomRightColIdx;
                        loc4RowIdx = _bottomRightRowIdx;
                    }
                    break;

                case ShapeDirections.FaceUp:
                    if (_isLeft)
                    {
                        loc1ColIdx = _topLeftColIdx;
                        loc1RowIdx = _topLeftRowIdx;

                        loc2ColIdx = _leftColIdx;
                        loc2RowIdx = _leftRowIdx;

                        loc3ColIdx = _centerColIdx;
                        loc3RowIdx = _centerRowIdx;

                        loc4ColIdx = _rightColIdx;
                        loc4RowIdx = _rightRowIdx;
                    }
                    else
                    {
                        loc1ColIdx = _topRightColIdx;
                        loc1RowIdx = _topRightRowIdx;

                        loc2ColIdx = _leftColIdx;
                        loc2RowIdx = _leftRowIdx;

                        loc3ColIdx = _centerColIdx;
                        loc3RowIdx = _centerRowIdx;

                        loc4ColIdx = _rightColIdx;
                        loc4RowIdx = _rightRowIdx;
                    }
                    break;
            }

            //Compute the next locations
            switch (nextDirection)
            {
                case MovingDirections.Right:
                    loc1ColIdx = loc1ColIdx + 1;
                    loc2ColIdx = loc2ColIdx + 1;
                    loc3ColIdx = loc3ColIdx + 1;
                    loc4ColIdx = loc4ColIdx + 1;
                    break;

                case MovingDirections.Left:
                    loc1ColIdx = loc1ColIdx - 1;
                    loc2ColIdx = loc2ColIdx - 1;
                    loc3ColIdx = loc3ColIdx - 1;
                    loc4ColIdx = loc4ColIdx - 1;
                    break;

                case MovingDirections.Down:
                    loc1RowIdx = loc1RowIdx + 1;
                    loc2RowIdx = loc2RowIdx + 1;
                    loc3RowIdx = loc3RowIdx + 1;
                    loc4RowIdx = loc4RowIdx + 1;
                    break;
            }

            if (loc1ColIdx < BORDER_LEFT || loc2ColIdx < BORDER_LEFT || loc3ColIdx < BORDER_LEFT || loc4ColIdx < BORDER_LEFT
                || loc1ColIdx >= BORDER_RIGHT || loc2ColIdx >= BORDER_RIGHT || loc3ColIdx >= BORDER_RIGHT || loc4ColIdx >= BORDER_RIGHT
                || loc1RowIdx >= BORDER_BOTTOM || loc2RowIdx >= BORDER_BOTTOM || loc3RowIdx >= BORDER_BOTTOM || loc4RowIdx >= BORDER_BOTTOM)
                return false;

            //The shape can be moved if the cells at the next location are not ButtonCellType
            nextCellType1 = _sheet.Cells[loc1RowIdx, loc1ColIdx].CellType;
            nextCellType2 = _sheet.Cells[loc2RowIdx, loc2ColIdx].CellType;
            nextCellType3 = _sheet.Cells[loc3RowIdx, loc3ColIdx].CellType;
            nextCellType4 = _sheet.Cells[loc4RowIdx, loc4ColIdx].CellType;

            switch (_currentShapeDirection)
            {
                case ShapeDirections.FaceDown:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            //Shape is facing down and moving down
                            if (_isLeft)
                            {
                                if (nextCellType1 != null || nextCellType2 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType2 != null || nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Left:
                            //Shape is facing down and moving left
                            if (_isLeft)
                            {
                                if (nextCellType1 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType1 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Right:
                            //Shape is facing down and moving right
                            if (_isLeft)
                            {
                                if (nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;
                    }

                    break;

                case ShapeDirections.FaceLeft:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            //Shape is facing left and moving down
                            if (_isLeft)
                            {
                                if (nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType1 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Left:
                            //Shape is facing left and moving left
                            if (_isLeft)
                            {
                                if (nextCellType1 != null || nextCellType2 != null || nextCellType3 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType1 != null || nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Right:
                            //Shape is facing left and moving right
                            if (_isLeft)
                            {
                                if (nextCellType1 != null || nextCellType2 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType2 != null || nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;
                    }
                    break;

                case ShapeDirections.FaceRight:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            //Shape is facing right and moving down
                            if (_isLeft)
                            {
                                if (nextCellType2 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Left:
                            //Shape is facing right and moving left
                            if (_isLeft)
                            {
                                if (nextCellType1 != null || nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType1 != null || nextCellType2 != null || nextCellType3 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Right:
                            //Shape is facing right and moving right
                            if (_isLeft)
                            {
                                if (nextCellType2 != null || nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType1 != null || nextCellType2 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;
                    }
                    break;

                case ShapeDirections.FaceUp:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            //Shape is facing up and moving down
                            if (_isLeft)
                            {
                                if (nextCellType2 != null || nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType2 != null || nextCellType3 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Left:
                            //Shape is facing up and moving left
                            if (_isLeft)
                            {
                                if (nextCellType1 != null || nextCellType2 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType1 != null || nextCellType2 != null)
                                    return false;
                            }
                            break;

                        case MovingDirections.Right:
                            //Shape is facing up and moving right
                            if (_isLeft)
                            {
                                if (nextCellType1 != null || nextCellType4 != null)
                                    return false;
                            }
                            else
                            {
                                if (nextCellType1 != null || nextCellType4 != null)
                                    return false;
                            }
                            break;
                    }
                    break;
            }

            return true;
        }
Esempio n. 15
0
 /// <summary>
 /// Base function to check whether the shape can move. Default is return true
 /// </summary>
 /// <param name="nextDirection"></param>
 /// <returns></returns>
 public virtual bool CanMove(MovingDirections nextDirection)
 {
     return true;
 }
Esempio n. 16
0
        /// <summary>
        /// Base move left function, move all cells coordinates to the left
        /// </summary>
        public virtual void Move(MovingDirections direction)
        {
            switch (direction)
            {
                case MovingDirections.Left:
                    if (_center != null) _centerColIdx -= 1;
                    if (_top != null) _topColIdx -= 1;
                    if (_bottom != null) _bottomColIdx -= 1;
                    if (_left != null) _leftColIdx -= 1;
                    if (_right != null) _rightColIdx -= 1;
                    if (_topLeft != null) _topLeftColIdx -= 1;
                    if (_bottomLeft != null) _bottomLeftColIdx -= 1;
                    if (_topRight != null) _topRightColIdx -= 1;
                    if (_bottomRight != null) _bottomRightColIdx -= 1;
                    break;

                case MovingDirections.Right:
                    if (_center != null) _centerColIdx += 1;
                    if (_top != null) _topColIdx += 1;
                    if (_bottom != null) _bottomColIdx += 1;
                    if (_left != null) _leftColIdx += 1;
                    if (_right != null) _rightColIdx += 1;
                    if (_topLeft != null) _topLeftColIdx += 1;
                    if (_bottomLeft != null) _bottomLeftColIdx += 1;
                    if (_topRight != null) _topRightColIdx += 1;
                    if (_bottomRight != null) _bottomRightColIdx += 1;
                    break;

                case MovingDirections.Down:
                    if (_center != null) _centerRowIdx += 1;
                    if (_top != null) _topRowIdx += 1;
                    if (_bottom != null) _bottomRowIdx += 1;
                    if (_left != null) _leftRowIdx += 1;
                    if (_right != null) _rightRowIdx += 1;
                    if (_topLeft != null) _topLeftRowIdx += 1;
                    if (_bottomLeft != null) _bottomLeftRowIdx += 1;
                    if (_topRight != null) _topRightRowIdx += 1;
                    if (_bottomRight != null) _bottomRightRowIdx += 1;
                    break;
            }

            ResetCells();
            Draw();
        }
Esempio n. 17
0
        public void Move(Vector2 velocity, MovingDirections direction, MovingDirections direction2)
        {
            velocity.X = Math.Abs(velocity.X);
            velocity.Y = Math.Abs(velocity.Y);

            if (direction != direction2)
            {
                switch (direction)
                {
                    case MovingDirections.Left:
                    case MovingDirections.Right:
                        if (direction2 != MovingDirections.Left && direction2 != MovingDirections.Right)
                        {
                            this.Velocity.X = direction == MovingDirections.Left ? -velocity.X : velocity.X;
                            this.Velocity.Y = direction2 == MovingDirections.Up ? -velocity.Y : velocity.Y;
                        }
                        break;
                    case MovingDirections.Up:
                    case MovingDirections.Down:
                        if (direction2 != MovingDirections.Down && direction2 != MovingDirections.Up)
                        {
                            this.Velocity.X = direction2 == MovingDirections.Left ? -velocity.X : velocity.X;
                            this.Velocity.Y = direction == MovingDirections.Up ? -velocity.Y : velocity.Y;
                        }
                        break;
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Check if the shape can move in the desinated direction
        /// </summary>
        /// <param name="nextDirection">The direction the shape is going to be moved</param>
        /// <returns>true if it can move, false otherwise</returns>
        public override bool CanMove(MovingDirections nextDirection)
        {
            //The shape can be moved if the cells at the next location are nulll
            //The shapes are built from 3 cells so we need to check 3 next locations
            //Locations are from left to right, top to bottom
            int loc1RowIdx = 0;
            int loc1ColIdx = 0;
            int loc2RowIdx = 0;
            int loc2ColIdx = 0;
            int loc3RowIdx = 0;
            int loc3ColIdx = 0;

            ICellType nextCellType1 = null;
            ICellType nextCellType2 = null;
            ICellType nextCellType3 = null;

            //Work around to fix a bug where the shape direction doesn't match the location of the cells
            if (_currentShapeDirection == ShapeDirections.FaceDown || _currentShapeDirection == ShapeDirections.FaceUp)
            {
                if (_left == null || _right == null)
                {
                    _currentShapeDirection = ShapeDirections.FaceLeft;
                }
            }
            else
            {
                if (_top == null || _bottom == null)
                {
                    _currentShapeDirection = ShapeDirections.FaceDown;
                }
            }

            //Compute the original locations
            switch (_currentShapeDirection)
            {
                case ShapeDirections.FaceDown:
                    loc1ColIdx = _leftColIdx;
                    loc1RowIdx = _leftRowIdx;

                    loc2ColIdx = _centerColIdx;
                    loc2RowIdx = _centerRowIdx;

                    loc3ColIdx = _rightColIdx;
                    loc3RowIdx = _rightRowIdx;

                    break;

                case ShapeDirections.FaceUp:
                    loc1ColIdx = _leftColIdx;
                    loc1RowIdx = _leftRowIdx;

                    loc2ColIdx = _centerColIdx;
                    loc2RowIdx = _centerRowIdx;

                    loc3ColIdx = _rightColIdx;
                    loc3RowIdx = _rightRowIdx;

                    break;

                case ShapeDirections.FaceLeft:
                    loc1ColIdx = _topColIdx;
                    loc1RowIdx = _topRowIdx;

                    loc2ColIdx = _centerColIdx;
                    loc2RowIdx = _centerRowIdx;

                    loc3ColIdx = _bottomColIdx;
                    loc3RowIdx = _bottomRowIdx;

                    break;

                case ShapeDirections.FaceRight:
                    loc1ColIdx = _topColIdx;
                    loc1RowIdx = _topRowIdx;

                    loc2ColIdx = _centerColIdx;
                    loc2RowIdx = _centerRowIdx;

                    loc3ColIdx = _bottomColIdx;
                    loc3RowIdx = _bottomRowIdx;

                    break;
            }

            //Compute the next locations
            switch (nextDirection)
            {
                case MovingDirections.Right:
                    loc1ColIdx = loc1ColIdx + 1;
                    loc2ColIdx = loc2ColIdx + 1;
                    loc3ColIdx = loc3ColIdx + 1;
                    break;

                case MovingDirections.Left:
                    loc1ColIdx = loc1ColIdx - 1;
                    loc2ColIdx = loc2ColIdx - 1;
                    loc3ColIdx = loc3ColIdx - 1;
                    break;

                case MovingDirections.Down:
                    loc1RowIdx = loc1RowIdx + 1;
                    loc2RowIdx = loc2RowIdx + 1;
                    loc3RowIdx = loc3RowIdx + 1;
                    break;
            }

            if (loc1ColIdx < BORDER_LEFT || loc2ColIdx < BORDER_LEFT || loc3ColIdx < BORDER_LEFT
                || loc1ColIdx >= BORDER_RIGHT || loc2ColIdx >= BORDER_RIGHT || loc3ColIdx >= BORDER_RIGHT
                || loc1RowIdx >= BORDER_BOTTOM || loc2RowIdx >= BORDER_BOTTOM || loc3RowIdx >= BORDER_BOTTOM)
                return false;

            //The shape can be moved if the cells at the next location are not ButtonCellType
            nextCellType1 = _sheet.Cells[loc1RowIdx, loc1ColIdx].CellType;
            nextCellType2 = _sheet.Cells[loc2RowIdx, loc2ColIdx].CellType;
            nextCellType3 = _sheet.Cells[loc3RowIdx, loc3ColIdx].CellType;

            switch (_currentShapeDirection)
            {
                case ShapeDirections.FaceDown:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            //Shape is facing down/up and moving down
                            if (nextCellType2 != null || nextCellType3 != null || nextCellType1 != null)
                                return false;
                            break;

                        case MovingDirections.Left:
                            //Shape is facing down/up and moving left
                            if (nextCellType1 != null)
                                return false;
                            break;

                        case MovingDirections.Right:
                            //Shape is facing down/up and moving right

                            if (nextCellType3 != null)
                                return false;
                            break;
                    }

                    break;

                case ShapeDirections.FaceUp:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            //Shape is facing down/up and moving down
                            if (nextCellType2 != null || nextCellType3 != null || nextCellType1 != null)
                                return false;
                            break;

                        case MovingDirections.Left:
                            //Shape is facing down/up and moving left
                            if (nextCellType1 != null)
                                return false;
                            break;

                        case MovingDirections.Right:
                            //Shape is facing down/up and moving right

                            if (nextCellType3 != null)
                                return false;
                            break;
                    }

                    break;

                case ShapeDirections.FaceRight:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            if (nextCellType3 != null)
                                return false;
                            break;

                        case MovingDirections.Left:
                            if (nextCellType1 != null || nextCellType2 != null || nextCellType3 != null)
                                return false;
                            break;

                        case MovingDirections.Right:
                            //Shape is facing right and moving right
                            if (nextCellType1 != null || nextCellType2 != null || nextCellType3 != null)
                                return false;
                            break;
                    }
                    break;

                case ShapeDirections.FaceLeft:
                    switch (nextDirection)
                    {
                        case MovingDirections.Down:
                            if (nextCellType3 != null)
                                return false;
                            break;

                        case MovingDirections.Left:
                            if (nextCellType1 != null || nextCellType2 != null || nextCellType3 != null)
                                return false;
                            break;

                        case MovingDirections.Right:
                            //Shape is facing right and moving right
                            if (nextCellType1 != null || nextCellType2 != null || nextCellType3 != null)
                                return false;
                            break;
                    }
                    break;
            }

            return true;
        }
Esempio n. 19
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            base.Update(gameTime);

            float leftThumbX = Controller.Input.GetPadState(this.player).ThumbSticks.Left.X;
            float leftThumbY = Controller.Input.GetPadState(this.player).ThumbSticks.Left.Y;

            Vector2 currentVelocity = new Vector2(0);

            if (Controller.Input.JustPressed(this.player, Microsoft.Xna.Framework.Input.Buttons.A) && OnFloor)
            {
                this.OnFloor = false;
                Jump();
            }

            if (Math.Abs(leftThumbX) > 0.1f)
            {

                this.movingDirection = leftThumbX > 0 ? MovingDirections.Right : MovingDirections.Left;

                currentVelocity.X = MathHelper.Lerp(0, MaxVelocity.X, Math.Abs(leftThumbX));

                this.Move(currentVelocity.X, this.movingDirection);
            }
            else
            {
                this.movingDirection = MovingDirections.None;
                this.movingDirection2 = MovingDirections.None;
                this.Velocity.X = 0;
            }

            AddGravitation(5);
            Controller.Collide(this, "tilemap", BloodCellCollides);
        }
Esempio n. 20
0
        public void MoveTetromino(MovingDirections movingDirection)
        {
            switch (movingDirection)
            {
            case MovingDirections.Left:
                bool allowMovementLeft = true;
                foreach (Block block in Shape)
                {
                    if (block.Left <= 0)
                    {
                        allowMovementLeft = false;
                    }
                }

                if (!allowMovementLeft)
                {
                    return;
                }
                else
                {
                    foreach (Block block in Shape)
                    {
                        block.MoveBlock(movingDirection);
                    }
                }

                break;

            case MovingDirections.Right:
                bool allowMovementRight = true;
                foreach (Block block in Shape)
                {
                    if (block.Right >= TetrisConfig.getFieldWidth())
                    {
                        allowMovementRight = false;
                    }
                }

                if (!allowMovementRight)
                {
                    return;
                }
                else
                {
                    foreach (Block block in Shape)
                    {
                        block.MoveBlock(movingDirection);
                    }
                }
                break;

            case MovingDirections.Down:
                bool allowMovementDown = true;
                foreach (Block block in Shape)
                {
                    if (block.Bottom >= TetrisConfig.getFieldHeight())
                    {
                        allowMovementDown = false;
                    }
                }

                if (!allowMovementDown)
                {
                    TetrominoDocked?.Invoke(this);
                    return;
                }
                else
                {
                    foreach (Block block in Shape)
                    {
                        block.MoveBlock(movingDirection);
                    }
                }
                break;

            default:
                break;
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Cambia la dirección del vehículo
 /// </summary>
 /// <param name="movingDirection">Dirección</param>
 public void ChangeDirection(MovingDirections movingDirection)
 {
     this.Engine.ChangeDirection(movingDirection);
 }