예제 #1
0
        protected void Move(TileMap tileMap)
        {
            if (mastChangeDirection && InTile())
            {
                switch (_nextMoveDirection)
                {
                case MoveDirection.Up:
                    if (CanMove(_nextMoveDirection, tileMap, point2F.x, point2F.y - 8f, true))
                    {
                        SetInTile(point2F);
                        _moveDirection      = _nextMoveDirection;
                        mastChangeDirection = false;
                    }

                    break;

                case MoveDirection.Down:
                    if (CanMove(_nextMoveDirection, tileMap, point2F.x, point2F.y, true))
                    {
                        SetInTile(point2F);
                        _moveDirection      = _nextMoveDirection;
                        mastChangeDirection = false;
                    }
                    break;

                case MoveDirection.Left:
                    if (CanMove(_nextMoveDirection, tileMap, point2F.x - 8f, point2F.y, true))
                    {
                        SetInTile(point2F);
                        _moveDirection      = _nextMoveDirection;
                        mastChangeDirection = false;
                    }

                    break;

                case MoveDirection.Right:
                    if (_moveDirection == MoveDirection.Up || _moveDirection == MoveDirection.Left)
                    {
                        if (CanMove(_nextMoveDirection, tileMap, point2F.x, point2F.y, true))
                        {
                            SetInTile(point2F);
                            _moveDirection      = _nextMoveDirection;
                            mastChangeDirection = false;
                        }
                    }
                    else
                    {
                        if (CanMove(_nextMoveDirection, tileMap, point2F.x, point2F.y + 8f, true))
                        {
                            SetInTile(point2F);
                            _moveDirection      = _nextMoveDirection;
                            mastChangeDirection = false;
                        }
                    }
                    break;

                case MoveDirection.Freeze:
                    _moveDirection      = _nextMoveDirection;
                    mastChangeDirection = false;
                    break;
                }
            }

            switch (_moveDirection)
            {
            case MoveDirection.Up:
                if (CanMove(_moveDirection, tileMap, point2F.x, point2F.y - _objectSpeed))
                {
                    point2F.y -= _objectSpeed;
                }
                else
                {
                    point2F.y = ((int)(point2F.y / 16f)) * 16;
                    if (!mastChangeDirection)
                    {
                        ChangeDirection(MoveDirection.Freeze);
                    }
                }
                break;

            case MoveDirection.Down:
                if (CanMove(_moveDirection, tileMap, point2F.x, point2F.y + _objectSpeed))
                {
                    point2F.y += _objectSpeed;
                }
                else
                {
                    point2F.y = ((int)((point2F.y + _objectSpeed) / 16f)) * 16;
                    if (!mastChangeDirection)
                    {
                        ChangeDirection(MoveDirection.Freeze);
                    }
                }
                break;

            case MoveDirection.Left:
                if (point2F.x <= 8)
                {
                    point2F.x = 416f;
                }
                if (CanMove(_moveDirection, tileMap, point2F.x - _objectSpeed, point2F.y))
                {
                    point2F.x -= _objectSpeed;
                }
                else
                {
                    point2F.x = ((int)(point2F.x) / 16f) * 16;
                    if (!mastChangeDirection)
                    {
                        ChangeDirection(MoveDirection.Freeze);
                    }
                }
                break;

            case MoveDirection.Right:
                if (point2F.x >= 424)
                {
                    point2F.x = 0f;
                }
                if (CanMove(_moveDirection, tileMap, point2F.x + _objectSpeed, point2F.y))
                {
                    point2F.x += _objectSpeed;
                }
                else
                {
                    point2F.x = ((int)((point2F.x + _objectSpeed) / 16f)) * 16;
                    if (!mastChangeDirection)
                    {
                        ChangeDirection(MoveDirection.Freeze);
                    }
                }
                break;

            case MoveDirection.Freeze:
                SetInTile(point2F);
                break;
            }
        }