Exemplo n.º 1
0
 void Update()
 {
     if (gameData.Playing)
     {
         positionOfInterest = levelCreator.Scan(cam.transform.position, cam.transform.forward, rayCastDistance);
     }
 }
Exemplo n.º 2
0
        private void HandleTrigger()
        {
            PositionData pd = levelCreator.GetCurrentTarget();

            Debug.Assert(pd == positionOfInterest);

            if (pd != null)
            {
                switch (pd.occupant)
                {
                case PositionData.OccupantType.None:
                    Debug.LogFormat("Hit empty panel {0}", pd.landingQuad.startTriangleIndex);

                    if (currentTravelRoutine != null)
                    {
                        StopCoroutine(currentTravelRoutine);
                    }

                    Vector3 mid   = Vector3.Lerp(player.transform.position, levelCreator.transform.TransformPoint(pd.centrePos), .5f);
                    Vector3 cross = Vector3.Cross(player.transform.forward, player.transform.right);
                    Vector3 apex  = mid + cross * curveHeight;
                    curve.CalcPoints(new Vector3[] { player.transform.position, apex, levelCreator.transform.TransformPoint(pd.centrePos) });
                    currentTravelRoutine = StartCoroutine(FollowPath(curve.Points));

                    break;

                case PositionData.OccupantType.Boss:
                    Debug.LogFormat("Hit boss panel");
                    gameData.WonGame();
                    StartCoroutine(WinGame());
                    break;
                }
            }
        }
Exemplo n.º 3
0
 private void HighlightQuad(PositionData pd)
 {
     colorBuffer[pd.landingQuad.ixBottomLeft]  = highlightColor;
     colorBuffer[pd.landingQuad.ixTopLeft]     = highlightColor;
     colorBuffer[pd.landingQuad.ixTopRight]    = highlightColor;
     colorBuffer[pd.landingQuad.ixBottomRight] = highlightColor;
 }
Exemplo n.º 4
0
        public int[] GetEmptyPositions()
        {
            List <int> indices = new List <int>(positionIndices);

            for (int i = 0; i < positionIndices.Length; i++)
            {
                PositionData pd = FindPositionData(positionIndices[i]);
                if (pd != null)
                {
                    if (pd.occupant == PositionData.OccupantType.None)
                    {
                        indices.Add(positionIndices[i]);
                    }
                    else
                    {
                        Debug.LogFormat("Skipped index {0} as it's not empty: contains {1}",
                                        pd.landingQuad.startTriangleIndex, pd.occupant);
                    }
                }
                else
                {
                    Debug.LogFormat("No data at index {0}", i);
                }
            }

            return(indices.ToArray());
        }
Exemplo n.º 5
0
 public PositionData SetPlayerAt()
 {
     if (triangleHitIndex >= 0)
     {
         PositionData current = FindPositionData(triangleHitIndex);
         if (current != null)
         {
             PlaceOccupant(current, PositionData.OccupantType.Player);
             return(current);
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        public PositionData SetObjectAt(Transform thing, PositionData.OccupantType ot, int index)
        {
            PositionData pd = FindPositionData(index);

            if (pd != null)
            {
                Debug.LogFormat("Placing occupant {0} at index {1}", ot, index);

                thing.transform.position = transform.TransformPoint(pd.centrePos);
                pd.occupant = ot;
                return(pd);
            }
            return(null);
        }
Exemplo n.º 7
0
        public void ClearCurrentTarget()
        {
            if (triangleHitIndex >= 0)
            {
                ResetColorBuffer();

                PositionData prev = FindPositionData(triangleHitIndex);
                if (prev != null)
                {
                    if (prev.occupant == PositionData.OccupantType.Player)
                    {
                        Debug.LogFormat("Clearing Player occupancyat index {0}", prev.landingQuad.startTriangleIndex);

                        prev.occupant = PositionData.OccupantType.None;
                    }
                }
            }
        }
Exemplo n.º 8
0
        public bool CreateObjectAt(GameObject template, PositionData.OccupantType ot, int index)
        {
            PositionData pd = FindPositionData(index);

            if (pd != null)
            {
                Debug.LogFormat("Creating occupant {0} at index {1}", ot, index);

                if (pd.occupant != PositionData.OccupantType.None)
                {
                    Debug.LogWarningFormat("Trying to place {0} but position occupied by {1}!", ot, pd.occupant);
                    return(false);
                }
                GameObject go = gameData.GetObject(template);
                go.transform.position = transform.TransformPoint(pd.centrePos);
                pd.occupant           = ot;
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="direction"></param>
        /// <param name="distance"></param>
        /// <param name="layer"></param>
        /// <param name="lookForObstruction">If we're about to move to a valid destination, check if there are any obstructions</param>
        public PositionData Scan(Vector3 startPoint, Vector3 direction, float distance)
        {
            if (!ready)
            {
                return(null);
            }

            int          newHitIndex = -1;
            PositionData newPosition = null;

            bool gotHit = Physics.Raycast(startPoint, direction, out RaycastHit hit, distance, ourLayer);

            if (gotHit) // New hit
            {
                newPosition = FindPositionData(hit.triangleIndex);
                if (newPosition != null)
                {
                    // It's a valid landing spot.
                    newHitIndex = newPosition.landingQuad.startTriangleIndex;
                }
            }

            if (newHitIndex != triangleHitIndex)
            {
                ClearCurrentTarget();

                if (newHitIndex >= 0)
                {
                    HighlightQuad(newPosition);
                }

                triangleHitIndex = newHitIndex;
                UpdateColors();
            }

            return(newPosition);
        }
Exemplo n.º 10
0
 private void PlayScan()
 {
     positionOfInterest = levelCreator.Scan(cam.transform.position, cam.transform.forward, rayCastDistance);
 }
Exemplo n.º 11
0
        public void PlaceOccupant(PositionData pd, PositionData.OccupantType ot)
        {
            Debug.LogFormat("Placing occupant {0} at index {1}", ot, pd.landingQuad.startTriangleIndex);

            pd.occupant = ot;
        }