Terrarium.Game.WorldState.OnlyOverlapsSelf C# (CSharp) Method

OnlyOverlapsSelf() public method

Make sure the organism only overlaps itself and not other organisms.
public OnlyOverlapsSelf ( OrganismBase.OrganismState state ) : System.Boolean
state OrganismBase.OrganismState The state of the organism to check.
return System.Boolean
        public Boolean OnlyOverlapsSelf(OrganismState state)
        {
            Debug.Assert(IndexBuilt);

            var minGridX = state.GridX - state.CellRadius;
            var maxGridX = state.GridX + state.CellRadius;
            var minGridY = state.GridY - state.CellRadius;
            var maxGridY = state.GridY + state.CellRadius;

            // If it would be out of bounds, return false.
            if (minGridX < 0 || maxGridX > _gridWidth - 1 ||
                minGridY < 0 || maxGridY > _gridHeight - 1)
            {
                return false;
            }

            for (var x = minGridX; x <= maxGridX; x++)
            {
                for (var y = minGridY; y <= maxGridY; y++)
                {
                    if (_cellOrganisms[x, y] == null) continue;
                    if (_cellOrganisms[x, y].ID != state.ID)
                    {
                        return false;
                    }
                }
            }

            return true;
        }