Beispiel #1
0
    public MinMaxBounds GetExtents()
    {
        Vector2 max = -_centerDelta + new Vector3(_boundsRenderer.extents.x, _boundsRenderer.extents.y, 0f);
        Vector2 min = -_centerDelta + new Vector3(-_boundsRenderer.extents.x, -_boundsRenderer.extents.y, 0f);

        MinMaxBounds extents = new MinMaxBounds(min, max);

        return(extents);
    }
    public static MinMaxBounds GetBoundary(this Camera cam)
    {
        MinMaxBounds boundary = new MinMaxBounds();

        boundary.Min = cam.GetMinBoundary();
        boundary.Max = cam.GetMaxBoundary();

        return(boundary);
    }
Beispiel #3
0
    // ----- [ Functions ] ---------------------------------------------

    // --v-- AEntity Override --v--

    /// <summary>
    /// No Padding for enemies.
    /// </summary>
    public override MinMaxBounds GetBoundaryPositionIn()
    {
        MinMaxBounds boundaryEntityIn = new MinMaxBounds();
        MinMaxBounds BoundaryMap      = GameManager.Instance.MapInfo.Boundary;

        boundaryEntityIn.Max = new Vector2(BoundaryMap.Max.x - _boundsRenderer.extents.x, BoundaryMap.Max.y - _boundsRenderer.extents.y);
        boundaryEntityIn.Min = new Vector2(BoundaryMap.Min.x + _boundsRenderer.extents.x, BoundaryMap.Min.y + _boundsRenderer.extents.y);

        return(boundaryEntityIn);
    }
Beispiel #4
0
    public virtual MinMaxBounds GetBoundaryPositionOut()
    {
        MinMaxBounds boundaryEntityOut = new MinMaxBounds();
        MinMaxBounds BoundaryMapOut    = GameManager.Instance.MapInfo.BoundaryOut;

        boundaryEntityOut.Max = new Vector2(BoundaryMapOut.Max.x + _boundsRenderer.extents.x, BoundaryMapOut.Max.y + _boundsRenderer.extents.y);
        boundaryEntityOut.Min = new Vector2(BoundaryMapOut.Min.x - _boundsRenderer.extents.x, BoundaryMapOut.Min.y - _boundsRenderer.extents.y);

        return(boundaryEntityOut);
    }
Beispiel #5
0
    private Vector3 CalcStopDestination()
    {
        MinMaxBounds mapBoundary = GameManager.Instance.MapInfo.Boundary;

        float maxDistance = mapBoundary.Max.x - mapBoundary.Min.x;
        float distance    = (maxDistance / 100f) * _destinationDist;

        Vector3 destination = new Vector3(transform.position.x - distance, transform.position.y, transform.position.z);

        return(destination);
    }
Beispiel #6
0
    // --v-- Abstract AEntity --v--

    public override MinMaxBounds GetBoundaryPositionOut()
    {
        MinMaxBounds boundaryEntityOut = new MinMaxBounds();
        MinMaxBounds BoundaryMapOut    = GameManager.Instance.MapInfo.BoundaryOut;

        float extent = _particleSys.shape.radius;

        boundaryEntityOut.Max = new Vector2(BoundaryMapOut.Max.x + extent, BoundaryMapOut.Max.y + extent);
        boundaryEntityOut.Min = new Vector2(BoundaryMapOut.Min.x - extent, BoundaryMapOut.Min.y - extent);

        return(boundaryEntityOut);
    }
Beispiel #7
0
    // --v-- Draw Gizmos --v--

    public void OnDrawGizmos()
    {
        MinMaxBounds camBoundary = Camera.main.GetBoundary();

        if (_shouldDisplayPadding)
        {
            Vector3 a = new Vector3(camBoundary.Max.x - _boundsPadding, camBoundary.Min.y + _boundsPadding);
            Vector3 b = new Vector3(camBoundary.Max.x - _boundsPadding, camBoundary.Max.y - _boundsPadding - GetExtraPaddingTopValue());
            Vector3 c = new Vector3(camBoundary.Min.x + _boundsPadding, camBoundary.Max.y - _boundsPadding - GetExtraPaddingTopValue());
            Vector3 d = new Vector3(camBoundary.Min.x + _boundsPadding, camBoundary.Min.y + _boundsPadding);

            Gizmos.color = Color.red;

            Gizmos.DrawLine(a, b);
            Gizmos.DrawLine(b, c);
            Gizmos.DrawLine(c, d);
            Gizmos.DrawLine(d, a);
        }

        if (_shouldDisplayMargin)
        {
            Vector3 a = new Vector3(camBoundary.Max.x + _boundsMargin, camBoundary.Min.y - _boundsMargin);
            Vector3 b = new Vector3(camBoundary.Max.x + _boundsMargin, camBoundary.Max.y + _boundsMargin);
            Vector3 c = new Vector3(camBoundary.Min.x - _boundsMargin, camBoundary.Max.y + _boundsMargin);
            Vector3 d = new Vector3(camBoundary.Min.x - _boundsMargin, camBoundary.Min.y - _boundsMargin);

            Gizmos.color = Color.red;

            Gizmos.DrawLine(a, b);
            Gizmos.DrawLine(b, c);
            Gizmos.DrawLine(c, d);
            Gizmos.DrawLine(d, a);
        }

        if (_shouldDisplayBounds)
        {
            Vector3 a = new Vector3(camBoundary.Max.x, camBoundary.Min.y);
            Vector3 b = new Vector3(camBoundary.Max.x, camBoundary.Max.y);
            Vector3 c = new Vector3(camBoundary.Min.x, camBoundary.Max.y);
            Vector3 d = new Vector3(camBoundary.Min.x, camBoundary.Min.y);

            Gizmos.color = Color.white;

            Gizmos.DrawLine(a, b);
            Gizmos.DrawLine(b, c);
            Gizmos.DrawLine(c, d);
            Gizmos.DrawLine(d, a);
        }
    }
Beispiel #8
0
    private void CalculateMovementRestriction()
    {
        //
        // for the following, we are assuming the main camera is orthonorme
        // Boundaries will be calculated based on the main camera
        //

        MinMaxBounds positionBoundary = GetBoundaryPositionIn();

        if (positionBoundary.Min.x > positionBoundary.Max.x || positionBoundary.Min.y > positionBoundary.Max.y)
        {
            Debug.LogWarning("The player is too big for the boundary. Boundaries are disabled");
            return;
        }

        float x = Mathf.Clamp(transform.position.x, positionBoundary.Min.x, positionBoundary.Max.x);
        float y = Mathf.Clamp(transform.position.y, positionBoundary.Min.y, positionBoundary.Max.y);

        transform.position = new Vector3(x, y, 0);
    }
Beispiel #9
0
    public bool IsOutOfBoundary(BoundaryType BoundaryType)
    {
        MinMaxBounds bulletBoundary = null;

        switch (BoundaryType)
        {
        case BoundaryType.IN:
            bulletBoundary = GetBoundaryPositionIn();
            break;

        case BoundaryType.OUT:
            bulletBoundary = GetBoundaryPositionOut();
            break;

        default:
            bulletBoundary = GetBoundaryPositionIn();
            Debug.LogWarning("[AEntity] BoundaryType switch is default case.");
            break;
        }

        if (!Utils.IsValueInRange(transform.position.x, bulletBoundary.Min.x, bulletBoundary.Max.x))
        {
            // Out of bound on the Horizontal axis (X)
            return(true);
        }

        if (!Utils.IsValueInRange(transform.position.y, bulletBoundary.Min.y, bulletBoundary.Max.y))
        {
            // Out of bound on the Vertical axis (Y)
            return(true);
        }



        return(false);
    }
Beispiel #10
0
 public MapInfo()
 {
     Boundary    = new MinMaxBounds();
     BoundaryIn  = new MinMaxBounds();
     BoundaryOut = new MinMaxBounds();
 }