コード例 #1
0
ファイル: PlayerMovement.cs プロジェクト: lswzzz/BombMan
    public void NormalMovement()
    {
        switch (direction)
        {
        case PlayerDirection.Left:
            transform.position = new Vector3(transform.position.x - speed * Time.deltaTime,
                                             transform.position.y, transform.position.z);
            popDirection = PlayerBoxUpdate.PopDirection.HORIZONTAL;
            break;

        case PlayerDirection.Right:
            transform.position = new Vector3(transform.position.x + speed * Time.deltaTime,
                                             transform.position.y, transform.position.z);
            popDirection = PlayerBoxUpdate.PopDirection.HORIZONTAL;
            break;

        case PlayerDirection.Up:
            transform.position = new Vector3(transform.position.x,
                                             transform.position.y + speed * Time.deltaTime,
                                             transform.position.z);
            popDirection = PlayerBoxUpdate.PopDirection.VERTICAL;
            break;

        case PlayerDirection.Down:
            transform.position = new Vector3(transform.position.x,
                                             transform.position.y - speed * Time.deltaTime,
                                             transform.position.z);
            popDirection = PlayerBoxUpdate.PopDirection.VERTICAL;
            break;
        }
    }
コード例 #2
0
    void Update()
    {
        updateMovement();
        switch (targetDirection)
        {
        case PlayerDirection.Left:
        case PlayerDirection.Right:
            popDirection = PlayerBoxUpdate.PopDirection.HORIZONTAL;
            break;

        case PlayerDirection.Up:
        case PlayerDirection.Down:
            popDirection = PlayerBoxUpdate.PopDirection.VERTICAL;
            break;
        }
        boxUpdate.RobotUpdate(popDirection);
    }
コード例 #3
0
ファイル: PlayerMovement.cs プロジェクト: lswzzz/BombMan
    //direct.y为负1表示往下方移动
    //isNormal 表示player正对方向有块 否则表示没有块
    public void SpecialMovement(Vector2 direct, bool isNormal)
    {
        switch (direction)
        {
        case PlayerDirection.Left:
        case PlayerDirection.Right:
            if (direct.y < 0)
            {
                float newY = transform.position.y + speed * Time.deltaTime;
                if (!isNormal)
                {
                    Vector2 pos       = getCenterPos();
                    float   positionY = colliderBox.getTransformPosY(pos.y);
                    if (newY > positionY)
                    {
                        newY = positionY;
                    }
                }
                transform.position = new Vector3(transform.position.x,
                                                 newY,
                                                 transform.position.z);
            }
            else
            {
                float newY = transform.position.y - speed * Time.deltaTime;
                if (!isNormal)
                {
                    Vector2 pos       = getCenterPos();
                    float   positionY = colliderBox.getTransformPosY(pos.y);
                    if (newY < positionY)
                    {
                        newY = positionY;
                    }
                }
                transform.position = new Vector3(transform.position.x,
                                                 newY,
                                                 transform.position.z);
            }
            popDirection = PlayerBoxUpdate.PopDirection.VERTICAL;
            break;

        case PlayerDirection.Up:
        case PlayerDirection.Down:
            if (direct.x < 0)
            {
                float newX = transform.position.x - speed * Time.deltaTime;
                if (!isNormal)
                {
                    Vector2 pos       = getCenterPos();
                    float   positionX = colliderBox.getTransformPosX(pos.x);
                    if (newX < positionX)
                    {
                        newX = positionX;
                    }
                }
                transform.position = new Vector3(newX,
                                                 transform.position.y,
                                                 transform.position.z);
            }
            else
            {
                float newX = transform.position.x + speed * Time.deltaTime;
                if (!isNormal)
                {
                    Vector2 pos       = getCenterPos();
                    float   positionX = colliderBox.getTransformPosX(pos.x);
                    if (newX > positionX)
                    {
                        newX = positionX;
                    }
                }
                transform.position = new Vector3(newX,
                                                 transform.position.y,
                                                 transform.position.z);
            }
            popDirection = PlayerBoxUpdate.PopDirection.HORIZONTAL;
            break;
        }
    }