public void DoDamageTileUp(TileBehaviour tile) { Debug.Log (tile.gameObject.name); Ray _ray; RaycastHit _hitInfo; RaycastHit objectHit; Vector3 up = Vector3.up; selectedCharacter.GetComponent<disablinghp> ().Appear = false; // Raycast and verify that it collided if (Physics.Raycast (tile.gameObject.transform.position, up, out objectHit, 50)) { if (objectHit.collider.gameObject.tag == "AttackableEnemy") { objectHit.collider.gameObject.GetComponent<disablinghp> ().JustHit = true; objectHit.collider.gameObject.GetComponent<Enemy> ().DealtDamage (unitAttack); objectHit.collider.transform.parent.tag = "Enemy"; objectHit.collider.gameObject.tag = "Enemy"; objectHit.collider.gameObject.GetComponent<Enemy> ().CheckDeath (); } if (objectHit.collider.gameObject.tag == "AttackableRangedEnemy") { objectHit.collider.gameObject.GetComponent<disablinghp> ().JustHit = true; objectHit.collider.gameObject.GetComponent<EnemyRanged> ().DealtDamage (unitAttack); objectHit.collider.transform.parent.tag = "RangedEnemy"; objectHit.collider.gameObject.tag = "RangedEnemy"; objectHit.collider.gameObject.GetComponent<EnemyRanged> ().CheckDeath (); } if (objectHit.collider.gameObject.tag == "AttackableEnemySiege") { objectHit.collider.gameObject.GetComponent<disablinghp> ().JustHit = true; objectHit.collider.gameObject.GetComponent<EnemyCannon> ().DealtDamage (unitAttack); objectHit.collider.gameObject.tag = "EnemySiege"; objectHit.collider.gameObject.GetComponent<EnemyCannon> ().CheckDeath (); } if (objectHit.collider.gameObject.tag == "Enemy") { objectHit.collider.gameObject.GetComponent<disablinghp> ().JustHit = true; objectHit.collider.gameObject.GetComponent<Enemy> ().DealtDamage (unitAttack); objectHit.collider.gameObject.GetComponent<Enemy> ().CheckDeath (); } if (objectHit.collider.gameObject.tag == "RangedEnemy") { objectHit.collider.gameObject.GetComponent<disablinghp> ().JustHit = true; objectHit.collider.gameObject.GetComponent<EnemyRanged> ().DealtDamage (unitAttack); objectHit.collider.gameObject.GetComponent<EnemyRanged> ().CheckDeath (); } if (objectHit.collider.gameObject.tag == "EnemySiege") { objectHit.collider.gameObject.GetComponent<disablinghp> ().JustHit = true; objectHit.collider.gameObject.GetComponent<EnemyCannon> ().DealtDamage (unitAttack); objectHit.collider.gameObject.GetComponent<EnemyCannon> ().CheckDeath (); } } }
public TileData(string _name, Solidity _solidity, int _id, ContentManager content, TileBehaviour _behaviour = null, Category _category = Category.NONE) { name = _name; id = _id; if (File.Exists("Content/Tiles/" + name + ".xnb")) { texture = content.Load <Texture2D>("Tiles/" + _name); } solidity = _solidity; behaviour = _behaviour; category = _category; }
void destTileChanged() { var destTile = GridManager.instance.destTileTB; //deselect destination tile if user clicks on current destination tile if (this == destTile) { GridManager.instance.destTileTB = null; GridManager.instance.originTileTB = null; return; } GridManager.instance.destTileTB = this; previousTile = destTile; if (previousTile != null) { } }
public void setGroundSize(float width, float height) { destTileTB = null; originTileTB = null; Destroy(GameObject.Find("Lines")); Destroy(GameObject.Find("HexGrid")); Vector3 groundScale = Ground.transform.localScale; Vector3 groundSize = new Vector3(width, groundScale.y, height); Ground.transform.localScale = groundSize; Vector2 textureTiling = new Vector2(width * 2, height * 2); Ground.renderer.material.mainTextureScale = textureTiling; setSizes(); createGrid(); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Tile" && this.tag == "Starting") { this.tag = "Explodable"; //this.GetComponent<CircleCollider2D>().enabled = false; CurrentTile = collision.gameObject.GetComponent <TileBehaviour>(); //Current = CurrentTile.GetComponent<TileBehaviour>().Letra; //tilespercorridos += 1; SobeNoTile(); } if (collision.tag == "Explodable") { } }
/// <summary> /// Returns the tile path by working backwards /// </summary> /// <param name="endNode">The last node in the line</param> private List <TileBehaviour> CalculatePath(TileBehaviour endNode) { List <TileBehaviour> path = new List <TileBehaviour> { endNode }; TileBehaviour currentNode = endNode; while (currentNode.cameFromNode != null) { path.Add(currentNode.cameFromNode); currentNode = currentNode.cameFromNode; } path.Reverse(); return(path); }
void Start() { instance = this; monsterDict = new Dictionary <GameObject, TileBehaviour>(); monsters = new List <GameObject>(); foreach (Transform monsterTr in GameObject.Find("Monsters").transform) { TileBehaviour tb = findTileBehavior(monsterTr.gameObject); monsterDict.Add(monsterTr.gameObject, tb); monsters.Add(monsterTr.gameObject); } foreach (var monster in monsterDict.Values) { monster.setAsImpassable(); } Messenger.AddListener("characterMoved", finishedMoving); }
public void Crack(TileBehaviour origin) { Clear(); TileBehaviour[] adjacents = GetAdjacents(origin); foreach (TileBehaviour tile in adjacents) { if (tile != null && !(tile.Cracked || IsContained(tile))) { subsets.Add(GetSet(tile, new List <TileBehaviour>())); } } if (!(subsets.Count > 1)) { return; } int max = subsets [0].Count; foreach (var tiles in subsets) { if (tiles.Count > max) { max = tiles.Count; } } float offset = 0; foreach (var tiles in subsets) { if (tiles.Count < max) { tiles.Sort((a, b) => { return((int)Mathf.Floor(Vector2.Distance(origin.transform.position, a.transform.position) - Vector2.Distance(origin.transform.position, b.transform.position))); }); foreach (var tile in tiles) { tile.InvokeCrack(offset); offset += 0.1f; } } } }
//Pathfinding time //Takes in the target tile to move to as a parameter //This method is for the player units. An actual A* movement will be implemented later. public void FindPath(TileBehaviour tile) { path.Clear(); //so we don't have any leftover stuff from the previous move tile.targetTile = true; TileBehaviour nextTile = tile; // Debug.Log(path.Count + " path count " + character.type); while (nextTile != null) { if (nextTile != currentTile && !(nextTile.occupied && path.Count == 0))//nextTile.selectable && { path.Push(nextTile); } nextTile = nextTile.parent; } }
private void RandomizeSpawnCrystalOnTile(TileBehaviour tile)//спавним кристал на указанном тайле при необходимости { bool activ = false; if (!_crystalAlreadySpawn) { if (_tileCounter == _crystalSpawnIndex) { activ = true; _crystalAlreadySpawn = true; //вычисляем следующий switch (GamemanagerBehaviour.Instance.Rule) { case GamemanagerBehaviour.CrystalGenerationRule.Random: // случайным образом { _crystalSpawnIndex = Random.Range(0, GamemanagerBehaviour.Instance.Period + 1); break; } case GamemanagerBehaviour.CrystalGenerationRule.Period: //по порядку.То есть на первом блоке - 1 - ый тайл с кристаллом, на 2 - ом - 2 тайл и так далее до 5 - ого блока.Далее опять с 1 - ого по 5. { _crystalSpawnIndex++; if (_crystalSpawnIndex > GamemanagerBehaviour.Instance.Period) { _crystalSpawnIndex = 0; } break; } case GamemanagerBehaviour.CrystalGenerationRule.None: { break; } } } } _tileCounter++; if (_tileCounter > GamemanagerBehaviour.Instance.Period) { _crystalAlreadySpawn = false; _tileCounter = 0; } tile.SetCrystalActive(activ); }
//private IEnumerator followPath(PathToTile path) //{ // Queue<Vector2Int> actualPath = new Queue<Vector2Int>(path.path); // actualPath.Enqueue(path.tile); // position = path.tile; // Vector2 target = actualPath.Dequeue(); //We need to figure out how to gradually increase stamina intake depending on distance. // while (true) // { // Vector2 dist = target - (Vector2)transform.position; // print(character.speed); // if (dist.magnitude > 0.05) // { // //I assume this is where the unit records that it has moved one tile? // transform.position += (Vector3)(dist.normalized * Time.deltaTime * character.speed); // } // else if (actualPath.Count != 0) // { // transform.position += (Vector3)dist; // target = actualPath.Dequeue(); // } // else // { // doneMoving.Invoke(); // break; // } // yield return null; // } //} //This starts movement along the given path /* * public void move(PathToTile path) * { * StartCoroutine(followPath(path)); * }*/ //Now the fun stuff. Pathfinding for AI :D //A* time protected TileBehaviour FindLowestTotalCost(List <TileBehaviour> list) { TileBehaviour lowest = list[0]; foreach (TileBehaviour tile in list) { //Debug.Log(tile.name + " in FOR EACH"); if (tile.totalCost < lowest.totalCost) { lowest = tile; } } list.Remove(lowest); return(lowest); }
void selectedCharChanged() { GridManager.instance.originTileTB.setAsNormal(); BaseChar selectedChar = GameMaster.instance.selectedChar; TileBehaviour tb = characters[selectedChar].tileBeh; tb.setAsOrigin(); foreach (var character in characters) { if (character.Key != selectedChar) { character.Value.tileBeh.setAsImpassable(); } } findWalkable(); }
//Finally the method which initialises and positions all the tiles void createGrid() { Vector2 gridSize = calcGridSize(); GameObject hexGridGO = new GameObject("HexGrid"); //board is used to store tile locations board = new Dictionary <Point, TileBehaviour>(); for (float y = 0; y < gridSize.y; y++) { float sizeX = gridSize.x; //if the offset row sticks up, reduce the number of hexes in a row if (y % 2 != 0 && (gridSize.x + 0.5) * hexWidth > groundWidth) { sizeX--; } for (float x = 0; x < sizeX; x++) { GameObject hex = (GameObject)Instantiate(Hex); Vector2 gridPos = new Vector2(x, y); hex.transform.position = calcWorldCoord(gridPos); hex.transform.parent = hexGridGO.transform; GameObject tx = (GameObject)Instantiate(Text); tx.transform.position = calcWorldCoord(gridPos); tx.transform.Translate(new Vector3(0, 0.1f, 0)); TextMesh tm = tx.GetComponent <TextMesh>(); tm.text = x.ToString() + " , " + y.ToString(); TileBehaviour tb = hex.GetComponent <TileBehaviour>(); //y / 2 is subtracted from x because we are using straight axis coordinate system tb.tile = new Tile((int)x - (int)(y / 2), (int)y); board.Add(tb.tile.Location, tb); } } //variable to indicate if all rows have the same number of hexes in them //this is checked by comparing width of the first hex row plus half of the hexWidth with groundWidth bool equalLineLengths = (gridSize.x + 0.5) * hexWidth <= groundWidth; //Neighboring tile coordinates of all the tiles are calculated foreach (TileBehaviour tb in board.Values) { tb.tile.FindNeighbours(board, gridSize, equalLineLengths); } }
public void MergeTiles(List <GameObject> linkedTiles) { int minRow = rowCount; int minCol = colCount; int maxRow = 0; int maxCol = 0; foreach (GameObject go in linkedTiles) { TileBehaviour tileBehaviour = go.GetComponent <TileBehaviour>(); if (tileBehaviour.row < minRow) { minRow = tileBehaviour.row; } if (tileBehaviour.row > maxRow) { maxRow = tileBehaviour.row; } if (tileBehaviour.col < minCol) { minCol = tileBehaviour.col; } if (tileBehaviour.col > maxCol) { maxCol = tileBehaviour.col; } } Vector2 centerPos = calculateMergedCenterPos(linkedTiles); Vector2 mergedMinPos = new Vector2(minRow, minCol); Vector2 mergedMaxPos = new Vector2(maxRow, maxCol); for (int i = 0; i < linkedTiles.Count; i++) { TileBehaviour tileBehaviour = linkedTiles[i].GetComponent <TileBehaviour>(); bool mergeRight = tileBehaviour.col + 1 <= maxCol; bool mergeLeft = tileBehaviour.col - 1 >= minCol; bool mergeBottom = tileBehaviour.row + 1 <= maxRow; bool mergeTop = tileBehaviour.row - 1 >= minRow; tileBehaviour.Merge(centerPos, mergedMinPos, mergedMaxPos, linkedTiles, mergeLeft, mergeRight, mergeTop, mergeBottom); mergedTiles.Add(linkedTiles[i]); } }
public void TransformTile(GameObject tile, string newCharacter) { TileBehaviour tileBehaviour = tile.GetComponent <TileBehaviour>(); if (tileBehaviour.isMerged) { foreach (GameObject peerTile in tileBehaviour.mergedPeerTiles) { ApplyTileSpriteInfo(peerTile, newCharacter); peerTile.GetComponent <TileBehaviour>().character = newCharacter; } } else { ApplyTileSpriteInfo(tile, newCharacter); tileBehaviour.character = newCharacter; } }
bool proximityCheck() { TileBehaviour lastTileInLink = link[link.Count - 1]; int deltaX = lastTileInLink.x - currentSelection.x; deltaX *= deltaX; int deltaY = lastTileInLink.y - currentSelection.y; deltaY *= deltaY; if (deltaX <= 1 && deltaY <= 1) { return(true); } else { return(false); } }
void switchOriginAndDestTiles() { if (!CombatManager.instance.playersTurn) { return; } HUD.instance.clickable = true; Material originMaterial = originTileTB.renderer.material; originTileTB.renderer.material = destTileTB.defaultMaterial; originTileTB.tile.Passable = true; originTileTB = destTileTB; originTileTB.renderer.material = originMaterial; originTileTB.tile.Passable = false; destTileTB = null; generateAndShowPath(); CombatManager.instance.charMoved(); }
private void setBoundaryWalls(TileBehaviour tileBehaviour, int row, int column) { if (row == 0 || (gridMapping[row - 1, column] != 1 && gridMapping[row - 1, column] != 2)) { tileBehaviour.setWall(Enums.Direction.South); } if (column == 0 || (gridMapping[row, column - 1] != 1 && gridMapping[row, column - 1] != 2)) { tileBehaviour.setWall(Enums.Direction.West); } if (column == (y_Size - 1) || (gridMapping[row, column + 1] != 1 && gridMapping[row, column + 1] != 2)) { tileBehaviour.setWall(Enums.Direction.East); } if (row == (x_Size - 1) || (gridMapping[row + 1, column] != 1 && gridMapping[row + 1, column] != 2)) { tileBehaviour.setWall(Enums.Direction.North); } }
void ApplyTileSpriteInfo(GameObject tile, string tileCharacter) { TileSpriteInfo tileSpriteInfo = GetTileSpriteInfo(tileCharacter); if (tileSpriteInfo == null) { print("tileSpriteInfo of " + tileCharacter + " does not exist"); return; } SpriteRenderer characterSpriteRenderer = tile.transform.FindChild(TileBehaviour.CHARACTER).GetComponent <SpriteRenderer>(); characterSpriteRenderer.color = tileSpriteInfo.characterColor; characterSpriteRenderer.sprite = tileSpriteInfo.characterSprite; TileBehaviour newTileBehaviour = tile.GetComponent <TileBehaviour>(); newTileBehaviour.backgroundColor = tileSpriteInfo.tileColor; }
IEnumerator enemyAction() { yield return(new WaitForSeconds(2)); foreach (Tile tile in this.currentTB.tile.Neighbours) { TileBehaviour tb = GridManager.instance.board[tile.Location]; for (int i = 0; i < CharacterManager.instance.getCharacterInstanceListSize(); i++) { if (CharacterManager.instance.getCharacterInstance(i) == tb.containedCharacter) { TurnManager.instance.initiateCombat(this.gameObject, tb.containedCharacter); Debug.Log("Fighting " + CharacterManager.instance.getCharacterInstance(i)); this.GetComponent <CharacterStatus>().ableToMove = false; break; } } break; } }
void DestroyLink(bool shouldDestroyLinkedTiles) { foreach (GameObject go in linkedTiles) { go.GetComponent <TileBehaviour>().isLinked = false; } if (shouldDestroyLinkedTiles) { foreach (GameObject go in linkedTiles) { TileBehaviour TileBehaviour = go.GetComponent <TileBehaviour>(); TileManager.GetInstance().DestroyTile(TileBehaviour.row, TileBehaviour.col); } tileManager.Drop(shouldGenerateNewTile); } mLineRenderer.enabled = false; linkedTiles.Clear(); }
bool IsLinkRectangle() { if (linkedTiles.Count < 2) { return(false); } int minRow = TileManager.GetInstance().rowCount; int minCol = TileManager.GetInstance().colCount; int maxRow = 0; int maxCol = 0; foreach (GameObject go in linkedTiles) { TileBehaviour tileBehaviour = go.GetComponent <TileBehaviour>(); if (tileBehaviour.isMerged) { return(false); } if (tileBehaviour.row < minRow) { minRow = tileBehaviour.row; } if (tileBehaviour.row > maxRow) { maxRow = tileBehaviour.row; } if (tileBehaviour.col < minCol) { minCol = tileBehaviour.col; } if (tileBehaviour.col > maxCol) { maxCol = tileBehaviour.col; } } return((maxRow - minRow + 1) * (maxCol - minCol + 1) == linkedTiles.Count); }
//called every frame when mouse cursor is on this tile void OnMouseOver() { //if player right-clicks on the tile, toggle passable variable and change the color accordingly if (Input.GetMouseButtonUp(1)) { if (this == GridManager.instance.destTileTB || this == GridManager.instance.originTileTB) { return; } tile.Passable = !tile.Passable; if (!tile.Passable) { changeColor(Color.gray); } else { changeColor(orange); } GridManager.instance.generateAndShowPath(); } //if user left-clicks the tile if (Input.GetMouseButtonUp(0)) { tile.Passable = true; TileBehaviour originTileTB = GridManager.instance.originTileTB; //if user clicks on origin tile or origin tile is not assigned yet if (this == originTileTB || originTileTB == null) { originTileChanged(); } else { destTileChanged(); } GridManager.instance.generateAndShowPath(); } }
IEnumerator PoblateZone() { GameObject last = null; while(_tiles.Count > 0) { int rnd = Random.Range(0, _tiles.Count); GameObject g = _tiles[rnd].gameObject; TileBehaviour tb = g.GetComponent<TileBehaviour>(); int index = _auxTiles.FindIndex(x => x == g); if (selectedFlowerInTile[index] < _flowers.Length && !plantAlreadyCreated[index]) { plantAlreadyCreated[index] = true; GameObject f = Instantiate(_flowers[selectedFlowerInTile[index]], transform.position, Quaternion.identity); f.transform.parent = g.transform; f.transform.localPosition = new Vector3(0, 0.5f, 0); f.transform.localScale = new Vector3(1, 25, 1); } tb.startGrowAnimation(); _tiles.RemoveAt(rnd); last = g; yield return new WaitForSeconds(_timeBetweenPoblateAnimation * Time.deltaTime); } expandingZone = false; if (last.GetComponent<lastFlowerBehaviour>()) Destroy(last.GetComponent<lastFlowerBehaviour>()); last.AddComponent<lastFlowerBehaviour>(); last.GetComponent<lastFlowerBehaviour>().myFather = gameObject; }
List <TileBehaviour> GetSet(TileBehaviour origin, List <TileBehaviour> visited) { List <TileBehaviour> result = new List <TileBehaviour> (); TileBehaviour[] adjacents = GetAdjacents(origin); if (!IsContained(origin, visited)) { result.Add(origin); } foreach (TileBehaviour tile in adjacents) { if (tile != null && !(tile.Cracked || IsContained(tile, visited))) { visited = visited.Concat(result).ToList(); result = result.Concat(GetSet(tile, visited)).ToList(); } } return(result); }
// Update is called once per frame void Update() { //if (currentTile != null) //{ // currentTB = GridManager.instance.board[currentTile.Location]; // currentTile = currentTB.tile; //} //Enemy AI if allied with enemy if (this.gameObject.GetComponent <CharacterStatus>().allegiance == 1) { if (TurnManager.instance.getPhaseStatus() == TurnManager.kEnemy) { if (this.GetComponent <CharacterStatus>().ableToMove) { foreach (Tile tile in this.currentTB.tile.Neighbours) { TileBehaviour tb = GridManager.instance.board[tile.Location]; for (int i = 0; i < CharacterManager.instance.getCharacterInstanceListSize(); i++) { if (CharacterManager.instance.getCharacterInstance(i) == tb.containedCharacter) { TurnManager.instance.initiateCombat(this.gameObject, tb.containedCharacter); Debug.Log("Fighting " + CharacterManager.instance.getCharacterInstance(i)); this.GetComponent <CharacterStatus>().ableToMove = false; return; } } } this.GetComponent <CharacterStatus>().ableToMove = false; return; } } } if (currentTB != null) { this.gameObject.transform.position = GridManager.instance.calcWorldCoord(new Vector2(currentTB.gridX, currentTB.gridY)); } }
/* * Visit all the neighbouring tiles of the root tile, * if the neighbours belong to the other player, in a depth first * search fashion. */ void DFSVisit(TileBehaviour tileScript) { // Will switch the owner of the game tile, if necessary tileScript.UpdateScore(); // Create an array of the list of neighbouring game tiles GameObject[] neighbours = new GameObject[4]; int i = 0; foreach (GameObject numSqur in tileScript.NumberSquares) { GameObject adjSqur = numSqur.GetComponent < NumberSquareBehaviour>().AdjacentNumSqur; if (adjSqur) { neighbours[i] = adjacencyList[adjSqur.GetComponent < NumberSquareBehaviour>().GetIDNumber()]; } else { neighbours[i] = null; } i++; } tileScript.Colour = 1; // If the owner of the neighbouring game tile is not the owner // of this game tile, update its score foreach (GameObject neighbour in neighbours) { if (neighbour) { TileBehaviour nextTile = neighbour.GetComponent < TileBehaviour>(); if (nextTile.Owner != tileScript.Owner && nextTile.Colour == 0) { DFSVisit(nextTile); } } } }
// Use this for initialization void Start() { beh = new TileBehaviour(); beh.sprite = tileSprite; //beh.color = testColor; for (int i = 0; i < x_max; i++) { for (int j = 0; j < y_max; j++) { //map.grid[i, j, 0] = new TestTileClass(tileSprite, testColor); map.SetTile(beh, new TilePosition(0, i, j, map)); } } //TestAdvancedTile large = new TestAdvancedTile(tileSprite,tileSpriteSecound); //map.SetTile(large, new TilePosition(1, 0, 0, map)); //map.SetTile(large, new TilePosition(1, 1, 0, map)); //map.GenerateAllMesh(); //StartCoroutine(Draw()); }
void OnMouseOver() { if (Input.GetMouseButtonUp(1)) { if (this == gridManager.destTileTB || this == gridManager.originTileTB) { return; } tile.Passable = !tile.Passable; if (!tile.Passable) { ChangeColor(mouseOverColor); } else { ChangeColor(orange); } gridManager.GenerateAndShowPath(); } if (Input.GetMouseButtonUp(0)) { tile.Passable = true; TileBehaviour originTileTB = gridManager.originTileTB; if (this == originTileTB || originTileTB == null) { originTileChanged(); } else { destTileChanged(); } gridManager.GenerateAndShowPath(); } }
// Update is called once per frame void Update() { bool foundSlidingTile = false; int numTiles = tileList.Count; for (int i = 0; i < numTiles; i++) { TileBehaviour currentTile = tileList[i].GetComponent <TileBehaviour>(); if (currentTile.isSliding) { foundSlidingTile = true; areAnyTilesSliding = true; } if (currentTile.wasClicked) { currentTile.wasClicked = false; //invalid if any tiles are already sliding or the tile isn't touching the empty tile if (!areAnyTilesSliding && (currentTile.transform.position - emptyTileObject.transform.position).magnitude == tileSize && !currentTile.isEmptyTile) { currentTile.startPos = currentTile.transform.position; currentTile.targetPos = emptyTileObject.transform.position; currentTile.isSliding = true; emptyTileObject.transform.position = currentTile.transform.position; } } } if (!foundSlidingTile) { areAnyTilesSliding = false; } }
// To be called on ticks where the balls are on the edge between two tiles void ExecuteTickOffTurn() { foreach (BallBehaviour ball in board.activeBalls) { TileBehaviour tile = board.GetTileEntered(ball); if (!tile) { Debug.LogError("Ball leaving board"); gameState.isPaused = true; continue; } if (tile.tileType == TileBehaviour.TileType.Block) { ball.forward *= -1.0f; } else if (tile.tileType == TileBehaviour.TileType.Vault) { if (!tile.GetComponentInChildren <VaultBehaviour>().CanEnter(ball.forward)) { ball.forward *= -1.0f; } } else if (tile.tileType == TileBehaviour.TileType.LockRed || tile.tileType == TileBehaviour.TileType.LockBlue) { if (tile.GetComponentInChildren <RaiseBehaviour>().isRaised) { ball.forward *= -1.0f; } } else { BounceBall(ball); } tile.ConditionalBlock(ball.forward * -1.0f); } }
public void Rebuild() { if (board != null) { foreach (Tile tile in board) { Destroy(tile.go); } } board = new Tile[boardSize, boardSize]; CalculateTileSize(); float posy = BoardLeftBottom.y + tileSize * 0.5f; for (int y = 0; y < boardSize; y++) { float posx = BoardLeftBottom.x + tileSize * 0.5f; for (int x = 0; x < boardSize; x++) { Vector3 tilePosition = new Vector3(posx, posy, 0f); GameObject tileGO = Instantiate(tilePrefab, tilePosition, Quaternion.identity, transform); tileGO.transform.localScale = Vector3.one * tileSize; TileBehaviour tb = tileGO.AddComponent <TileBehaviour>(); tb.Init(x, y); Tile tile = new Tile(tileGO, x, y); board[x, y] = tile; posx += tileSize + spacing; } } }
//Methods in GridManager class to be modified void createGrid() { Vector2 gridSize = calcGridSize(); GameObject hexGridGO = new GameObject("HexGrid"); //board is used to store tile locations Dictionary<Point, Tile> board = new Dictionary<Point, Tile>(); Vector3 playerPosition = player.transform.position; double playerX = double.Parse(Math.Round(playerPosition.x, 2).ToString()); double playerY = double.Parse(Math.Round(playerPosition.y, 2).ToString()); //modif z->y for (float y = 0; y < gridSize.y; y++) { float sizeX = gridSize.x; //if the offset row sticks up, reduce the number of hexes in a row if (y % 2 != 0 && (gridSize.x + 0.5) * hexWidth > groundWidth) sizeX--; for (float x = 0; x < sizeX; x++) { bool passable = false; GameObject hex = (GameObject)Instantiate(Hex); Vector2 gridPos = new Vector2(x, y); hex.transform.position = calcWorldCoord(gridPos); hex.transform.parent = hexGridGO.transform; var tb = (TileBehaviour)hex.GetComponent("TileBehaviour"); float terrainHeight = Terrain.activeTerrain.SampleHeight(hex.transform.position); float limitBottom = 0.4f ;//player.transform.position.y + terrainHeight; float limitTop = 0.45f; // if(Math.Abs(terrainHeight - player.transform.position.y) < limit) // { // passable = true; // } if(terrainHeight > limitBottom && terrainHeight < limitTop) { passable = true; } if(!passable) { tb.renderer.material.color = Color.cyan; } //y / 2 is subtracted from x because we are using straight axis coordinate system tb.tile = new Tile((int)x - (int)(y / 2), (int)y, passable); board.Add(tb.tile.Location, tb.tile); double tileX = double.Parse(Math.Round(calcWorldCoord(gridPos).x, 2).ToString()); double tileY = double.Parse(Math.Round(calcWorldCoord(gridPos).y, 2).ToString()); //modif z->y //Mark originTile as the tile with the player coordinates if (tileX == playerX && tileY == playerY) { playerTile = tb.tile; tb.renderer.material = tb.OpaqueMaterial; Color red = Color.red; red.a = 158f / 255f; tb.renderer.material.color = red; originTileTB = tb; } } } //variable to indicate if all rows have the same number of hexes in them //this is checked by comparing width of the first hex row plus half of the hexWidth with groundWidth bool equalLineLengths = (gridSize.x + 0.5) * hexWidth <= groundWidth; //Neighboring tile coordinates of all the tiles are calculated //int i = 0; foreach (Tile tile in board.Values) { tile.FindNeighbours (board, gridSize, equalLineLengths); //Debug.Log(board.Values.ElementAt(i)); //++i; } //traceWalkable (board); }
void switchOriginAndDestTiles() { if (!CombatManager.instance.playersTurn) return; HUD.instance.clickable = true; Material originMaterial = originTileTB.renderer.material; originTileTB.renderer.material = destTileTB.defaultMaterial; originTileTB.tile.Passable = true; originTileTB = destTileTB; originTileTB.renderer.material = originMaterial; originTileTB.tile.Passable = false; destTileTB = null; generateAndShowPath(); CombatManager.instance.charMoved(); }
public bool IsSameElementTile(TileBehaviour tile) { return this.element.IsSameElementImage (tile.element); }
public charInfo(TileBehaviour tile, int stepsLeft) { this.tileBeh = tile; this.stepsLeft = stepsLeft; attacked = false; }
//Method used to switch destination and origin tiles after the destination is reached void switchOriginAndDestinationTiles() { GridManager GM = GridManager.instance; GM.originTileTB = GM.destTileTB; unitOriginalTile = GM.originTileTB; GM.destTileTB = null; // GM.generateAndShowPath(); }
public void setGroundSize(float width, float height) { destTileTB = null; originTileTB = null; Destroy(GameObject.Find("Lines")); Destroy(GameObject.Find("HexGrid")); Vector3 groundScale = Ground.transform.localScale; Vector3 groundSize = new Vector3(width, groundScale.y, height); Ground.transform.localScale = groundSize; Vector2 textureTiling = new Vector2(width * 2, height * 2); Ground.renderer.material.mainTextureScale = textureTiling; setSizes(); createGrid(); }
void OnTileSelected(TileBehaviour tileBehaviour) { TileChanged(tileBehaviour); /* if (_selectedPiece == null) TileChanged(tileBehaviour); else MovePiece(tileBehaviour); */ }
void TileChanged(TileBehaviour tileBehaviour) { // kill animal if animal exist Debug.Log("TileChanged-"+ tileBehaviour.Tile.Tile_StandStatus+"("+tileBehaviour.Tile.X+"," + tileBehaviour.Tile.Y+")"); // chance //tileBehaviour.Tile.CanPass; //tileBehaviour.Tile.TerrianType; //tileBehaviour.Tile.TileStatus; //tileBehaviour.Tile.Tile_StandStatus; //GameObject newParticle = (GameObject)Instantiate( ParticlePrefab , hit.point , Camera.main.transform.rotation); //int nRandomChoose = UnityEngine.Random.Range(0 , 5); //Debug.Log( "CalculateGameLogic:"+ Piece.X + ","+Piece.Y +"neib # "+AvailableTiles.Count+",choose:"+ nRandomChoose ); //GameObject newParticle = (GameObject)Instantiate( ParticlePrefab , hit.point , Camera.main.transform.rotation); if( tileBehaviour.Tile.Tile_StandStatus == TILE_STAND_STATUS.TILE_STAND_STATUS_HUMAN) { //KillHumanPiece( tileBehaviour); //if ( _gamePieces_Humans.Count ==0) // createHumanPiece(); } else if( tileBehaviour.Tile.Tile_StandStatus == TILE_STAND_STATUS.TILE_STAND_STATUS_ANIMAL) { // kill animal option is available KillAnimalPiece( tileBehaviour.Tile); } else if( tileBehaviour.Tile.TileStatus == TILE_STATUS.TILE_STATUS_BUILDING) { /* // Debug //foreach ( GameObject o in _gamePieces_Buildings) //{ // int nX = ( (BuildingBehavior)o.GetComponent("BuildingBehavior")).Piece.X; // int nY = ( (BuildingBehavior)o.GetComponent("BuildingBehavior")).Piece.Y; // Debug.Log( "all buildingLocation-"+nX+","+ nY+";"); //}*/ // make sure the building is on top , get it by name ? GameObject Building = _gamePieces_Buildings.Find( o => ( (BuildingBehavior)o.GetComponent("BuildingBehavior")).Piece.X == tileBehaviour.Tile.X && ( (BuildingBehavior)o.GetComponent("BuildingBehavior")).Piece.Y == tileBehaviour.Tile.Y ); // GameObject BuildingList = GameObject.Find("Environments_Building").transform; if(Building == null) Debug.LogError( "Logic Error-get Building object"); int nRandom = UnityEngine.Random.Range(0 , 2); Debug.Log( "Building-"+nRandom); // destroy if(nRandom == 1 ) { /// building Destroy is available. _gamePieces_Buildings.Remove(Building); Destroy(Building) ; tileBehaviour.Tile.Tile_StandStatus = TILE_STAND_STATUS.TILE_STAND_STATUS_NONE; tileBehaviour.Tile.TileStatus = TILE_STATUS.TILE_STATUS_TERRIAN; //tileBehaviour.Tile.TerrianType } else { // building Upgrade //string BuildingLevel = BuildingBehavior Building_info = (BuildingBehavior)Building.GetComponent("BuildingBehavior"); if (Building_info.UI_StatusText.text== "Building_Level1") Building_info.UI_StatusText.text = "Building_Level2"; //GameObject newParticle = (GameObject)Instantiate( ParticlePrefab_Firework , GetWorldCoordinates( tileBehaviour.Tile.X , tileBehaviour.Tile.Y,0)+ new Vector3(0f,0f,-0.5f) , Quaternion.identity); Instantiate( ParticlePrefab_Firework , GetWorldCoordinates( tileBehaviour.Tile.X , tileBehaviour.Tile.Y,0)+ new Vector3(0f,0f,-0.5f) , Quaternion.identity); } } else if( tileBehaviour.Tile.TileStatus == TILE_STATUS.TILE_STATUS_TERRIAN && tileBehaviour.Tile.Tile_StandStatus == TILE_STAND_STATUS.TILE_STAND_STATUS_NONE) { // change the terrian /// Randon Event if( tileBehaviour.Tile.CanPass == true) { tileBehaviour.Tile.CanPass = false; tileBehaviour.Tile.TerrianType = TERRIAN_STATUS.MOUNTAIN; //tileBehaviour.Tile.Tile_StandStatus ; } else { tileBehaviour.Tile.CanPass = true; tileBehaviour.Tile.TerrianType = TERRIAN_STATUS.GROUND_GRASS; } tileBehaviour.Tile.TileStatus = TILE_STATUS.TILE_STATUS_TERRIAN; tileBehaviour.SetMaterial(); // OnGameStateChanged(); // Instantiate( ParticlePrefab , GetWorldCoordinates( tileBehaviour.Tile.X , tileBehaviour.Tile.Y,0)+ new Vector3(0f,0f,-0.5f) , Quaternion.identity); } }