Esempio n. 1
0
    /**
     * 1 - above, -1 - below
     */
    protected Collider2D WallAboveOrBelow(int direction)
    {
        var epsX = _ctx.minDistToWall;
        // TODO: this too
        var epsY = 0.06f;

        var bounds  = _ctx.collider.bounds;
        var boxPosY = direction == Below ? bounds.min.y - epsY / 2 : bounds.max.y + epsY / 2;
        var boxPos  = new Vector2(bounds.center.x, boxPosY);
        var boxSize = new Vector2(bounds.size.x - epsX * 2, epsY);
        var hit     = Physics2D.OverlapBox(boxPos, boxSize, 0, _ctx.platformMask);

        var color = hit != null ? Color.green : Color.red;

        CustomDebug.DebugDrawBox(boxPos, boxSize, color);

        return(hit);
    }
Esempio n. 2
0
    protected Collider2D GetWall(int direction)
    {
        var bounds  = _ctx.collider.bounds;
        var boxPosY = bounds.min.y + bounds.size.y * 0.5f;
        var boxSize = new Vector2(_wallEpsX, bounds.size.y);

        Func <int, Vector2> getBoxPosition = (dir) => {
            var colliderBoundX = dir == Left ? bounds.min.x : bounds.max.x;
            var boxPosX        = colliderBoundX + dir * _wallEpsX / 2;

            return(new Vector2(boxPosX, boxPosY));
        };

        var hit   = Physics2D.OverlapBox(getBoxPosition(direction), boxSize, 0, _ctx.platformMask);
        var color = hit ? Color.green : Color.red;

        CustomDebug.DebugDrawBox(getBoxPosition(direction), boxSize, color);
        return(hit);
    }
Esempio n. 3
0
    protected int IsWalled()
    {
        var bounds  = _ctx.collider.bounds;
        var boxSize = new Vector2(_wallEpsX, bounds.size.y * 0.05f);
        Func <int, Vector2[]> getBoxPositions = (direction) => {
            var colliderBoundX = direction == Left ? bounds.min.x : bounds.max.x;
            var boxPosX        = colliderBoundX + direction * _wallEpsX / 2;
            var boxPosY1       = bounds.min.y + bounds.size.y * 0.225f;
            var boxPosY2       = bounds.min.y + bounds.size.y * 0.55f;
            var boxPosY3       = bounds.min.y + bounds.size.y * 0.875f;

            return(new[] {
                new Vector2(boxPosX, boxPosY1),
                new Vector2(boxPosX, boxPosY2),
                new Vector2(boxPosX, boxPosY3)
            });
        };

        Func <int, bool> getHit = (direction) => {
            var resultHit = getBoxPositions(direction)
                            .Select(pos => {
                var hit   = Physics2D.OverlapBox(pos, boxSize, 0, _ctx.platformMask);
                var color = hit != null ? Color.green : Color.red;
                CustomDebug.DebugDrawBox(pos, boxSize, color);
                return(hit);
            })
                            .All(hit => hit != null);

            return(resultHit);
        };

        if (getHit(Left))
        {
            return(Left);
        }
        if (getHit(Right))
        {
            return(Right);
        }

        return(0);
    }