void Awake() { GameObject woodsquare = (GameObject)Instantiate(Resources.Load("Prefabs/Board_Tile")); GameObject temp = GameObject.Find("Spelplan"); gridArray = new GameObject[width, height]; for (int x = 0; x < gridArray.GetLength(0); x++) { for (int y = 0; y < gridArray.GetLength(1); y++) { gridArray[x, y] = Instantiate(woodsquare, temp.transform); if (x == maryStartX && y == maryStartY) { gridArray[x, y].GetComponent <Owner>().specialState = 1; gridArray[x, y].GetComponent <Owner>().owned = 1; } if (x == enemyStartX && y == enemyStartY) { gridArray[x, y].GetComponent <Owner>().specialState = 2; gridArray[x, y].GetComponent <Owner>().owned = 2; } gridArray[x, y].GetComponent <Owner>().xPos = x; gridArray[x, y].GetComponent <Owner>().yPos = y; float posX = x * size; float posY = y * -size; gridArray[x, y].transform.position += new Vector3(posX, posY, 0); } } Destroy(woodsquare); }
// Use this for initialization void Start() { _rowSelector = GameObject.Find("PuzzleGrid/RowSelector"); _currentlySelectedRow = 1; _gridVerticalSize = 4; //instantiate puzzle grid _puzzleGrid = new PuzzleNode[4,GridHorizontalSize]; //Create array of gameobjects in game where puzzle nodes are placed _anchors = new GameObject[_gridVerticalSize,GridHorizontalSize]; for (int row = 0; row < _anchors.GetLength(0); row++) { for (int col = 0; col < _anchors.GetLength(1); col++) { //find current lane's left and right anchors var currentLaneLeftAnchor = GameObject.Find("LaneAnchors/Row" + row + "/Left"); var currentLaneRightAnchor = GameObject.Find("LaneAnchors/Row" + row + "/Right"); //divide the distance of anchors by amount of anchors to determine spacing between them float rowAnchorSpacing = Vector3.Distance(currentLaneLeftAnchor.transform.position,currentLaneRightAnchor.transform.position)/GridHorizontalSize; //create new vector3 for where the current anchor will be placed var putAnchorAt = new Vector3(currentLaneLeftAnchor.transform.position.x + rowAnchorSpacing * col,0); //create game object, name it, make it's parent the parent of the rest of the row elements var currentAnchor = (GameObject) Instantiate(Resources.Load<GameObject>("Prefabs/PuzzleNode")); currentAnchor.name = row + "_" + col; currentAnchor.transform.parent = GameObject.Find("LaneAnchors/Row" + row).transform; //change it's position currentAnchor.transform.localPosition = putAnchorAt; //add game object to array _anchors[row, col] = currentAnchor; } } }
public override void PreviewMove(int moveNum, Vector2 currLoc, GameObject[,] tiles) { for (int i = 0; i < tiles.GetLength(0); i++) { for (int j = 0; j < tiles.GetLength(1); j++) { tiles[i, j].GetComponent <Tile>().isPreview = false; } } if (moveNum == 1) { if (CheckTile((int)currLoc.x, (int)currLoc.y, tiles)) { tiles[(int)currLoc.x, (int)currLoc.y + 1].GetComponent <Tile>().isPreview = true; if (CheckTile((int)currLoc.x + 1, (int)currLoc.y + 1, tiles)) { tiles[(int)currLoc.x + 1, (int)currLoc.y + 1].GetComponent <Tile>().isPreview = true; } if (CheckTile((int)currLoc.x - 1, (int)currLoc.y + 1, tiles)) { tiles[(int)currLoc.x - 1, (int)currLoc.y + 1].GetComponent <Tile>().isPreview = true; } } //theory: x and y are switched } else if (moveNum == 2) { if (CheckTile((int)currLoc.x, (int)currLoc.y, tiles)) { tiles[(int)currLoc.x, (int)currLoc.y + 1].GetComponent <Tile>().isPreview = true; } } }
public void GetNeighbors(GameObject[,] grid, int x, int y, out int treeCount, out int houseCount, out int powerHouseCount) { treeCount = 0; houseCount = 0; powerHouseCount = 0; for (int tmpX = Math.Max(x - 1, 0); tmpX < grid.GetLength(1) && tmpX <= x + 1; tmpX++) { for (int tmpY = Math.Max(y - 1, 0); tmpY < grid.GetLength(0) && tmpY <= y + 1; tmpY++) { if (tmpX == x && tmpY == y) { continue; } var name = grid[tmpY, tmpX].name; if (name.Contains("Tree")) { treeCount++; } else if (name.Contains("House") && !name.Contains("Power")) { houseCount++; } else if (name.Contains("Power")) { powerHouseCount++; } } } }
public IEnumerator FruitsDestroy(GameObject[,] allObjects, float destroyTime) { TilesController tilesControll = new TilesController(); List <Combine> dieFruits = new List <Combine>(); yield return(new WaitForSeconds(destroyTime + 0.01f)); for (int i = 0; i < allObjects.GetLength(0); i++) { for (int j = 0; j < allObjects.GetLength(1); j++) { Combine combinedFruit = allObjects[i, j].GetComponent <Combine>(); if (combinedFruit != null) { if (combinedFruit.iDie) { dieFruits.Add(combinedFruit); Vector2 fruitPos = allObjects[i, j].transform.position; Object.Destroy(allObjects[i, j]); allObjects[i, j] = tilesControll.CreateEmpty(fruitPos); allObjects[i, j].GetComponent <Movable>().SetColRow(i, j); } } } } EventHolder.destroyEvent.Invoke(); EventHolder.destroyFruits.Invoke(dieFruits); AudioManager.Instance.PlayExplosion(); yield break; }
void Awake() { int size = UnityEngine.Random.Range (minSize, maxSize + 1); lights = new GameObject[size, size]; for (int i = 0; i < lights.GetLength (0); i++) { for (int j = 0; j < lights.GetLength (1); j++) { GameObject light = new GameObject ("light " + i + " " + j); lights [i, j] = light; Light l = light.AddComponent<Light> (); l.On = true; LightButton lButton = light.AddComponent<LightButton> (); lButton.layout = this; lButton.position = new Position2d (i, j); BoxCollider2D clickCollider = light.AddComponent<BoxCollider2D> (); clickCollider.size = new Vector2 (multiplier, multiplier); SpriteRenderer renderer = light.AddComponent<SpriteRenderer> (); renderer.color = l.On ? Color.yellow : Color.grey; renderer.sprite = lightSprite; light.transform.parent = this.transform; light.transform.position = IntToFloat (i, j); } } for (int i = 0; i < lightBulbsToToggle; i++) { int x = UnityEngine.Random.Range (0, lights.GetLength (0)); int y = UnityEngine.Random.Range (0, lights.GetLength (1)); click (new Position2d (x, y)); } }
private void Awake() { System.Random random = new System.Random(); _map = new GameObject[_rowsAndColumns, _rowsAndColumns]; for (float i = _rowsAndColumns * -_coordinateStep; i < _map.GetLength(0) * _coordinateStep; i += _coordinateStep) { for (float j = _rowsAndColumns * -_coordinateStep; j < _map.GetLength(1) * _coordinateStep; j += _coordinateStep) { if (random.Next(1, 100) <= _probability && _emptyCount <= 0) { _emptyCount = 2; _position = new Vector3(j, i, transform.position.z); var platform = Instantiate(_platforms[random.Next(0, _platforms.Count)], _position, Quaternion.identity); platform.transform.SetParent(gameObject.transform); } else { _emptyCount -= 1; } } } }
void connectGalaxies() { for (int i = 1; i < listOfGalaxies.GetLength(0); i++) { addGalaxy(listOfGalaxies[i, 0], listOfGalaxies[i - 1, 0]); } }
private void CreateAllWaveBlocks() { for (int p = 0; p < levelLoader.NumPuzzles; p++) { for (int i = 0; i < waveCubes.GetLength(0); i++) { for (int j = 0; j < puzzleLen; j++) { if (j + (p * puzzleLen) < floorBlocks.LevelLength - 1) { waveCubes[i, j + (p * puzzleLen)] = Instantiate(floorCube, new Vector3(i + 0.5f, -0.505f, floorBlocks.LevelEnd - (j + (p * puzzleLen) + 0.4905f)), Quaternion.identity); } else { waveCubes[i, j + (p * puzzleLen)] = null; } if (p == levelLoader.NumPuzzles - 1) { puzzleCubes[i, j] = waveCubes[i, j + (p * puzzleLen)]; } } } } }
public static List <GameObject> getAdjacentMinions(GameObject[,] arr, int row, int column) { int rows = arr.GetLength(0); int columns = arr.GetLength(1); Debug.Log(rows + " " + columns); List <GameObject> adjacentMinions = new List <GameObject>(); for (int j = row - 1; j <= row + 1; j++) { for (int i = column - 1; i <= column + 1; i++) { if (arr[j, i].GetComponent <nodeInfo>().monsterOnNode != null) { if (i != column || j != row) { if (i >= 0 && j >= 0 && i < columns && j < rows && !arr[j, i].GetComponent <nodeInfo>().isFree) { Debug.Log(j + " " + i); adjacentMinions.Add(arr[j, i].GetComponent <nodeInfo>().monsterOnNode); } } } } } return(adjacentMinions); }
void Start() { objMatrix = new GameObject[2 * Size + 1, 2 * Size + 1]; for (int i = 0; i < objMatrix.GetLength(0); i++) { for (int j = 0; j < objMatrix.GetLength(1); j++) { /*if ((i + 1) % 2 == 0 && (j + 1) % 2 == 0) * { * float y = Random.Range(scalarY / 3, scalarY); * objMatrix[i, j] = GameObject.CreatePrimitive(PrimitiveType.Cube); * objMatrix[i, j].transform.localScale = new Vector3(scalarX, y, scalarZ); * objMatrix[i, j].transform.position = new Vector3(j * scalarX, y / 2, i * scalarZ); * } * else*/ { objMatrix[i, j] = GameObject.CreatePrimitive(PrimitiveType.Quad); objMatrix[i, j].transform.localScale = new Vector3(scalarX, scalarZ, 1); objMatrix[i, j].transform.rotation = Quaternion.Euler(90, 0, 0); objMatrix[i, j].transform.position = new Vector3(j * scalarX, -0.5f, i * scalarZ); objMatrix[i, j].GetComponent <MeshCollider>().convex = true; } objMatrix[i, j].transform.parent = transform; //objMatrix[i, j].AddComponent<MeshCollider>(); } } wall_W = GameObject.CreatePrimitive(PrimitiveType.Quad); wall_W.transform.localScale = new Vector3(objMatrix.GetLength(0) * scalarX, scalarZ, 1); wall_W.transform.position = new Vector3(-scalarX / 2, scalarZ / 2, (objMatrix.GetLength(0) - 1) * scalarZ / 2); wall_W.transform.rotation = Quaternion.Euler(0, -90, 0); wall_W.GetComponent <MeshCollider>().convex = true; wall_W.GetComponent <MeshRenderer>().material = brick; wall_W.transform.parent = transform; wall_E = GameObject.CreatePrimitive(PrimitiveType.Quad); wall_E.transform.localScale = new Vector3(objMatrix.GetLength(0) * scalarX, scalarZ, 1); wall_E.transform.position = new Vector3(objMatrix.GetLength(0) * scalarX - scalarX / 2, scalarZ / 2, (objMatrix.GetLength(0) - 1) * scalarZ / 2); wall_E.transform.rotation = Quaternion.Euler(0, 90, 0); wall_E.GetComponent <MeshCollider>().convex = true; wall_E.GetComponent <MeshRenderer>().material = brick; wall_E.transform.parent = transform; wall_N = GameObject.CreatePrimitive(PrimitiveType.Quad); wall_N.transform.localScale = new Vector3(objMatrix.GetLength(0) * scalarX, scalarZ, 1); wall_N.transform.position = new Vector3((objMatrix.GetLength(0) - 1) * scalarX / 2, scalarZ / 2, objMatrix.GetLength(0) * scalarZ - scalarZ / 2); wall_N.transform.rotation = Quaternion.Euler(0, 0, 0); wall_N.GetComponent <MeshCollider>().convex = true; wall_N.GetComponent <MeshRenderer>().material = brick; wall_N.transform.parent = transform; wall_S = GameObject.CreatePrimitive(PrimitiveType.Quad); wall_S.transform.localScale = new Vector3(objMatrix.GetLength(0) * scalarX, scalarZ, 1); wall_S.transform.position = new Vector3((objMatrix.GetLength(0) - 1) * scalarX / 2, scalarZ / 2, -scalarZ / 2); wall_S.transform.rotation = Quaternion.Euler(0, 180, 0); wall_S.GetComponent <MeshCollider>().convex = true; wall_S.GetComponent <MeshRenderer>().material = brick; wall_S.transform.parent = transform; }
void Destru(GameObject [,] grid) //Metodo para destruir hasta 2 pelotas por fila (Regla Extra) { for (int a = 0; a < grid.GetLength(0); a++) { List <int> crash; //Declaracion de una lista crash = new List <int>(); int c = Random.Range(0, 2); //Randomizador que controla cuantas pelotas por fila se van a destruir, o si no se va a destruir ninguna if (c == 1) //Condicional para destruir 1 pelota { crash.Add(Random.Range(0, grid.GetLength(1))); grid[a, crash[0]].SetActive(false); } else if (c == 2) //Condicional para destruir 2 pelotas { crash.Add(Random.Range(0, grid.GetLength(1))); int d = Random.Range(0, grid.GetLength(1)); while (d == crash[0]) { d = Random.Range(0, grid.GetLength(1)); } crash.Add(d); grid[a, crash[0]].SetActive(false); grid[a, crash[1]].SetActive(false); } } }
public void ResetGame() { // Wipe out the map for (int row = 0; row < levelMap.GetLength(0); row++) { for (int col = 0; col < levelMap.GetLength(1); col++) { Destroy(levelMap [row, col]); } } Enemy[] enemies = FindObjectsOfType <Enemy> (); for (int i = 0; i < enemies.Length; i++) { Destroy(enemies [i].gameObject); } Tower[] towers = FindObjectsOfType <Tower> (); for (int i = 0; i < towers.Length; i++) { Destroy(towers [i].gameObject); } InitializeGame(); Time.timeScale = 1.0f; }
void Start() //最初作るとき ここでかじた作のプレイヤー人数+を記憶 { difficulty = TitleSystem.Get_Difficulty(); // タイトルシステムから難易度の変数を読み込む。 playerCount = TitleSystem.Get_Member(); MonsterCount = MonsterMax[difficulty]; presentBoxCount = presentBoxMax[difficulty]; trapCount = trapMax[difficulty]; UI_Con = GameObject.Find("UI_Controller"); Floor = 0; for (int i = 0; i < ivent.GetLength(0); i++) { for (int j = 0; j < ivent.GetLength(1); j++) { ivent[i, j] = nullObject; } } oil = new float[playerCount]; StairsUP(); difficulty = TitleSystem.Get_Difficulty(); // タイトルシステムから難易度の変数を読み込む。 for (int i = 0; i < playerCount; i++) { getPlayer[i].GetComponent <Oil_Controller>().set_InitialOil(difficulty); onetime = true; } }
private void Paint(GameObject[,] worldMap, Tile tile, Sprite lastTile, MapLayers layer, int x, int y) { if (x < 0 || y < 0 || x >= worldMap.GetLength(0) || y >= worldMap.GetLength(1)) { return; } if (lastTile == null) { if (worldMap[x, y] != null) { return; } } else { GameObject currentTile = worldMap[x, y]; if (currentTile == null) { return; } if (currentTile.GetComponentInChildren <SpriteRenderer>().sprite != lastTile) { return; } } CreateTile(tile, new Vector2(x, y), layer); Paint(worldMap, tile, lastTile, layer, x + 1, y); Paint(worldMap, tile, lastTile, layer, x, y + 1); Paint(worldMap, tile, lastTile, layer, x - 1, y); Paint(worldMap, tile, lastTile, layer, x, y - 1); }
public void ResizeLayerMap(MapLayers layer) { GameObject[,] mapLayer = m_worldMap[layer]; int oldCols = mapLayer.GetLength(0); int oldRows = mapLayer.GetLength(1); if ((oldRows > rows) || (oldCols > columns)) { for (int c = columns; c < oldCols; c++) { for (int r = 0; r < oldRows; r++) { DeleteTile(new Vector2(c, r), layer); } } for (int r = rows; r < oldRows; r++) { for (int c = 0; c < oldCols; c++) { DeleteTile(new Vector2(c, r), layer); } } } m_worldMap[layer] = ResizeMatrix(mapLayer, columns, rows); }
public Map(GameObject[,] mapObjects) { var columns = mapObjects.GetLength(0); var rows = mapObjects.GetLength(1); Size = new Size(columns * Game.boxSize.Width, rows * Game.boxSize.Height); this.tiles = new Tile[columns, rows]; // Create tiles that wrap the given objects... for (int y = 0; y < rows; y++) { for (int x = 0; x < columns; x++) { var tile = new Tile(new Point(y, x)) { Bounds = new RectangleF(x * Game.tileSize, y * Game.tileSize, Game.tileSize, Game.tileSize), Object = mapObjects[x, y] }; tiles[x, y] = tile; } } // ...and create a graph where each tile is a node with connections to its neighbors for (int y = 0; y < rows - 1; y++) { for (int x = 0; x < columns - 1; x++) { tiles[x, y].ConnectNeighbors(tiles[x + 1, y], tiles[x, y + 1]); } } }
/// <summary> /// 绘制棋子 /// </summary> void DrawPieces() { for (int i = 0; i < piecesObj.GetLength(0); i++) { for (int j = 0; j < piecesObj.GetLength(1); j++) { if (piecesObj[i, j] != null) { Destroy(piecesObj[i, j]); } } } for (int i = 0; i < IndexPos.GetLength(0); i++) { for (int j = 0; j < IndexPos.GetLength(1); j++) { if (IndexPos[i, j] > 0) { GameObject go = Instantiate(piece, transform.Find("main")); piecesObj[i, j] = go; go.GetComponent <RectTransform>().sizeDelta = new Vector2(125, 120); go.GetComponent <RectTransform>().anchoredPosition = piecesPosArray[i, j]; go.transform.GetChild(0).GetComponent <Text>().text = IndexPos[i, j].ToString(); } else { if (piecesObj[i, j] != null) { Destroy(piecesObj[i, j]); } } } } }
void Awake() { if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } classroom = new GameObject[4, 4]; classroom[0, 0] = GameObject.FindGameObjectWithTag("Enemy"); classroom [classroom.GetUpperBound(0), classroom.GetUpperBound(1)] = GameObject.FindGameObjectWithTag("Player"); int index = 0; GameObject[] others = GameObject.FindGameObjectsWithTag("Student"); for (int i = 0; i < classroom.GetLength(0); i++) { for (int j = 0; j < classroom.GetLength(1); j++) { if ((i == 0 && j == 0) || (i == classroom.GetUpperBound(0) && j == classroom.GetUpperBound(1))) { continue; } classroom[i, j] = others[index]; index++; } } }
public List <GameObject> SetMenuText(GameObject[,] but) { List <GameObject> l = new List <GameObject>(); for (int i = 0; i < but.GetLength(0); i++) { for (int j = 0; j < but.GetLength(1); j++) { GameObject text = new GameObject("MenuButton"); text.transform.SetParent(but[i, j].transform); text.AddComponent <Text>(); text.GetComponent <RectTransform>().anchorMin = new Vector2(0.0f, 0.0f); text.GetComponent <RectTransform>().anchorMax = new Vector2(1.0f, 1.0f); text.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0.5f); text.GetComponent <RectTransform>().localScale = new Vector3(1.0f, 1.0f, 1.0f); text.GetComponent <RectTransform>().offsetMax = new Vector2(0.0f, 0.0f); text.GetComponent <RectTransform>().offsetMin = new Vector2(0.0f, 0.0f); text.GetComponent <Text>().resizeTextForBestFit = false; text.GetComponent <Text>().fontSize = 20; text.GetComponent <Text>().fontStyle = FontStyle.BoldAndItalic; text.GetComponent <Text>().alignment = TextAnchor.MiddleCenter; text.GetComponent <Text>().font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; text.GetComponent <Text>().color = new Color32(0, 0, 0, 255); if (j == 0) { text.GetComponent <Text>().text = "RESTART"; } else { text.GetComponent <Text>().text = "EXIT"; } } } return(l); }
private void ClearAll() { if (grid?.Length > 0) { for (int row = 0; row < grid.GetLength(0); row++) { for (int col = 0; col < grid.GetLength(1); col++) { if (grid[row, col] != null) { DestroyImmediate(grid[row, col]); } } } } if (transform.childCount > 0) { foreach (Transform child in transform) { DestroyImmediate(child.gameObject); } } grid = null; }
void Start() { gridy = gridSize[0]; gridx = gridSize[1]; pathfinding = new Pathfinding(gridx, gridy, cellSize); grid = pathfinding.GetGrid(); map = new MapData(); map.grid = new List <GridEntry>(); squareArray = new GameObject[gridx, gridy]; player.transform.position = grid.GetWorldPosition(0, 0) + Vector3.one * cellSize * 0.5f; for (int x = 0; x < squareArray.GetLength(0); x++) { for (int y = 0; y < squareArray.GetLength(1); y++) { //create a matrix of squares the size of the grid. Vector3 squarePosition = grid.GetWorldPosition(x, y) + Vector3.one * cellSize * 0.5f; GameObject square = Instantiate(squarePrefab, squarePosition, Quaternion.identity); square.transform.localScale = new Vector3(cellSize - borderSize[0], cellSize - borderSize[1]); square.name = "square " + x + "-" + y; squareArray[x, y] = square; } } LoadFromMap(); }
private GameObject[,] ResizeMatrix(GameObject[,] matrix, int newCols, int newRows) { GameObject[,] newMatrix = new GameObject[newCols, newRows]; int currentCols = matrix.GetLength(0); int currentRows = matrix.GetLength(1); int maxCols = Mathf.Max(newCols, currentCols); int maxRow = Mathf.Max(newRows, currentRows); for (int i = 0; i < maxCols; i++) { for (int j = 0; j < maxRow; j++) { if (newMatrix.GetLength(0) <= i) { continue; } if (newMatrix.GetLength(1) <= j) { continue; } if (matrix.GetLength(0) <= i) { continue; } if (matrix.GetLength(1) <= j) { continue; } newMatrix[i, j] = matrix[i, j]; } } return(newMatrix); }
public void optimizeMatrix() { bool justUpdated; //need to make sure no further matrix update is needed int updateCount; //replacement counter do { Debug.Log("optimizing matrix"); updateCount = 0; justUpdated = false; for (int i = 0; i < blockObjects.GetLength(0) - 1; i++) { for (int j = 0; j < blockObjects.GetLength(1) - 1; j++) { if (blockObjects[i, j].GetComponent <blockProfile>().colourIs == blockObjects[i + 1, j + 1].GetComponent <blockProfile>().colourIs) { Debug.Log("found one is the same"); Debug.Log("this was" + blockObjects[i, j].GetComponent <blockProfile>().colourIs + " at " + i + " " + j); updateCount += 1; GameObject objBackup = blockObjects[i, j]; Destroy(blockObjects[i, j]); blockObjects[i, j] = Instantiate(instantiateReplacement(objBackup), blockPositions[i, j], Quaternion.identity) as GameObject; } else { continue; } } } if (updateCount != 0) { justUpdated = true; } } while (justUpdated); }
void Start() { agents = new List <Agent_behavour1>(); pathList = new List <Point>(); pathIndex = -1; Pre_process_grid_units(n); assets_holder = new GameObject[map.width, map.height]; for (int i = 0; i < map.width; i++) { for (int j = 0; j < map.height; j++) { Instantiate_prefs_on_map(i, j); } } agentMap = new bool[grid.GetLength(0), grid.GetLength(1)]; /* PathToHouse(3, 3, 14, 14); * do * { * PathToHouse(pathList[pathIndex].x, pathList[pathIndex].y, 14, 14); * CheckIfHasMove(14, 14); * * } while (!foundPath); * * for (int i = 0; i < pathList.Count; i++) * if (!(pathList[i].x== 14 && pathList[i].y == 14)) * grid[pathList[i].x, pathList[i].y].GetComponent<Renderer>().material = mat2; * //for (int i = 0; i < pathList.Count; i++) * // if (pathList[i].x == 14 && pathList[i].y == 14) * // grid[pathList[i].x, pathList[i].y].GetComponent<Renderer>().material = mat3; */ }
//●関数名が微妙● public void InitializeItems(int eggNum, int komugikoNum, int pankoNum, int badItemNum) { //▼マップ上のアイテムを全破棄 for (int i = 0; i < generateBoxes.GetLength(0); i++) { for (int j = 0; j < generateBoxes.GetLength(1); j++) { Destroy(generateBoxes[i, j]); generateBoxes[i, j] = null; } } //▼アイテム生成 if (IsRush) { ItemGenerate(rushItem, eggNum + komugikoNum + pankoNum + badItemNum); } else { ItemGenerate(egg, eggNum); ItemGenerate(komugiko, komugikoNum); ItemGenerate(panko, pankoNum); ItemGenerate(badItem, badItemNum); } }
public static int[,] IndexOf(GameObject[,] array, Cell value) { int[,] index = new int[, ] { { -1 }, { -1 } }; for (int y = 0; y < array.GetLength(0); y++) { for (int x = 0; x < array.GetLength(1); x++) { var cell = array[y, x].GetComponent <Cell>(); if (ReferenceEquals(cell, value)) { index = new int[, ] { { y }, { x } }; return(index); } } } return(index); }
public void onSelect(object sender, System.EventArgs args) { if (((GameObject)sender).GetComponent <Person>() == this) { select(); } else { if (selected) { GameObject[,] tiles = world.GetComponent <Grid>().tiles; for (int x = 0; x < tiles.GetLength(0); x++) { for (int y = 0; y < tiles.GetLength(1); y++) { if (tiles[x, y].GetInstanceID() == ((GameObject)sender).GetInstanceID()) { Vector2Int diff = new Vector2Int(pos.x - x, pos.y + y); if (((GameObject)sender).GetComponent <Ground>().movementMarker != null) { transform.SetParent(tiles[x, y].transform); transform.localPosition = new Vector3(0, 1, 0); pos = new Vector2Int(x, y); canMove = false; } } } } } deselect(sender); } }
void Start() { //Set up NodeMap xOffSet = 1-(Node.minX); yOffSet = 1-(Node.minY); nodeMap = new GameObject[(Node.maxX+xOffSet+2),(Node.maxY+yOffSet+2)]; //+2 is to create a buffer edge //Populate empty map for(int x=0;x<(nodeMap.GetLength(0));x++){ for(int y=0;y<(nodeMap.GetLength(1));y++){ nodeMap[x,y] = null; } } //Stick nodes in the map GameObject[] temp = GameObject.FindGameObjectsWithTag("Node"); for(int i=0;i<temp.Length;i++){ Node node = temp[i].GetComponent<Node>(); node.refactorX(xOffSet); node.refactorY(yOffSet); nodeMap[node.getX(),node.getY()]=temp[i]; } //Now that they're in the big map, tell them who //the neighbours are. for(int i=0;i<temp.Length;i++){ Node node = temp[i].GetComponent<Node>(); node.mapNeighbours(); } //Identify the Player. player = GameObject.FindGameObjectWithTag("Player"); //PrintDimensions(); PrintMap(); }
public List <Movable> GetDiogonalsPair(GameObject[,] allObjects) { List <Movable> fruits = new List <Movable>(); for (int i = allObjects.GetLength(0) - 1; i > 0; i--) { for (int j = 0; j < allObjects.GetLength(1); j++) { Movable _movable = allObjects[i, j].GetComponent <Movable>(); if (_movable != null && allObjects[i, j].GetComponent <Empty>() == null) { if (allObjects[i - 1, j].GetComponent <Empty>() != null) { return(null); } Empty _empty = _movable.GetEmptyNeighboor(new Vector2Int(1, -1), allObjects); if (_movable.GetObjectNeighboor(Vector2Int.right, allObjects) == null && _empty != null) { fruits.Add(_movable); fruits.Add(_empty.GetComponent <Movable>()); return(fruits); } _empty = _movable.GetEmptyNeighboor(new Vector2Int(-1, -1), allObjects); if (_movable.GetObjectNeighboor(Vector2Int.left, allObjects) == null && _empty != null) { fruits.Add(_movable); fruits.Add(_empty.GetComponent <Movable>()); return(fruits); } } } } return(null); }
public bool AvailableToMove(Vector2 atualPosition, Vector2 dir) { int x = (int)atualPosition.x; int y = (int)atualPosition.y; int xDir = (int)(dir.x + x); int yDir = (int)(dir.y + y); if (xDir >= board.GetLength(0) || xDir < 0 || yDir >= board.GetLength(1) || yDir < 0 || board[xDir, yDir] == null) { return(false); } string tagAtual = board[x, y].tag; string tagDir = board[xDir, yDir].tag; Piece atualPiece = board[x, y].GetComponent <Piece>(); if (tagAtual == "Number" && tagDir == "Number") { atualPiece.UpdateValue(); finishedLevel = false; return(true); } else if (tagAtual == "Number" && tagDir == "Finish" && CanFinish()) { atualPiece.UpdateValue(); finishedLevel = true; return(true); } return(false); }
void fieldInit() { for (int i = 0; i < fieldArray.GetLength(1); ++i) { for (int e = 0; e < fieldArray.GetLength(0); ++e) { GameObject cube = fieldArray[i, e]; if (cube == null) { cube = Instantiate(block, new Vector3(i, e, 0), Quaternion.identity); } if (shipArray[i, e] == 0) { cube.GetComponent <Renderer>().material = background; } else if (shipArray[i, e] == 1) { cube.GetComponent <Renderer>().material = playerOne; } else { cube.GetComponent <Renderer>().material = playerTwo; } cube.transform.position = new Vector3(i, e, 0); fieldArray[i, e] = cube; } } }
private List <GameObject> GetNeighborTiles(GameObject tile) { int x = (int)tile.transform.position.x; int y = (int)tile.transform.position.y; List <GameObject> neighbourTiles = new List <GameObject>(); int count = 0; for (int i = 0; i < NEIGHBOURS.GetLength(0); i++) { int xPos = x + NEIGHBOURS[i, 0]; int yPos = y + NEIGHBOURS[i, 1]; // If the position is not out of bounds if ((xPos >= 0 && xPos < tiles.GetLength(0)) && (yPos >= 0 && yPos < tiles.GetLength(1))) { GameObject selectedTile = tiles[xPos, yPos]; // Why check if tile is alive? Because we are getting tiles while we are creating it. Will return 4 results (excluding self) when creating and searching /* {tile} {tile} {not created} * {tile} {self} {not created} * {tile}{not created}{not created} */ if (selectedTile != null) { //print(string.Format("x: {0}, y: {1}, name: {2}", xPos, yPos, selectedTile.gameObject.name)); //neighbourTiles[count] = selectedTile; neighbourTiles.Add(selectedTile); count++; } } } return(neighbourTiles); }
void Awake () { BoardDimensions = 18; _tiles = new GameObject[BoardDimensions, BoardDimensions]; for (int x = 0; x < _tiles.GetLength (0); x++) for (int y = 0; y < _tiles.GetLength (1); y++) _tiles [x, y] = CreateTile (x, y); GetSurroundingTiles(); }
void DiscoverBlocks() { int maxX = 0; int maxY = 0; foreach (Transform child in transform) { maxX = Mathf.Max( Mathf.RoundToInt(child.localPosition.y), maxX); maxY = Mathf.Max( Mathf.RoundToInt(child.localPosition.x), maxY); } blocks = new GameObject[maxY+1,maxX+1]; foreach (Transform child in transform) { int x = Mathf.RoundToInt(child.localPosition.y); int y = Mathf.RoundToInt(child.localPosition.x); blocks[blocks.GetLength(0)-1-y, x] = child.gameObject; } print(blocks); }
private static void PlayGame(int level) { //The method returns the score matrixForGame = LoadLevel(level); Ball ball = new Ball(matrixForGame.GetLength(0) - 1, matrixForGame.GetLength(1) / 2); int boardRow = matrixForGame.GetLength(0) - 1; int boardCol = matrixForGame.GetLength(1) / 2; bool allBricksCleared = false; Board board = new Board(boardRow, boardCol); while (true) { if (ballBoardHits >= MAX_BALL_BOARD_HITS_BEFORE_BRICKS_DOWN) { for (int row = matrixForGame.GetLength(0) - 1; row > 1; row--) { for (int col = 1; col < matrixForGame.GetLength(1) - 1; col++) { matrixForGame[row, col] = matrixForGame[row - 1, col]; } } ballBoardHits = 0; } if (lives < 1) { //Read all the users List<User> users = new List<User>(); users.Add(new User(user, score)); using (StreamReader scoreReader = new StreamReader(@"..\..\HighScore.txt")) { string lineRead = scoreReader.ReadLine(); while (!string.IsNullOrEmpty(lineRead)) { users.Add(User.ParseUser(lineRead)); lineRead = scoreReader.ReadLine(); } } //Write the current user using (StreamWriter sr = new StreamWriter(@"..\..\HighScore.txt")) { foreach (var userToWrite in users) { sr.WriteLine(userToWrite.ToString()); } } users.Clear(); lives = 3; score = 0; break; } Console.Clear(); PrintFrame(ball, board); Update(ball, board); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(); switch (key.Key) { case ConsoleKey.LeftArrow: if (board.Col >= 2) { board.Col--; } break; case ConsoleKey.RightArrow: if (board.Col + board.Size < matrixForGame.GetLength(1) - 1) { board.Col++; } break; case ConsoleKey.P: { while (true) { ConsoleKeyInfo isPause = Console.ReadKey(true); if (isPause.Key == ConsoleKey.P) { break; } Console.ReadKey(true); } } break; case ConsoleKey.Escape: { Console.Clear(); DrawMenu(); } break; } } allBricksCleared = true; for (int row = 0; row < matrixForGame.GetLength(0); row++) { for (int col = 0; col < matrixForGame.GetLength(1); col++) { if (matrixForGame[row, col].IsDestroyable) { allBricksCleared = false; break; } } } if (allBricksCleared) { break; } Thread.Sleep(150); } if (allBricksCleared) { PlayGame(level + 1); } else { AskRetry(); } }
/// <summary> /// Object initialization /// </summary> private void Initializer() { _imgView = new GameObject[_height,_width]; for (int i =0;i<_imgView.GetLength(0);i++)// Initialize field components { for (int j =0;j<_imgView.GetLength(1);j++) { _imgView[i,j] = GameObject.CreatePrimitive(PrimitiveType.Cube); _imgView[i,j].transform.position = new Vector3(j, i , 0); _imgView[i,j].transform.GetComponent<MeshFilter>().mesh = _cube.GetComponent<MeshFilter>().mesh; _imgView[i,j].transform.GetComponent<MeshRenderer>().material = _cube.GetComponent<MeshRenderer>().material; _imgView[i,j].GetComponent<Renderer>().enabled = true; } } }
private void fillBoard() { board = new GameObject[boardState.GetLength(0),boardState.GetLength(1)]; for(int i=0;i<board.GetLength(0);++i){ for(int j=0;j<board.GetLength(1);++j){ switch(boardState[i,j]){ case 10: board[i,j] = (GameObject)Instantiate((GameObject)Resources.Load("Board/ground")); break; case 11: board[i,j] = (GameObject)Instantiate((GameObject)Resources.Load("Board/stone")); break; case 20: board[i,j] = (GameObject)Instantiate((GameObject)Resources.Load("Board/build")); break; case 21: board[i,j] = (GameObject)Instantiate((GameObject)Resources.Load("Board/ladder")); break; case 30: board[i,j] = (GameObject)Instantiate((GameObject)Resources.Load("Board/gold")); break; case 40: board[i,j] = (GameObject)Instantiate((GameObject)Resources.Load("Board/dinamite")); break; case 50: board[i,j] = (GameObject)Instantiate((GameObject)Resources.Load("Board/invencible")); break; } board[i,j].transform.localPosition = new Vector3(i-board.GetLength(0)/2,board.GetLength(1)/2-j,0.0f); } } }
void CreateImage() { Screen_w = this.GetComponent<RectTransform>().rect.width; Screen_h = this.GetComponent<RectTransform>().rect.height; border_x = (Screen_w - (pix_w) * 6)/2; border_y = ((Screen_h - (pix_h) * 5)/2)+10;//8 myGameobject = new GameObject[5, 6]; int num = 0; for (int i = 0; i < myGameobject.GetLength(0); i++) { for (int j = 0; j < myGameobject.GetLength(1); j++) { Vector3 position; position = new Vector3(border_x + (pix_w)*j +pix_w/2 - Screen_w/2, -border_y-(pix_h)*i - pix_h/2 + Screen_h/2, -1); // position = new Vector3(j*90,i*-90,0);z var tmp = GameObject.Instantiate(imagePrefab, Vector3.zero, Quaternion.identity) as GameObject; myGameobject[i, j] = tmp; myGameobject[i, j].transform.SetParent(transform); tmp.transform.localScale = Vector3.one; tmp.transform.localPosition = position; myGameobject[i, j].name = "Pic_" + num; num++; Image image = myGameobject[i, j].GetComponent<Image>(); image.sprite = mySprite[Random.Range(0, 6)]; myGameobject[i, j].AddComponent<Pic>(); myGameobject[i, j].AddComponent<Button>(); } } }
/// <summary> /// Object initialization /// </summary> private void Initializer() { _cubes = MainActivity.Instance.cube; _imgView = new GameObject[_height,_width]; for (var i = 0;i<_imgView.GetLength(0);i++)// Initialize field components { for (var j = 0;j<_imgView.GetLength(1);j++) { _imgView[i,j] = GameObject.CreatePrimitive(PrimitiveType.Cube); _imgView[i,j].transform.position = new Vector3(j, i , 0); _imgView[i,j].transform.GetComponent<MeshFilter>().mesh = _cubes.GetComponent<MeshFilter>().mesh; _imgView[i,j].transform.GetComponent<MeshRenderer>().material = _cubes.GetComponent<MeshRenderer>().material; _imgView[i,j].GetComponent<Renderer>().enabled = true; } } for (var i = 0; i < _pole.GetLength(0); i++) // clear the field { for (var j = 0; j < _pole.GetLength(1); j++) { _pole[i,j] = false; } } DrawPole(); }
void Start() { switch(PersistentBeat.difficulty){ case 0: rows = 5; cols = 3; enemyTypes = easy; break; case 1: rows = 7; cols = 4; enemyTypes = med; break; case 2: rows = 9; cols = 5; enemyTypes = hard; break; } speed = 1f; theAliens = new GameObject[rows,cols]; for(int x=0;x<theAliens.GetLength(0);x++){ for(int y=0;y<theAliens.GetLength(1);y++){ theAliens[x,y] = fillEnemy(); } } for(int x=0;x<theAliens.GetLength(0);x++){ for(int y=0;y<theAliens.GetLength(1);y++){ if(theAliens[x,y] != null){ GameObject temp = (GameObject)Instantiate(theAliens[x,y], new Vector3(x*1.5f,y*-1.5f,0f),Quaternion.identity); temp.GetComponent<Alien>().setPos(new Vector2(x,y)); temp.transform.parent=transform; enemyCount++; } } } StartCoroutine(alwaysMove()); StartCoroutine(checkForWin()); }
private void GenerateGraph() { ClearBars(); ingameBars = new GameObject[data.GetLength(0), data.GetLength(1)]; for (int x = 0; x < ingameBars.GetLength(0); x++) { for (int y = 0; y < ingameBars.GetLength(1); y++) { var bar = Instantiate(prefabBar); var dataPoint = bar.GetComponent<DataPointOld>(); if (!dataPoint) { print("Error: Attach DataPointOld script to graph prefab object!"); } else { bar.transform.parent = transform; dataPoint.TargetHeight = data[x, y]; dataPoint.SetPosition(2 * x, 2 * y); } ingameBars[x, y] = bar; } } }
public void LoadContent() { //Finding and declaring the grid Level parentLevel = parent as Level; TileGrid tileGrid = parentLevel.Find("TileGrid") as TileGrid; this.grid = tileGrid.Objects; gridWidth = grid.GetLength(0); gridHeight = grid.GetLength(1); stepgrid = new int[gridWidth, gridHeight]; //Counting the amount of path-tiles in the room for (int x = 0; x < gridWidth; x++) { for (int y = 0; y < gridHeight; y++) { if (grid[x, y] is Tile && !(grid[x, y] is WallTile)) { tiles++; } } } //Monster's position foreach(GameObject tile in tileGrid.Objects) if (tile != null) if (tile.ID == "EntryTile") monsterPosition = tile.Position + new Vector3(0, 200, 0); //Monster's velocity velocity = 150; //Setting the emitter and listener for 3D sound playerListener = new AudioListener(); monsterEmitter = new AudioEmitter(); }