Пример #1
0
    /// <summary>
    /// Casts a ray looking for direction signals. If any are found, returns its state.
    /// </summary>
    float LookForDirection()
    {
        float returnValue = 0f;

        RaycastHit hit;
        Vector3    fromPosition = transform.position + transform.forward * 1.1f;
        Vector3    direction    = transform.TransformDirection(new Vector3(0, 0, 1).normalized);

        if (Physics.Raycast(fromPosition, direction, out hit, directions_range, ~carsLayer))
        {
            if (hit.collider.tag.Equals("IntersectionTrigger"))
            {
                // Direction sign found!
                returnValue =
                    hit.collider.gameObject.
                    GetComponentInParent <DirectionSignalController>().GetDirectionAsFloat();

                // Write down the expected outcome:
                isDirectionPending = true;

                // Left is returnValue 0.33, more than that is straight or right
                if (returnValue < 0.4)
                {
                    expectedDirection = DirectionTaken.left;
                }
                else
                {
                    expectedDirection = DirectionTaken.rightOrStraight;
                }
            }
        }

        return(returnValue);
    }
Пример #2
0
        internal Coordinates GetAdjecentCellCoordinates(Coordinates c, DirectionTaken d)
        {
            switch (d)
            {
            case DirectionTaken.Up: if (IsInBounds(c.X, c.Y - 1))
                {
                    return new Coordinates {
                               X = c.X, Y = c.Y - 1, Val = GetVal(c.X, c.Y - 1)
                    }
                }
                ; break;

            case DirectionTaken.Down: if (IsInBounds(c.X, c.Y + 1))
                {
                    return new Coordinates {
                               X = c.X, Y = c.Y + 1, Val = GetVal(c.X, c.Y + 1)
                    }
                }
                ; break;

            case DirectionTaken.Left: if (IsInBounds(c.X - 1, c.Y))
                {
                    return new Coordinates {
                               X = c.X - 1, Y = c.Y, Val = GetVal(c.X - 1, c.Y)
                    }
                }
                ; break;

            case DirectionTaken.Right: if (IsInBounds(c.X + 1, c.Y))
                {
                    return new Coordinates {
                               X = c.X + 1, Y = c.Y, Val = GetVal(c.X + 1, c.Y)
                    }
                }
                ; break;
            }

            return(null);
        }
Пример #3
0
 internal DirectionTaken GetOppositeDirection(DirectionTaken dt)
 {
     if (dt == DirectionTaken.Left)
     {
         return(DirectionTaken.Right);
     }
     else if (dt == DirectionTaken.Right)
     {
         return(DirectionTaken.Left);
     }
     else if (dt == DirectionTaken.Up)
     {
         return(DirectionTaken.Down);
     }
     else if (dt == DirectionTaken.Down)
     {
         return(DirectionTaken.Up);
     }
     else
     {
         return(DirectionTaken.Random);
     }
 }
Пример #4
0
        internal List <Coordinates> GetAdjacentTargets(Coordinates c, Orientation o, DirectionTaken dt)
        {
            List <Coordinates> tempCoords = new List <Coordinates>();
            Coordinates        t          = null;

            if (dt != DirectionTaken.Random)
            {
                t = GetAdjecentCellCoordinates(c, dt);
                if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                {
                    tempCoords.Add(t);
                }
            }
            else
            {
                if (o == Orientation.Random)
                {
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Up);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Down);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Left);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Right);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                }
                else if (o == Orientation.Vertical)
                {
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Up);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Down);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                }
                else if (o == Orientation.Horizontal)
                {
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Left);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                    t = GetAdjecentCellCoordinates(c, DirectionTaken.Right);
                    if (t != null && !Board.Grid[t.X, t.Y].IsShot)
                    {
                        tempCoords.Add(t);
                    }
                }
            }
            return(tempCoords);
        }