public void CreateSliderBF(Vector3Int position) { if (grid.PositionIsFilled(position)) { return; } Tile sliderBF = tileTypes.GetPrefab(TileInteger.BFSlider); MovableTile movableTile = (MovableTile)CreateTile(sliderBF, position); JoinNeighbors(movableTile); grid.SubscribeTileMovement(movableTile); Slider slider = (Slider)movableTile; slider.MinBound = slider.Position; slider.MaxBound = slider.Position; SliderRail rail = CreateRailBF(position); //ignore collision between the rail and slider Physics.IgnoreCollision(movableTile.transform.GetChild(0).GetComponent <Collider>(), rail.transform.GetChild(0).GetComponent <Collider>(), true); slider.OnInitialize += SetSliderBounds; }
private void JoinNeighbors(MovableTile tile) { //TODO: Make a mechanism to join a simple movable tile to its neighbors //join tile on rightside if (tile.AttachableSides.right) //if tile can be attached from right side { Tile rightSideTile = grid.GetTileAtPosition(tile.Position + Vector3Int.right); TryJoiningNeighbor(tile, rightSideTile, SideName.right); } if (tile.AttachableSides.left) { Tile leftSideTile = grid.GetTileAtPosition(tile.Position + Vector3Int.left); TryJoiningNeighbor(tile, leftSideTile, SideName.left); } if (tile.AttachableSides.front) { Tile frontSideTile = grid.GetTileAtPosition(tile.Position + new Vector3Int(0, 0, 1)); TryJoiningNeighbor(tile, frontSideTile, SideName.front); } if (tile.AttachableSides.back) { Tile backSideTile = grid.GetTileAtPosition(tile.Position + new Vector3Int(0, 0, -1)); TryJoiningNeighbor(tile, backSideTile, SideName.back); } if (tile.AttachableSides.up) { Tile upperTile = grid.GetTileAtPosition(tile.Position + Vector3Int.up); TryJoiningNeighbor(tile, upperTile, SideName.up); } if (tile.AttachableSides.down) { Tile downSideTile = grid.GetTileAtPosition(tile.Position + Vector3Int.down); TryJoiningNeighbor(tile, downSideTile, SideName.down); } }
private void TryJoiningNeighbor(MovableTile tile, Tile neighbor, SideName side) { if (IsMovable(neighbor)) // the neighbor is attachable/movable { MovableTile neighborMovableTile = (MovableTile)neighbor; bool neighborAttachableOnOppositeSide = RobuzzleUtilities.IsTileAttachableOnOppositeSide(neighborMovableTile, side); if (neighborAttachableOnOppositeSide) //the tile and neighbor can join together { //if the tile neighbor tile are not already attached if (!AreAttached(tile, neighborMovableTile)) { RigidbodyTile RBTile = GetRigidbodyTile(tile); if (RBTile != null)//If neighbor already has a rigidbody, attach both rigidbodies { JoinNeighbor(RBTile, neighborMovableTile, side); } else//join simple movable tile with neighbors -> or can that be done somewhere else { RigidbodyTile RBNeighbor = GetRigidbodyTile(neighborMovableTile); if (RBNeighbor != null) { JoinNeighbor(RBNeighbor, tile, RobuzzleUtilities.GetOppositeSide(side)); //this tile is on the left of neighbor } } } } } }
private bool AreAttached(MovableTile tile1, MovableTile tile2) { bool retVal = tile1.Compound != null && tile2.Compound != null && tile1.Compound == tile2.Compound; Debug.Log(tile1.gameObject.name + " and " + tile2.gameObject.name + " Are attached " + retVal); return(retVal); }
public void CreateAgent(Vector3Int position) { if (grid.PositionIsFilled(position)) { return; } Tile agent = tileTypes.GetPrefab(TileInteger.YelloWRobo); MovableTile movableTile = (MovableTile)CreateTile(agent, position); grid.SubscribeTileMovement(movableTile); }
//TODO: Recheck tile type private void JoinNeighbor(RigidbodyTile tile, MovableTile neighbor, SideName side) { //the neighbor is on left, down or back side of the tile if (side == SideName.left || side == SideName.down || side == SideName.back) { JoinNeighbor(tile, neighbor, true); } else// neighbor is on the right, up or front side of the tile { JoinNeighbor(tile, neighbor, false); } }
public void CreateDraggable(Vector3Int position) { if (grid.PositionIsFilled(position)) { return; } Tile draggable = tileTypes.GetPrefab(TileInteger.Draggable); MovableTile movableTile = (MovableTile)CreateTile(draggable, position); grid.SubscribeTileMovement(movableTile); JoinNeighbors(movableTile); }
public void CreateMovableTile(Vector3Int position) { if (grid.PositionIsFilled(position)) { return; } Tile movableTilePrefab = tileTypes.GetPrefab(TileInteger.WoodenTile); MovableTile movableTile = (MovableTile)CreateTile(movableTilePrefab, position); grid.SubscribeTileMovement(movableTile); //TODO: JoinToNeighbors JoinNeighbors(movableTile); }
/// <summary> /// Updates the position of movable tiles. /// </summary> /// <param name="gameTime"></param> private void UpdateMovableTiles(GameTime gameTime) { for (int i = 0; i < TileEngine.movableTiles.Count; ++i) { MovableTile movableTile = TileEngine.movableTiles[i]; movableTile.Update(gameTime); if (movableTile.PlayerIsOn) { //Make player move with tile if the player is on top of tile Player.Position += movableTile.Velocity; } } }
private void OnMouseOver() { if (Input.GetMouseButtonDown(0)) //Captura o botao de click esquerod do Mouse { if (lm.turnPlayer != null && lm.currentStatus == LevelManager.Status.Moving) //Verifica se a ação na qual o jogador está realziando é de movimento { MovableTile mT = lm.turnPlayer.FindTileToMove(this); if (lm.turnPlayer.tilesToMove.Contains(mT)) //Verifica se esse Tile é um dos Tiles para qual o personagem pode se mover; { MoveCharacter(); } } } }
private RigidbodyTile GetRigidbodyTile(MovableTile tile) { RigidbodyTile RBTile = null; if (tile.GetType() == typeof(RigidbodyTile) || tile.GetType().IsSubclassOf(typeof(RigidbodyTile))) { RBTile = (RigidbodyTile)tile; } else if (tile.transform.parent != null) { RBTile = tile.transform.parent.GetComponent <RigidbodyTile>(); } return(RBTile); }
public SliderRail CreateRailUD(Vector3Int position) { Tile railDU = tileTypes.GetPrefab(TileInteger.DURail); MovableTile movableTile = (MovableTile)CreateTile(railDU, position); JoinNeighbors(movableTile); grid.SubscribeTileMovement(movableTile); SliderRail rail = (SliderRail)movableTile; rail.Position = position; return((SliderRail)movableTile); }
//Recebe o Tile para qual o personagem irá se movimenatr e cria o caminho a ser traçado usando uma pilha. public void MoveCharacterToTile(Tile destination) { isRunning = true; hud.HideCancelPanel(); //Cria pilha dos Tiles do caminho com Backtracking através do //previousTile de cada MovableTile Stack <MovableTile> path = new Stack <MovableTile>(); MovableTile temp = turnPlayer.FindTileToMove(destination); while (temp != null) { path.Push(temp); temp = turnPlayer.FindTileToMove(temp.previousTile); } //Movimenta o Personagem StartCoroutine(MoveCharacterToPath(path)); }
private void JoinNeighbor(RigidbodyTile rbTile, MovableTile neighbor, bool tile2OnNegativeSide) { RigidbodyTile neighborRigidbodyTile = GetRigidbodyTile(neighbor); if (neighborRigidbodyTile != null) //if the neighbor has rigidbody, or a parent has rigidbody { RigidbodyTile rbTile1; RigidbodyTile rbTile2; if (tile2OnNegativeSide) { rbTile1 = neighborRigidbodyTile; rbTile2 = rbTile; } else { rbTile1 = rbTile; rbTile2 = neighborRigidbodyTile; } /* Before attaching tile1 with tile2 we want to make sure that tile2 has a compound. * Because, tile1 is added into tile2's cmompound */ if (rbTile2.Compound == null) //tile2 has no compound { if (rbTile1.Compound == null) //tile1 has no compound { rbTile2.AddInCompound(new TileCompound()); } else // if tile1 has a compound, assign it to tile2 { rbTile2.AddInCompound(rbTile1.Compound); } } else if (rbTile1.Compound != null) // if both tiles have compound we will merge the smaller one into bigger one { if (rbTile2.Compound.GetTotalSize() > rbTile1.Compound.GetTotalSize()) { rbTile2.Compound.Integrate(rbTile1.Compound); } else { rbTile1.Compound.Integrate(rbTile2.Compound); } } //now rbTile2 must have a compound. Tile1 is added into tile2's compound rbTile1.Attach(rbTile2); } else // if the neighbor has no rigidbody onitself and on its parent { if (rbTile.Compound == null) { rbTile.AddInCompound(new TileCompound()); } neighbor.Attach(rbTile); /* * Simple moving tiles are not connected to their neighbors, * until a rigidbody is added in their neighborhood. So, they must * attach all their neighbors recursively when a rigidbody is added in neighborhood * */ JoinNeighbors(neighbor); } }