Пример #1
0
    public Transform GetTileFromPosition(Vector3 position)
    {
        int x = Mathf.RoundToInt(position.x / tileSize + (mapSize - 1) / 2f);
        int y = Mathf.RoundToInt(position.z / tileSize + (mapSize - 1) / 2f);

        x = Mathf.Clamp(x, 0, tileMap.GetLength(0) - 1);
        y = Mathf.Clamp(y, 0, tileMap.GetLength(1) - 1);
        return(tileMap[x, y]);
    }
Пример #2
0
    internal void updateGrid()
    {
        // start by assigning all indeces to null
        for (int i = 0; i < gridMatrix.GetLength(0); i++)
        {
            for (int j = 0; j < gridMatrix.GetLength(1); j++)
            {
                gridMatrix[i, j] = null;
            }
        }

        // assign all of the gameObjects in the grid to their appropriate spots

        foreach (Transform child in transform)
        {
            if (child.tag.Equals("Player") || child.tag.Equals("Wall")) // add Goal later.
            {
                //Debug.Log("Found a player tag.");
                int gridCoordX = GameUtility.gameToGridCoord(child.position.x);
                int gridCoordY = GameUtility.gameToGridCoord(child.position.y);
                gridMatrix[gridCoordX, gridCoordY] = child;
            }
            else if (
                child.tag.Equals("Block") ||
                child.tag.Equals("WallTop") ||
                child.tag.Equals("WallBottom") ||
                child.tag.Equals("WallRight") ||
                child.tag.Equals("WallLeft") ||
                child.tag.Equals("PushableBlock")
                )
            {
                foreach (Transform blockChild in child.transform)
                {
                    int gridCoordX = GameUtility.gameToGridCoord(blockChild.position.x);
                    int gridCoordY = GameUtility.gameToGridCoord(blockChild.position.y);
                    gridMatrix[gridCoordX, gridCoordY] = child;
                }
            }
        }



        /*
         * //make sure this shit is right
         * for (int i = 0; i < gridMatrix.GetLength(0); i++)
         * {
         *  for (int j = 0; j < gridMatrix.GetLength(1); j++)
         *  {
         *      if (gridMatrix[i, j] == null)
         *          Debug.Log("The cell at grid coordinate " + i + ", " + j + " is null.");
         *      else
         *          Debug.Log("The cell at grid coordinate " + i + ", " + j + " is " + gridMatrix[i, j].tag + ".");
         *  }
         * }
         */
    }
Пример #3
0
    public Transform GetTileFromPosition(Vector3 position)
    {
        int x = Mathf.RoundToInt(position.x / tileSize + (currentMap.mapSize.width - 1) / 2f);
        int y = Mathf.RoundToInt(position.z / tileSize + (currentMap.mapSize.height - 1) / 2f);

        // protect against out of bounds
        x = Mathf.Clamp(x, 0, tileMap.GetLength(0) - 1);
        y = Mathf.Clamp(y, 0, tileMap.GetLength(1) - 1);
        return(tileMap[x, y]);
    }
Пример #4
0
    public Transform GenerateMissingTile(Transform[,] map, int x, int y)
    {
        Transform obj = Instantiate(objects[Random.Range(0, objects.Count)],
                                    new Vector3(-0.5f * x + (map.GetLength(0) - 1) * 0.5f / 2.0f,
                                                (map.GetLength(1) + 3) * 0.5f / 2.0f,
                                                0f),
                                    Quaternion.identity);

        return(obj);
    }
 void resetArray()
 {
     for (int k = 0; k < mapArray.GetLength(0); k++)
     {
         for (int l = 0; l < mapArray.GetLength(1); l++)
         {
             mapArray[k, l] = null;
         }
     }
 }
 /// <summary>
 /// Prints out the grid in console
 /// </summary>
 void PrintGridToConsole()
 {
     for (int x = 0; x < Grid.GetLength(0); x++)
     {
         for (int y = 0; y < Grid.GetLength(1); y++)
         {
             Debug.Log(x + "," + y + ": " + Grid[x, y].name);
         }
     }
 }
Пример #7
0
 public void ClearStats()
 {
     for (int y = 0; y < statsMatrix.GetLength(0); y++)
     {
         for (int x = 0; y < statsMatrix.GetLength(1); x++)
         {
             statsMatrix[y, x].gameObject.SetActive(false);
             statsMatrix[y, x].SetParent(MinoPool.instance.poolParent.transform);
             statsMatrix[y, x].position = Vector2.zero;
         }
     }
 }
Пример #8
0
    public void Reset()
    {
        for (int y = 0; y < TetrisSettings.GridHeight; y++)
        {
            for (int x = 0; x < TetrisSettings.GridWidth; x++)
            {
                ClearCell(x, y);
            }
        }

        Array.Clear(visualGrid, 0, visualGrid.GetLength(0) * visualGrid.GetLength(1));
        Array.Clear(intGrid, 0, intGrid.GetLength(0) * intGrid.GetLength(1));
    }
Пример #9
0
        void Start()
        {
            if (PlayerHealth.dead)
            {
                PlayerHealth.dead = false;
            }
            //Time.fixedDeltaTime = 1f;
            p      = player;
            render = renderRange;
            lastdirection.Insert(0, new Vector3());
            player.position = new Vector3(renderRange, 0, renderRange);
            if (mapSize % 2 == 0)
            {
                mapSize++;
            }
            if (renderRange % 2 == 0)
            {
                renderRange++;
            }
            map.generate(mapSize, mapSize, 0, 0);
            groundCuboids = new Transform[renderRange, renderRange];
            for (int x = 0; x < groundCuboids.GetLength(0); x++)
            {
                for (int z = 0; z < groundCuboids.GetLength(1); z++)
                {
                    GameObject cube = Instantiate <GameObject>(groundPrefab, new Vector3(x, 0, z), Quaternion.identity, terrain);
                    //GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    //cube.AddComponent<Rigidbody>();
                    //cube.transform.position = new Vector3(x, 0, z);
                    groundCuboids[x, z] = cube.transform;
                }
            }
            cuboids = new Transform[renderRange, renderRange];
            for (int x = 0; x < cuboids.GetLength(0); x++)
            {
                for (int z = 0; z < cuboids.GetLength(1); z++)
                {
                    GameObject cube = Instantiate <GameObject>(waterPrefab, new Vector3(x, 0, z), Quaternion.identity, terrain);
                    //GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    //cube.AddComponent<Rigidbody>();
                    //cube.transform.position = new Vector3(x, 0, z);
                    cuboids[x, z] = cube.transform;
                }
            }
            //player.obj = Instantiate(player.prefab, new Vector3(renderRange/2,0,renderRange/2), Vector3.forward) as GameObject;
            //p.AddComponent<Material>();
            updateHeights();
            int loc = renderRange / 2;

            player.obj.transform.position = new Vector3(loc, cuboids[loc, loc].position.y + 1, loc);
        }
Пример #10
0
    public void DestroyBlock(int x, int y)
    {
        Vector2 v = new Vector2(x, y);
        Debug.Log("x: " + x + " y : " + y);

        if (!occupiedPos.Contains(v))
            occupiedPos.Add(v);

        if (grid.GetLength(0) > x && x > 0 && grid.GetLength(1) > y && y > 0)
        {
            iTween.ColorTo(grid[x, y].gameObject,
                iTween.Hash("time", 1.2f, "color", Color.clear, "onCompleteTarget", GameObject.Find("Grid"), "onCompleteParams", v, "onComplete", "NullBlocks"));
        }
    }
Пример #11
0
        Transform[,] GenerateTransformMap()
        {
            transformMap = new Transform[Terminologies.LengthOfOneSideOfBoard, Terminologies.LengthOfOneSideOfBoard];
            BoxCollider2D[] boxColliders = GetComponentsInChildren <BoxCollider2D>();
            for (int x = 0; x < transformMap.GetLength(0); x++)
            {
                for (int y = 0; y < transformMap.GetLength(1); y++)
                {
                    transformMap[x, y] = boxColliders[y * transformMap.GetLength(0) + x].transform;
                }
            }

            return(transformMap);
        }
Пример #12
0
 public virtual void PlaceSegments()
 {
     for (int y = 0; y < segments.GetLength(1); y++)
     {
         for (int x = 0; x < segments.GetLength(0); x++)
         {
             if (segments [x, y] == null)
             {
                 continue;
             }
             SegmentPosition(segments[x, y], x, y);
         }
     }
 }
Пример #13
0
 bool CompareMaps(Transform[,] firstMap, Transform[,] secondMap)
 {
     for (int j = 0; j < firstMap.GetLength(0); j++)
     {
         for (int k = 0; k < firstMap.GetLength(1); k++)
         {
             if (firstMap[j, k].tag != secondMap[j, k].tag)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #14
0
        private void Start()
        {
            Transform[,] columns = GetComponent <IMapProvider <Transform> >().GetMap();

            for (int x = 0; x < columns.GetLength(0); x++)
            {
                for (int y = 0; y < columns.GetLength(1); y++)
                {
                    ColumnView     columnView     = columns[x, y].gameObject.AddComponent <ColumnView>();
                    IntegerVector2 columnPosition = new IntegerVector2(x, y);
                    columnView.OnClick.TakeUntilDestroy(this).Select(_ => columnPosition).Subscribe(onColumnClicked.Invoke);
                }
            }
        }
Пример #15
0
        //Call on movement not on frame update
        public void updateHeights()
        {
            int X = cuboids.GetLength(0);
            int Z = cuboids.GetLength(1);

            for (int x = 0; x < X; x++)
            {
                for (int z = 0; z < Z; z++)
                {
                    /*Debug.Log("x: " + xShift + " : " + x);
                     * Debug.Log("z: " + zShift + " : " + z);
                     */
                    //Debug.Log("y: " + map.heightMap[xShift + x,zShift + z]);
                    //float temp = Mathf.Abs(x + z - player.x - player.z);
                    //if (temp < 10) {
                    float relHeight = (map.heightMap[-X / 2 + x + (int)(player.x), -Z / 2 + z + (int)player.z] - 0.5f) / 2;
                    //relHeight += Mathf.Clamp(temp,0,10);
                    float scale = Mathf.Max(relHeight - map.minHeight, minBlockSize);
                    relHeight = relHeight - 0.5f * scale;
                    //Instantaneous
                    groundCuboids[x, z].localPosition = new Vector3(x, relHeight - 5f, z);
                    CreateBetweenTwo(groundCuboids[x, z], relHeight - scale / 2, -10f);

                    cuboids[x, z].localPosition = new Vector3(x, relHeight, z);
                    cuboids[x, z].localScale    = new Vector3(1, scale, 1);



                    //}
                    //Asymptotic Averaging
                    //float max = speed * Time.deltaTime;


                    /*cuboids[x,z].localPosition = new Vector3(x,
                     * Mathf.Clamp(asympConst*relHeight,-max,max)
                     + (1-asympConst)*cuboids[x,z].localPosition.y,z);*/

                    /*cuboids[x,z].localScale = new Vector3 (1f,
                     * Mathf.Clamp(asympConst*scale,-max,max)
                     + (1-asympConst)*cuboids[x,z].localScale.y,1f);*/
                }
            }
            //float y = player.obj.transform.position.y;
            //float dest = map.heightMap[-X / 2 + (int)(player.x) - (int)player.obj.transform.position.x, -Z / 2 + (int)player.z - (int)player.obj.transform.position.x];

            //int loc = renderRange / 2;
            //player.obj.transform.position = new Vector3(loc, cuboids[loc, loc].position.y + 1, loc);
            //player.obj.transform.position = new Vector3(0,player.height + 1,0);
        }
Пример #16
0
 //public
 void Light(float speed)
 {
     int[] numbers = to3Digits(speed);
     panel.SetAsLastSibling();
     for (int i0 = 0; i0 < digits_Lights.GetLength(0); i0++)
     {
         for (int i1 = 0; i1 < digits_Lights.GetLength(1); i1++)
         {
             if (digits[numbers[i0]][i1])
             {
                 digits_Lights[digitsNumber - 1 - i0, i1].SetAsLastSibling();
             }
         }
     }
 }
Пример #17
0
 IEnumerator StageLoad()
 {
     for (int list_x = 0; list_x < spawnObj.GetLength(0); list_x++)
     {
         for (int list_y = 0; list_y < spawnObj.GetLength(1); list_y++)
         {
             if (data.GetGimmicID(list_x, list_y) == 0)
             {
                 continue;
             }
             StageObjUpdate(list_x, list_y, data.GetGimmicID(list_x, list_y), data.GetgimmicRotate(list_x, list_y));
             yield return(new WaitForEndOfFrame());
         }
     }
 }
Пример #18
0
        public Transform GetTileFromPosition(Vector3 position)
        {
            if (loadedRoom == null)
            {
                return(null);
            }

            int x = Mathf.RoundToInt(position.x / tileSize
                                     + (loadedRoom.size.x - 1) / 2f);
            int y = Mathf.RoundToInt(position.z / tileSize
                                     + (loadedRoom.size.y - 1) / 2f);

            x = Mathf.Clamp(x, 0, tileMap.GetLength(0) - 1);
            y = Mathf.Clamp(y, 0, tileMap.GetLength(1) - 1);
            return(tileMap[x, y]);
        }
Пример #19
0
 private void FinishGame()
 {
     for (int i = 0; i < m_grid.GetLength(0); i++)
     {
         for (int j = 0; j < m_grid.GetLength(1); j++)
         {
             if (m_grid[i, j] != null)
             {
                 Destroy(m_grid[i, j].gameObject);
                 m_grid[i, j] = null;
             }
         }
     }
     StartNewGame();
     DisplayManager.Instance().DisplayMessage("You lose!");
 }
Пример #20
0
 public Transform[,] GenerateMap(Transform[,] map)
 {
     for (int i = 0; i < map.GetLength(0); i++)
     {
         for (int j = 0; j < map.GetLength(1); j++)
         {
             Transform obj = Instantiate(objects[Random.Range(0, objects.Count)],
                                         new Vector3(-0.5f * i + (map.GetLength(0) - 1) * 0.5f / 2.0f,
                                                     -0.5f * j + (map.GetLength(1) - 1) * 0.5f / 2.0f,
                                                     0f),
                                         Quaternion.identity);
             map[i, j] = obj;
         }
     }
     return(map);
 }
Пример #21
0
 void Update()
 {
     // Choose the next destination point when the agent gets
     // close to the current one.
     cash = Random.Range (-10, 25);
     if (agent.remainingDistance < 0.05f)
     {
         timer--;
         if(timer <= 0)
         {
             GotoNextPoint();
             Money.profit += cash;
             timer = Random.Range (80,180);
         }
     }
     if(Router.onion [ID] == true && !started)
     {
         points = Router.Route;
         for(int i = 0; i < points.GetLength(1); i++)
         {
             Debug.Log(points[ID,i]);
             if(points[ID,i] != null)
             {
                 index++;
             }
             else
             {
                 Debug.Log (index);
             }
         }
         GotoNextPoint();
         started = true;
     }
 }
Пример #22
0
    public void clear()
    {
        _isEmpty = new int[Config.width, Config.height];
        int lengthX = tileArray.GetLength(0);
        int lengthY = tileArray.GetLength(1);

        for (int i = 0; i < lengthX; i++)
        {
            for (int j = 0; j < lengthY; j++)
            {
                Despawn(tileArray[i, j]);
                tileArray[i, j] = null;
            }
        }
//		col.GenerateGeometry();
    }
Пример #23
0
    void RenderSquare()
    {
        Vector3[] vertices = meshFilter.mesh.vertices;
        for (int y = 0; y < orderedChildren.GetLength(0); y++)
        {
            int row = y * density * 4;
            for (int x = 0; x < orderedChildren.GetLength(1); x++)
            {
                int column = x * 4;

                vertices[column + row + 0] = orderedChildren[x, y].localPosition + new Vector3(-0.5f, -0.5f, 0) * lineWidth;
                vertices[column + row + 1] = orderedChildren[x, y].localPosition + new Vector3(-0.5f, 0.5f, 0) * lineWidth;
                vertices[column + row + 2] = orderedChildren[x, y].localPosition + new Vector3(0.5f, 0.5f, 0) * lineWidth;
                vertices[column + row + 3] = orderedChildren[x, y].localPosition + new Vector3(0.5f, -0.5f, 0) * lineWidth;
            }
        }
        meshFilter.mesh.vertices = vertices;
    }
Пример #24
0
    private void Update()
    {
        float t = 0;

        if (animate)
        {
            t = Time.time;
        }

        // Iterate through cubes and position them on the y axis
        for (int x = 0; x < cubes.GetLength(0); x++)
        {
            for (int z = 0; z < cubes.GetLength(1); z++)
            {
                float y = (Mathf.Sin(x + t) + Mathf.Sin(z + t)) / 2f;
                cubes[x, z].localPosition = new Vector3(cubes[x, z].localPosition.x, y, cubes[x, z].localPosition.z);
            }
        }
    }
Пример #25
0
        private void Validate(Transform[,] tiles, int[] expected)
        {
            int water    = 0;
            int grass    = 0;
            int desert   = 0;
            int mountain = 0;
            int forest   = 0;

            for (int x = 0; x < tiles.GetLength(0); x++)
            {
                for (int y = 0; y < tiles.GetLength(1); y++)
                {
                    switch (tiles[x, y].tag)
                    {
                    case "WaterTile":
                        water++;
                        break;

                    case "GrassTile":
                        grass++;
                        break;

                    case "DesertTile":
                        desert++;
                        break;

                    case "MountainTile":
                        mountain++;
                        break;

                    case "ForestTile":
                        forest++;
                        break;
                    }
                }
            }

            Assert.AreEqual(expected[0], water);
            Assert.AreEqual(expected[1], grass);
            Assert.AreEqual(expected[2], desert);
            Assert.AreEqual(expected[3], mountain);
            Assert.AreEqual(expected[4], forest);
        }
Пример #26
0
    // IDEA:
    // store the tiles in a 2D array.
    // When cameraPos.x/TILE_SIZE > prevCameraPos.x/TILE_SIZE
    // move all the tiles (and their positions) to the other end of the array

    void Start()
    {
        // enough space to fill the area surrounding the camera with tiles
        int size = (int)(Camera.main.farClipPlane / HALF_TILE_SIZE);

        tiles = new Transform[size, size];
        for (int x = 0; x < tiles.GetLength(0); x++)
        {
            for (int y = 0; y < tiles.GetLength(1); y++)
            {
                tiles[x, y] = Instantiate(waterTilePrefab, transform.GetChild(0)).transform;
            }
        }



        // get start tiles
        transform.GetChild(0).GetComponentInChildren <Transform>();
    }
Пример #27
0
        Vector3[,] IMapProvider <Vector3> .GetMap()
        {
            if (vector3Map != null)
            {
                return(vector3Map);
            }

            transformMap = transformMap ?? GenerateTransformMap();
            vector3Map   = new Vector3[Terminologies.LengthOfOneSideOfBoard, Terminologies.LengthOfOneSideOfBoard];
            for (int i = 0; i < transformMap.GetLength(1); i++)
            {
                for (int j = 0; j < transformMap.GetLength(0); j++)
                {
                    vector3Map[i, j] = transformMap[i, j].position;
                }
            }

            return(vector3Map);
        }
Пример #28
0
    public void DeleteRow(int numberRow, Transform[,] grid)
    {
        int widthArray = grid.GetLength(0);

        for (int i = 0; i < widthArray; i++)
        {
            Destroy(grid[i, numberRow].gameObject);
            grid[i, numberRow] = null;
        }
    }
Пример #29
0
    public void Setup(Grid2D <MapObject> grid2D)
    {
        _grid2D     = grid2D;
        _vNodeArray = new Transform[_grid2D.GetWidth(), _grid2D.GetHeight()];
        for (var x = 0; x < _vNodeArray.GetLength(0); x++)
        {
            for (var y = 0; y < _vNodeArray.GetLength(1); y++)
            {
                var visualNode = CreatVisualNode(_grid2D.Cell2WorldPos(x, y));
                _vNodeArray[x, y] = visualNode;
                _visualNodeList.Add(visualNode);
            }
        }

        HideNodeVisual();
        UpdateVisual(_grid2D);

        _grid2D.OnGridMapValueChangeEvent += OnGrid2DObjectChangedHandel;
    }
Пример #30
0
 private void ClearRoomVisuals()
 {
     if (visualsTransforms != null)
     {
         for (int y = 0; y < visualsTransforms.GetLength(1); y++)
         {
             for (int x = 0; x < visualsTransforms.GetLength(0); x++)
             {
                 if (visualsTransforms[x, y] != null)
                 {
                     Destroy(visualsTransforms[x, y].gameObject);                                 //
                 }
             }
         }
     }
     visualsTransforms    = new Transform[roomBoundarySize.x, roomBoundarySize.y];
     floorPorts           = new List <Transform>();
     floorLockDownButtons = new List <Transform>();
 }
Пример #31
0
    public void RocketPowerup()
    {
        int startX = Random.Range(0, grid.GetLength(0) - 3);

        if (startX > grid.GetLength(0) - 3)
        {
            startX = grid.GetLength(0) - 3;
        }
        for (int x = startX; x < startX + 3; x++)
        {
            for (int y = 0; y < grid.GetLength(1); y++)
            {
                if (grid[x, y] != null)
                {
                    Destroy(grid[x, y].gameObject);
                    grid[x, y] = null;
                }
            }
        }
    }