Beispiel #1
0
        /// <summary>
        /// Get the next player position, and send an event for each feedback.
        /// </summary>
        /// <param name="coordPos"></param>
        public void PlayerMoveFeedback(Vector2Int coordPos)
        {
            Vector2Int coordPosInt = new Vector2Int(coordPos.x, coordPos.y);
            Vector2Int matrixPos   = CoordinatesConverter.CoordinateToMatrixIndex(coordPosInt, SharedVariables.matrixDimensions.x);

            if (IsPositionOutOfBounds(matrixPos))
            {
                OnCollided.Invoke(false);
                return;
            }
            else if (Matrix[matrixPos.x, matrixPos.y] == GridTags.Inaccessible.GetHashCode())    //snake has collided
            {
                OnCollided.Invoke(false);
            }
            else if (Matrix[matrixPos.x, matrixPos.y] == GridTags.Item.GetHashCode())    //snake collected an item
            {
                OnItemCollected.Invoke(coordPos);
            }
            else//the path is free , you can walk
            {
                OnFreePathOcurred.Invoke(coordPos);
            }
            OnChangeMatrixValue.Invoke(matrixPos, GridTags.Inaccessible);
            Matrix[matrixPos.x, matrixPos.y] = GridTags.Inaccessible.GetHashCode();
        }
Beispiel #2
0
        /// <summary>
        /// Set an matrix position to 'Empty'
        /// </summary>
        /// <param name="pos"></param>
        public void RemoveValueFromMatrix(Vector2 pos)
        {
            Vector2Int posInt = new Vector2Int((int)pos.x, (int)pos.y);

            posInt = CoordinatesConverter.CoordinateToMatrixIndex(posInt, SharedVariables.matrixDimensions.x);
            Matrix[(int)posInt.x, (int)posInt.y] = GridTags.Empty.GetHashCode();
            OnChangeMatrixValue.Invoke(posInt, GridTags.Empty);
        }
Beispiel #3
0
        void SpawnItem()
        {
            int randomItem = Random.Range(0, items.Length);

            currentItem = items[randomItem];    //get random item
            int        randomSpawnPoint = Random.Range(0, possibleSpawnPoints.Count);
            Vector2Int spawnPoint       = possibleSpawnPoints[randomSpawnPoint];

            OnItemSpawned.Invoke(spawnPoint);
            SetPossibleSpawnPoints(CoordinatesConverter.CoordinateToMatrixIndex(spawnPoint, SharedVariables.matrixDimensions.x), GridTags.Item);
        }
Beispiel #4
0
        public void FirstSpawn()
        {
            currentItem = items[0];

            if (possibleSpawnPoints.Contains(Vector2Int.one))
            {
                possibleSpawnPoints.Remove(Vector2Int.one);
            }

            Vector2Int spawnPoint = possibleSpawnPoints[Random.Range(0, possibleSpawnPoints.Count)];

            OnItemSpawned.Invoke(spawnPoint);
            SetPossibleSpawnPoints(CoordinatesConverter.CoordinateToMatrixIndex(spawnPoint, SharedVariables.matrixDimensions.x), GridTags.Item);
        }
Beispiel #5
0
        /// <summary>
        /// Add an Item (food) element to the matrix.
        /// </summary>
        /// <param name="pos"></param>
        public void AddItemToMatrix(Vector2Int pos)
        {
            Vector2Int posInt = CoordinatesConverter.CoordinateToMatrixIndex(new Vector2Int((int)pos.x, (int)pos.y), SharedVariables.matrixDimensions.x);

            Matrix[posInt.x, posInt.y] = GridTags.Item.GetHashCode();
        }