Example #1
0
    // This is specific to squares.
    public Vector2 CheckColPhys(TwoColSquarePlat other, ref TwoCommon tCommon)
    {
        Vector2 output = Vector2.zero;

        foreach (TwoCol e in twoCol)
        {
            if (e == other || !e.CanCollide(other))
            {
                continue;
            }

            Vector2 vec = Vector2.zero;
            if (e.GetType() == typeof(TwoColSquarePlat))
            {
                vec = other.CheckColSquarePhys((TwoColSquarePlat)e, ref tCommon);
            }
            else if (e.GetType() == typeof(TwoColLine))
            {
                if (tCommon.YSpeed <= 0.0f)
                {
                    vec          = other.CheckCol(e);
                    tCommon.Pos += vec;
                }
            }
            else
            {
                vec          = other.CheckCol(e);
                tCommon.Pos += vec;
            }

            if (vec != Vector2.zero)
            {
                output += vec;
            }
        }

        // No collisions.
        return(output);
    }
Example #2
0
    void Awake()
    {
        tColSquare = GetComponent <TwoColSquarePlat> ();

        tCommon = GetComponent <TwoCommon> ();
    }
Example #3
0
    public Vector2 CheckColSquarePhys(TwoColSquarePlat other, ref TwoCommon tCommon)
    {
        if (!CheckColBounds(other))
        {
            return(Vector2.zero);
        }

        float safe = 1.5f;

        // Check for X collision.
        if (other.Sides == ColSides.ALL ||
            other.Sides == ColSides.LEFT ||
            other.Sides == ColSides.RIGHT)
        {
            if (
                (BL.x + tCommon.Vel.x < other.TR.x) &&
                (TR.x + tCommon.Vel.x > other.BL.x) &&
                (BL.y - tCommon.Vel.y + safe < other.TR.y) &&
                (TR.y - tCommon.Vel.y - safe > other.BL.y)
                )
            {
                if (Center.x < other.Center.x &&
                    (other.Sides == ColSides.ALL ||
                     other.Sides == ColSides.LEFT)
                    )
                {
                    tCommon.X = other.BL.x - localTR.x;
                    return(-Vector2.right);
                }
                else if (other.Sides == ColSides.ALL ||
                         other.Sides == ColSides.RIGHT)
                {
                    tCommon.X = other.TR.x - localBL.x;
                    return(Vector2.right);
                }
            }
        }

        if (other.Sides == ColSides.ALL ||
            other.Sides == ColSides.UP ||
            other.Sides == ColSides.DOWN)
        {
            // Check for Y collision.
            if (
                (BL.x - tCommon.Vel.x + safe < other.TR.x) &&
                (TR.x - tCommon.Vel.x - safe > other.BL.x) &&
                (BL.y + tCommon.Vel.y < other.TR.y) &&
                (TR.y + tCommon.Vel.y > other.BL.y)
                )
            {
                if (Center.y < other.Center.y &&
                    (other.Sides == ColSides.ALL ||
                     other.Sides == ColSides.DOWN)
                    )
                {
                    tCommon.Y = other.BL.y - localTR.y;
                    return(-Vector2.up);
                }
                /* LEAVE IT! It works for the one way platforms! */
                else if (BL.y > other.TR.y - safe + tCommon.YSpeed &&
                         tCommon.YSpeed < 0.0f &&
                         (other.Sides == ColSides.ALL ||
                          other.Sides == ColSides.UP)
                         )
                {
                    tCommon.Y = other.TR.y + localBL.y;
                    return(Vector2.up);
                }
            }
        }

        return(Vector2.zero);
    }