Ejemplo n.º 1
0
    Vector2Int DoStaticCollisions(Vector2Int toMove)
    {
        Vector2Int vTempPos    = toMove;
        Vector2Int vCheckedPos = toMove;

        CollFlags = eCollFlags.NONE;
        //2D AABB 专用碰撞算法
        if (IsCollidingAABB(vCheckedPos))
        {
            //if(!canSlide)return vTempPos;
            //m_speed = 0f;
            vCheckedPos.y = owner.posYInt;
            if (!IsCollidingAABB(vCheckedPos))
            {
                vTempPos.y = owner.posYInt;
                CollFlags |= vTempPos.y > toMove.y? eCollFlags.DOWN : eCollFlags.UP;
            }
            else
            {
                vCheckedPos   = toMove;
                vCheckedPos.x = owner.posXInt;
                if (!IsCollidingAABB(vCheckedPos))
                {
                    vTempPos.x = owner.posXInt;
                    CollFlags |= vTempPos.x > toMove.x? eCollFlags.LEFT : eCollFlags.RIGHT;
                }
                else
                {
                    vTempPos.x = owner.posXInt;
                    vTempPos.y = owner.posYInt;

                    CollFlags |= vTempPos.y > toMove.y? eCollFlags.DOWN : eCollFlags.UP;
                    CollFlags |= vTempPos.x > toMove.x? eCollFlags.LEFT : eCollFlags.RIGHT;
                }
            }
        }
        else
        {
        }

        return(vTempPos);
    }
Ejemplo n.º 2
0
        void DoCollisions()
        {
            Vector3 vTempPos    = transform.position;
            Vector3 vCheckedPos = transform.position;

            CollFlags = eCollFlags.NONE;
            if (IsColliding(vCheckedPos))
            {
                //m_speed = 0f;
                vCheckedPos.y = m_vPrevPos.y;
                if (!IsColliding(vCheckedPos))
                {
                    vTempPos.y = m_vPrevPos.y;
                    CollFlags |= m_vPrevPos.y > transform.position.y? eCollFlags.DOWN : eCollFlags.UP;
                }
                else
                {
                    vCheckedPos   = transform.position;
                    vCheckedPos.x = m_vPrevPos.x;
                    if (!IsColliding(vCheckedPos))
                    {
                        vTempPos.x = m_vPrevPos.x;
                        CollFlags |= m_vPrevPos.x > transform.position.x? eCollFlags.LEFT : eCollFlags.RIGHT;
                    }
                    else
                    {
                        vTempPos   = m_vPrevPos;
                        CollFlags |= m_vPrevPos.y > transform.position.y? eCollFlags.DOWN : eCollFlags.UP;
                        CollFlags |= m_vPrevPos.x > transform.position.x? eCollFlags.LEFT : eCollFlags.RIGHT;
                    }
                }
                transform.position = vTempPos;
            }
            else
            {
                //image_blend = c_white;
            }
            transform.position = vTempPos;
            m_vPrevPos         = transform.position;
        }
 void DoCollisions()
 {
     Vector3 vTempPos = transform.position;
     Vector3 vCheckedPos = transform.position;
     CollFlags = eCollFlags.NONE;
     if( IsColliding( vCheckedPos ) )
     {
         //m_speed = 0f;
         vCheckedPos.y = m_vPrevPos.y;
         if( !IsColliding( vCheckedPos ) )
         {
             vTempPos.y = m_vPrevPos.y;
             CollFlags |= m_vPrevPos.y > transform.position.y? eCollFlags.DOWN : eCollFlags.UP;
         }
         else
         {
             vCheckedPos = transform.position;
             vCheckedPos.x = m_vPrevPos.x;
             if( !IsColliding( vCheckedPos ) )
             {
                 vTempPos.x = m_vPrevPos.x;
                 CollFlags |= m_vPrevPos.x > transform.position.x? eCollFlags.LEFT : eCollFlags.RIGHT;
             }
             else
             {
                 vTempPos = m_vPrevPos;
                 CollFlags |= m_vPrevPos.y > transform.position.y? eCollFlags.DOWN : eCollFlags.UP;
                 CollFlags |= m_vPrevPos.x > transform.position.x? eCollFlags.LEFT : eCollFlags.RIGHT;
             }
         }
         transform.position = vTempPos;
     }
     else
     {
         //image_blend = c_white;
     }
     transform.position = vTempPos;
     m_vPrevPos = transform.position;
 }